diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..166730d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pro.user +*.dll diff --git a/README.md b/README.md new file mode 100644 index 0000000..433a598 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +Split Browser +============= + +Split Browser is a minimalistic, ultra-lightweight, open source web browser for desktop, based on [WebKit](https://webkit.org/) (provided by [Playwright](https://playwright.dev/)), [Ultralight](https://ultralig.ht/) and a native [webview](https://webview.dev/) (WebKit on macOS, WebKitGTK on Linux, Edge WebView2 on Windows), with split screen (tiled) view, made with [Qt](https://www.qt.io/). + +![Split Browser](https://i.ibb.co/rcXz8Yd/Split-Browser.webp) + +Every variant of Split Browser (WebKit, Ultralight, native webview) uses <100 MB of RAM to show the home page, which is much less than Chrome/Firefox/Edge. It also allows you to tile web pages side-by-side by dragging and dropping tabs. + +Split Browser is in the alpha stage and provides only basic web browsing features, but no bookmarks, no history, no extensions, no advanced settings. + +## Download + +You can download the latest binary for Windows in the [releases](https://github.com/niutech/splitbrowser/releases). Keep in mind, this is an alpha version, so use at your own risk! + +## Build + +This project is being developed on Windows 10 using Qt 5.14, MSVC 2017 and qmake, but it should also run on Linux and macOS, provided that you have downloaded the lastest [Ultralight SDK](https://github.com/ultralight-ux/Ultralight#getting-the-latest-sdk) and [Playwright WebKit binaries](https://github.com/microsoft/playwright) for your platform. Extract them to folders: `../ultralight` and `../webkit` relative to `splitbrowser`, open this project in Qt Creator and run it. + +## Contribute + +Contributions are welcome! + +## License + +Split Browser © 2022 Jerzy GÅ‚owacki under MIT License. + +Ultralight © 2022 Ultralight Inc. under [Ultralight Free License Agreement](https://github.com/ultralight-ux/Ultralight/blob/master/license/LICENSE.txt). + +Playwright © 2022 Microsoft Corp. under Apache 2.0 License. + +Webview © 2022 Serge Zaitsev et. al. under MIT license. \ No newline at end of file diff --git a/WebView2Loader.dll b/WebView2Loader.dll new file mode 100644 index 0000000..2805c27 Binary files /dev/null and b/WebView2Loader.dll differ diff --git a/WebView2Loader.lib b/WebView2Loader.lib new file mode 100644 index 0000000..1adad38 Binary files /dev/null and b/WebView2Loader.lib differ diff --git a/ads/CMakeLists.txt b/ads/CMakeLists.txt new file mode 100644 index 0000000..dea76a0 --- /dev/null +++ b/ads/CMakeLists.txt @@ -0,0 +1,118 @@ +cmake_minimum_required(VERSION 3.5) +project(QtAdvancedDockingSystem LANGUAGES CXX VERSION ${VERSION_SHORT}) +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} 5.5 COMPONENTS Core Gui Widgets REQUIRED) +if (UNIX AND NOT APPLE) + include_directories(${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS}) +endif() +set(CMAKE_INCLUDE_CURRENT_DIR ON) +if(BUILD_STATIC) + set(CMAKE_STATIC_LIBRARY_SUFFIX "_static${CMAKE_STATIC_LIBRARY_SUFFIX}") +endif() +set(ads_SRCS + ads_globals.cpp + DockAreaTabBar.cpp + DockAreaTitleBar.cpp + DockAreaWidget.cpp + DockContainerWidget.cpp + DockManager.cpp + DockOverlay.cpp + DockSplitter.cpp + DockWidget.cpp + DockWidgetTab.cpp + DockingStateReader.cpp + DockFocusController.cpp + ElidingLabel.cpp + FloatingDockContainer.cpp + FloatingDragPreview.cpp + IconProvider.cpp + DockComponentsFactory.cpp + ads.qrc +) +set(ads_HEADERS + ads_globals.h + DockAreaTabBar.h + DockAreaTitleBar.h + DockAreaTitleBar_p.h + DockAreaWidget.h + DockContainerWidget.h + DockManager.h + DockOverlay.h + DockSplitter.h + DockWidget.h + DockWidgetTab.h + DockingStateReader.h + DockFocusController.h + ElidingLabel.h + FloatingDockContainer.h + FloatingDragPreview.h + IconProvider.h + DockComponentsFactory.h +) +add_compile_options("$<$:/utf-8>") +if (UNIX AND NOT APPLE) + set(ads_SRCS linux/FloatingWidgetTitleBar.cpp ${ads_SRCS}) + set(ads_HEADERS linux/FloatingWidgetTitleBar.h ${ads_HEADERS}) +endif() +if(BUILD_STATIC) + add_library(qtadvanceddocking STATIC ${ads_SRCS} ${ads_HEADERS}) + target_compile_definitions(qtadvanceddocking PUBLIC ADS_STATIC) +else() + add_library(qtadvanceddocking SHARED ${ads_SRCS} ${ads_HEADERS}) + target_compile_definitions(qtadvanceddocking PRIVATE ADS_SHARED_EXPORT) +endif() + +add_library(ads::qtadvanceddocking ALIAS qtadvanceddocking) + +target_link_libraries(qtadvanceddocking PUBLIC Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets) +set_target_properties(qtadvanceddocking PROPERTIES + AUTOMOC ON + AUTORCC ON + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + VERSION ${VERSION_SHORT} + EXPORT_NAME "qtadvanceddocking" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/bin" +) +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "qtadvanceddockingConfigVersion.cmake" + VERSION ${VERSION_SHORT} + COMPATIBILITY SameMajorVersion +) +install(FILES ${ads_HEADERS} + DESTINATION include + COMPONENT headers +) +install(FILES + "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE" + "${CMAKE_CURRENT_SOURCE_DIR}/../gnu-lgpl-v2.1.md" + DESTINATION license/ads + COMPONENT license +) +install(TARGETS qtadvanceddocking + EXPORT adsTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + INCLUDES DESTINATION include +) + +install(EXPORT adsTargets + FILE adsTargets.cmake + NAMESPACE ads:: + DESTINATION lib/cmake/qtadvanceddocking +) +install(FILES qtadvanceddockingConfig.cmake "${CMAKE_CURRENT_BINARY_DIR}/qtadvanceddockingConfigVersion.cmake" + DESTINATION lib/cmake/qtadvanceddocking +) + +target_include_directories(qtadvanceddocking PUBLIC + $ + $ +) diff --git a/ads/DockAreaTabBar.cpp b/ads/DockAreaTabBar.cpp new file mode 100644 index 0000000..d06313a --- /dev/null +++ b/ads/DockAreaTabBar.cpp @@ -0,0 +1,505 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaTabBar.cpp +/// \author Uwe Kindler +/// \date 24.08.2018 +/// \brief Implementation of CDockAreaTabBar class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "FloatingDragPreview.h" +#include "DockAreaTabBar.h" + +#include +#include +#include +#include +#include +#include + +#include "FloatingDockContainer.h" +#include "DockAreaWidget.h" +#include "DockOverlay.h" +#include "DockManager.h" +#include "DockWidget.h" +#include "DockWidgetTab.h" + +#include + + +namespace ads +{ +/** + * Private data class of CDockAreaTabBar class (pimpl) + */ +struct DockAreaTabBarPrivate +{ + CDockAreaTabBar* _this; + CDockAreaWidget* DockArea; + QWidget* TabsContainerWidget; + QBoxLayout* TabsLayout; + int CurrentIndex = -1; + + /** + * Private data constructor + */ + DockAreaTabBarPrivate(CDockAreaTabBar* _public); + + /** + * Update tabs after current index changed or when tabs are removed. + * The function reassigns the stylesheet to update the tabs + */ + void updateTabs(); + + /** + * Convenience function to access first tab + */ + CDockWidgetTab* firstTab() const {return _this->tab(0);} + + /** + * Convenience function to access last tab + */ + CDockWidgetTab* lastTab() const {return _this->tab(_this->count() - 1);} +}; +// struct DockAreaTabBarPrivate + +//============================================================================ +DockAreaTabBarPrivate::DockAreaTabBarPrivate(CDockAreaTabBar* _public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockAreaTabBarPrivate::updateTabs() +{ + // Set active TAB and update all other tabs to be inactive + for (int i = 0; i < _this->count(); ++i) + { + auto TabWidget = _this->tab(i); + if (!TabWidget) + { + continue; + } + + if (i == CurrentIndex) + { + TabWidget->show(); + TabWidget->setActiveTab(true); + _this->ensureWidgetVisible(TabWidget); + } + else + { + TabWidget->setActiveTab(false); + } + } +} + + +//============================================================================ +CDockAreaTabBar::CDockAreaTabBar(CDockAreaWidget* parent) : + QScrollArea(parent), + d(new DockAreaTabBarPrivate(this)) +{ + d->DockArea = parent; + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + setFrameStyle(QFrame::NoFrame); + setWidgetResizable(true); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + d->TabsContainerWidget = new QWidget(); + d->TabsContainerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + d->TabsContainerWidget->setObjectName("tabsContainerWidget"); + d->TabsLayout = new QBoxLayout(QBoxLayout::LeftToRight); + d->TabsLayout->setContentsMargins(0, 0, 0, 0); + d->TabsLayout->setSpacing(0); + d->TabsLayout->addStretch(1); + d->TabsContainerWidget->setLayout(d->TabsLayout); + setWidget(d->TabsContainerWidget); + + setFocusPolicy(Qt::NoFocus); +} + + +//============================================================================ +CDockAreaTabBar::~CDockAreaTabBar() +{ + delete d; +} + + +//============================================================================ +void CDockAreaTabBar::wheelEvent(QWheelEvent* Event) +{ + Event->accept(); + const int direction = Event->angleDelta().y(); + if (direction < 0) + { + horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 20); + } + else + { + horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20); + } +} + + +//============================================================================ +void CDockAreaTabBar::setCurrentIndex(int index) +{ + if (index == d->CurrentIndex) + { + return; + } + + if (index < -1 || index > (count() - 1)) + { + qWarning() << Q_FUNC_INFO << "Invalid index" << index; + return; + } + + Q_EMIT currentChanging(index); + d->CurrentIndex = index; + d->updateTabs(); + updateGeometry(); + Q_EMIT currentChanged(index); +} + + +//============================================================================ +int CDockAreaTabBar::count() const +{ + // The tab bar contains a stretch item as last item + return d->TabsLayout->count() - 1; +} + + +//=========================================================================== +void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab) +{ + d->TabsLayout->insertWidget(Index, Tab); + connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked())); + connect(Tab, SIGNAL(closeRequested()), this, SLOT(onTabCloseRequested())); + connect(Tab, SIGNAL(closeOtherTabsRequested()), this, SLOT(onCloseOtherTabsRequested())); + connect(Tab, SIGNAL(moved(const QPoint&)), this, SLOT(onTabWidgetMoved(const QPoint&))); + connect(Tab, SIGNAL(elidedChanged(bool)), this, SIGNAL(elidedChanged(bool))); + Tab->installEventFilter(this); + Q_EMIT tabInserted(Index); + if (Index <= d->CurrentIndex) + { + setCurrentIndex(d->CurrentIndex + 1); + } + else if (d->CurrentIndex == -1) + { + setCurrentIndex(Index); + } + + updateGeometry(); +} + + +//=========================================================================== +void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab) +{ + if (!count()) + { + return; + } + ADS_PRINT("CDockAreaTabBar::removeTab "); + int NewCurrentIndex = currentIndex(); + int RemoveIndex = d->TabsLayout->indexOf(Tab); + if (count() == 1) + { + NewCurrentIndex = -1; + } + if (NewCurrentIndex > RemoveIndex) + { + NewCurrentIndex--; + } + else if (NewCurrentIndex == RemoveIndex) + { + NewCurrentIndex = -1; + // First we walk to the right to search for the next visible tab + for (int i = (RemoveIndex + 1); i < count(); ++i) + { + if (tab(i)->isVisibleTo(this)) + { + NewCurrentIndex = i - 1; + break; + } + } + + // If there is no visible tab right to this tab then we walk to + // the left to find a visible tab + if (NewCurrentIndex < 0) + { + for (int i = (RemoveIndex - 1); i >= 0; --i) + { + if (tab(i)->isVisibleTo(this)) + { + NewCurrentIndex = i; + break; + } + } + } + } + + Q_EMIT removingTab(RemoveIndex); + d->TabsLayout->removeWidget(Tab); + Tab->disconnect(this); + Tab->removeEventFilter(this); + ADS_PRINT("NewCurrentIndex " << NewCurrentIndex); + if (NewCurrentIndex != d->CurrentIndex) + { + setCurrentIndex(NewCurrentIndex); + } + else + { + d->updateTabs(); + } + + updateGeometry(); +} + + +//=========================================================================== +int CDockAreaTabBar::currentIndex() const +{ + return d->CurrentIndex; +} + + +//=========================================================================== +CDockWidgetTab* CDockAreaTabBar::currentTab() const +{ + if (d->CurrentIndex < 0) + { + return nullptr; + } + else + { + return qobject_cast(d->TabsLayout->itemAt(d->CurrentIndex)->widget()); + } +} + + +//=========================================================================== +void CDockAreaTabBar::onTabClicked() +{ + CDockWidgetTab* Tab = qobject_cast(sender()); + if (!Tab) + { + return; + } + + int index = d->TabsLayout->indexOf(Tab); + if (index < 0) + { + return; + } + setCurrentIndex(index); + Q_EMIT tabBarClicked(index); +} + + +//=========================================================================== +void CDockAreaTabBar::onTabCloseRequested() +{ + CDockWidgetTab* Tab = qobject_cast(sender()); + int Index = d->TabsLayout->indexOf(Tab); + closeTab(Index); +} + + +//=========================================================================== +void CDockAreaTabBar::onCloseOtherTabsRequested() +{ + auto Sender = qobject_cast(sender()); + for (int i = 0; i < count(); ++i) + { + auto Tab = tab(i); + if (Tab->isClosable() && !Tab->isHidden() && Tab != Sender) + { + // If the dock widget is deleted with the closeTab() call, its tab + // it will no longer be in the layout, and thus the index needs to + // be updated to not skip any tabs + int Offset = Tab->dockWidget()->features().testFlag( + CDockWidget::DockWidgetDeleteOnClose) ? 1 : 0; + closeTab(i); + + // If the the dock widget blocks closing, i.e. if the flag + // CustomCloseHandling is set, and the dock widget is still open, + // then we do not need to correct the index + if (Tab->dockWidget()->isClosed()) + { + i -= Offset; + } + } + } +} + + +//=========================================================================== +CDockWidgetTab* CDockAreaTabBar::tab(int Index) const +{ + if (Index >= count() || Index < 0) + { + return nullptr; + } + return qobject_cast(d->TabsLayout->itemAt(Index)->widget()); +} + + +//=========================================================================== +void CDockAreaTabBar::onTabWidgetMoved(const QPoint& GlobalPos) +{ + CDockWidgetTab* MovingTab = qobject_cast(sender()); + if (!MovingTab) + { + return; + } + + int fromIndex = d->TabsLayout->indexOf(MovingTab); + auto MousePos = mapFromGlobal(GlobalPos); + MousePos.rx() = qMax(d->firstTab()->geometry().left(), MousePos.x()); + MousePos.rx() = qMin(d->lastTab()->geometry().right(), MousePos.x()); + int toIndex = -1; + // Find tab under mouse + for (int i = 0; i < count(); ++i) + { + CDockWidgetTab* DropTab = tab(i); + if (DropTab == MovingTab || !DropTab->isVisibleTo(this) + || !DropTab->geometry().contains(MousePos)) + { + continue; + } + + toIndex = d->TabsLayout->indexOf(DropTab); + if (toIndex == fromIndex) + { + toIndex = -1; + } + break; + } + + if (toIndex > -1) + { + d->TabsLayout->removeWidget(MovingTab); + d->TabsLayout->insertWidget(toIndex, MovingTab); + ADS_PRINT("tabMoved from " << fromIndex << " to " << toIndex); + Q_EMIT tabMoved(fromIndex, toIndex); + setCurrentIndex(toIndex); + } + else + { + // Ensure that the moved tab is reset to its start position + d->TabsLayout->update(); + } +} + +//=========================================================================== +void CDockAreaTabBar::closeTab(int Index) +{ + if (Index < 0 || Index >= count()) + { + return; + } + + auto Tab = tab(Index); + if (Tab->isHidden()) + { + return; + } + Q_EMIT tabCloseRequested(Index); +} + + +//=========================================================================== +bool CDockAreaTabBar::eventFilter(QObject *watched, QEvent *event) +{ + bool Result = Super::eventFilter(watched, event); + CDockWidgetTab* Tab = qobject_cast(watched); + if (!Tab) + { + return Result; + } + + switch (event->type()) + { + case QEvent::Hide: + Q_EMIT tabClosed(d->TabsLayout->indexOf(Tab)); + updateGeometry(); + break; + + case QEvent::Show: + Q_EMIT tabOpened(d->TabsLayout->indexOf(Tab)); + updateGeometry(); + break; + + // Setting the text of a tab will cause a LayoutRequest event + case QEvent::LayoutRequest: + updateGeometry(); + break; + + default: + break; + } + + return Result; +} + + +//=========================================================================== +bool CDockAreaTabBar::isTabOpen(int Index) const +{ + if (Index < 0 || Index >= count()) + { + return false; + } + + return !tab(Index)->isHidden(); +} + + +//=========================================================================== +QSize CDockAreaTabBar::minimumSizeHint() const +{ + QSize Size = sizeHint(); + Size.setWidth(10); + return Size; +} + + +//=========================================================================== +QSize CDockAreaTabBar::sizeHint() const +{ + return d->TabsContainerWidget->sizeHint(); +} + +} // namespace ads + + +//--------------------------------------------------------------------------- +// EOF DockAreaTabBar.cpp diff --git a/ads/DockAreaTabBar.h b/ads/DockAreaTabBar.h new file mode 100644 index 0000000..781f5e9 --- /dev/null +++ b/ads/DockAreaTabBar.h @@ -0,0 +1,215 @@ +#ifndef DockAreaTabBarH +#define DockAreaTabBarH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaTabBar.h +/// \author Uwe Kindler +/// \date 24.08.2018 +/// \brief Declaration of CDockAreaTabBar class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include "ads_globals.h" + +namespace ads +{ +class CDockAreaWidget; +class CDockWidgetTab; +struct DockAreaTabBarPrivate; +class CDockAreaTitleBar; +class CFloatingDockContainer; +class IFloatingWidget; + +/** + * Custom tabbar implementation for tab area that is shown on top of a + * dock area widget. + * The tabbar displays the tab widgets of the contained dock widgets. + * We cannot use QTabBar here because it does a lot of fancy animations + * that will crash the application if a tab is removed while the animation + * has not finished. And we need to remove a tab, if the user drags a + * a dock widget out of a group of tabbed widgets + */ +class ADS_EXPORT CDockAreaTabBar : public QScrollArea +{ + Q_OBJECT +private: + DockAreaTabBarPrivate* d; ///< private data (pimpl) + friend struct DockAreaTabBarPrivate; + friend class CDockAreaTitleBar; + +private Q_SLOTS: + void onTabClicked(); + void onTabCloseRequested(); + void onCloseOtherTabsRequested(); + void onTabWidgetMoved(const QPoint& GlobalPos); + +protected: + virtual void wheelEvent(QWheelEvent* Event) override; + + +public: + using Super = QScrollArea; + + /** + * Default Constructor + */ + CDockAreaTabBar(CDockAreaWidget* parent); + + /** + * Virtual Destructor + */ + virtual ~CDockAreaTabBar(); + + /** + * Inserts the given dock widget tab at the given position. + * Inserting a new tab at an index less than or equal to the current index + * will increment the current index, but keep the current tab. + */ + void insertTab(int Index, CDockWidgetTab* Tab); + + /** + * Removes the given DockWidgetTab from the tabbar + */ + void removeTab(CDockWidgetTab* Tab); + + /** + * Returns the number of tabs in this tabbar + */ + int count() const; + + /** + * Returns the current index or -1 if no tab is selected + */ + int currentIndex() const; + + /** + * Returns the current tab or a nullptr if no tab is selected. + */ + CDockWidgetTab* currentTab() const; + + /** + * Returns the tab with the given index + */ + CDockWidgetTab* tab(int Index) const; + + /** + * Filters the tab widget events + */ + virtual bool eventFilter(QObject *watched, QEvent *event) override; + + /** + * This function returns true if the tab is open, that means if it is + * visible to the user. If the function returns false, the tab is + * closed + */ + bool isTabOpen(int Index) const; + + /** + * Overrides the minimumSizeHint() function of QScrollArea + * The minimumSizeHint() is bigger than the sizeHint () for the scroll + * area because even if the scrollbars are invisible, the required speace + * is reserved in the minimumSizeHint(). This override simply returns + * sizeHint(); + */ + virtual QSize minimumSizeHint() const override; + + /** + * The function provides a sizeHint that matches the height of the + * internal viewport. + */ + virtual QSize sizeHint() const override; + +public Q_SLOTS: + /** + * This property sets the index of the tab bar's visible tab + */ + void setCurrentIndex(int Index); + + /** + * This function will close the tab given in Index param. + * Closing a tab means, the tab will be hidden, it will not be removed + */ + void closeTab(int Index); + +Q_SIGNALS: + /** + * This signal is emitted when the tab bar's current tab is about to be changed. The new + * current has the given index, or -1 if there isn't a new one. + */ + void currentChanging(int Index); + + /** + * This signal is emitted when the tab bar's current tab changes. The new + * current has the given index, or -1 if there isn't a new one + */ + void currentChanged(int Index); + + /** + * This signal is emitted when user clicks on a tab + */ + void tabBarClicked(int index); + + /** + * This signal is emitted when the close button on a tab is clicked. + * The index is the index that should be closed. + */ + void tabCloseRequested(int index); + + /** + * This signal is emitted if a tab has been closed + */ + void tabClosed(int index); + + /** + * This signal is emitted if a tab has been opened. + * A tab is opened if it has been made visible + */ + void tabOpened(int index); + + /** + * This signal is emitted when the tab has moved the tab at index position + * from to index position to. + */ + void tabMoved(int from, int to); + + /** + * This signal is emitted, just before the tab with the given index is + * removed + */ + void removingTab(int index); + + /** + * This signal is emitted if a tab has been inserted + */ + void tabInserted(int index); + + /** + * This signal is emitted when a tab title elide state has been changed + */ + void elidedChanged(bool elided); +}; // class CDockAreaTabBar +} // namespace ads +//----------------------------------------------------------------------------- +#endif // DockAreaTabBarH + diff --git a/ads/DockAreaTitleBar.cpp b/ads/DockAreaTitleBar.cpp new file mode 100644 index 0000000..8651d29 --- /dev/null +++ b/ads/DockAreaTitleBar.cpp @@ -0,0 +1,654 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaTitleBar.cpp +/// \author Uwe Kindler +/// \date 12.10.2018 +/// \brief Implementation of CDockAreaTitleBar class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockAreaTitleBar.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DockAreaTitleBar_p.h" +#include "ads_globals.h" +#include "FloatingDockContainer.h" +#include "FloatingDragPreview.h" +#include "DockAreaWidget.h" +#include "DockOverlay.h" +#include "DockManager.h" +#include "DockWidget.h" +#include "DockWidgetTab.h" +#include "DockAreaTabBar.h" +#include "IconProvider.h" +#include "DockComponentsFactory.h" +#include "DockFocusController.h" + +#include + +namespace ads +{ + +/** + * Private data class of CDockAreaTitleBar class (pimpl) + */ +struct DockAreaTitleBarPrivate +{ + CDockAreaTitleBar* _this; + QPointer TabsMenuButton; + QPointer UndockButton; + QPointer CloseButton; + QBoxLayout* Layout; + CDockAreaWidget* DockArea; + CDockAreaTabBar* TabBar; + bool MenuOutdated = true; + QMenu* TabsMenu; + QList DockWidgetActionsButtons; + + QPoint DragStartMousePos; + eDragState DragState = DraggingInactive; + IFloatingWidget* FloatingWidget = nullptr; + + + /** + * Private data constructor + */ + DockAreaTitleBarPrivate(CDockAreaTitleBar* _public); + + /** + * Creates the title bar close and menu buttons + */ + void createButtons(); + + /** + * Creates the internal TabBar + */ + void createTabBar(); + + /** + * Convenience function for DockManager access + */ + CDockManager* dockManager() const + { + return DockArea->dockManager(); + } + + /** + * Returns true if the given config flag is set + * Convenience function to ease config flag testing + */ + static bool testConfigFlag(CDockManager::eConfigFlag Flag) + { + return CDockManager::testConfigFlag(Flag); + } + + /** + * Test function for current drag state + */ + bool isDraggingState(eDragState dragState) const + { + return this->DragState == dragState; + } + + + /** + * Starts floating + */ + void startFloating(const QPoint& Offset); + + /** + * Makes the dock area floating + */ + IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState); +};// struct DockAreaTitleBarPrivate + +//============================================================================ +DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockAreaTitleBarPrivate::createButtons() +{ + QSizePolicy ButtonSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + + // Tabs menu button + TabsMenuButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasTabsMenuButton)); + TabsMenuButton->setObjectName("tabsMenuButton"); + TabsMenuButton->setAutoRaise(true); + TabsMenuButton->setPopupMode(QToolButton::InstantPopup); + internal::setButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon); + QMenu* TabsMenu = new QMenu(TabsMenuButton); +#ifndef QT_NO_TOOLTIP + TabsMenu->setToolTipsVisible(true); +#endif + _this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow())); + TabsMenuButton->setMenu(TabsMenu); + internal::setToolTip(TabsMenuButton, QObject::tr("List All Tabs")); + TabsMenuButton->setSizePolicy(ButtonSizePolicy); + Layout->addWidget(TabsMenuButton, 0); + _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), + SLOT(onTabsMenuActionTriggered(QAction*))); + + // Undock button + UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton)); + UndockButton->setObjectName("detachGroupButton"); + UndockButton->setAutoRaise(true); + internal::setToolTip(UndockButton, QObject::tr("Detach Group")); + internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon); + UndockButton->setSizePolicy(ButtonSizePolicy); + Layout->addWidget(UndockButton, 0); + _this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked())); + + // Close button + CloseButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasCloseButton)); + CloseButton->setObjectName("dockAreaCloseButton"); + CloseButton->setAutoRaise(true); + internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon); + if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) + { + internal::setToolTip(CloseButton, QObject::tr("Close Active Tab")); + } + else + { + internal::setToolTip(CloseButton, QObject::tr("Close Group")); + } + CloseButton->setSizePolicy(ButtonSizePolicy); + CloseButton->setIconSize(QSize(16, 16)); + Layout->addWidget(CloseButton, 0); + _this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked())); +} + + +//============================================================================ +void DockAreaTitleBarPrivate::createTabBar() +{ + TabBar = componentsFactory()->createDockAreaTabBar(DockArea); + TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + Layout->addWidget(TabBar); + _this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated())); + _this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated())); + _this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated())); + _this->connect(TabBar, SIGNAL(removingTab(int)), SLOT(markTabsMenuOutdated())); + _this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated())); + _this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int))); + _this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int))); + _this->connect(TabBar, SIGNAL(elidedChanged(bool)), SLOT(markTabsMenuOutdated())); +} + + +//============================================================================ +IFloatingWidget* DockAreaTitleBarPrivate::makeAreaFloating(const QPoint& Offset, eDragState DragState) +{ + QSize Size = DockArea->size(); + this->DragState = DragState; + bool OpaqueUndocking = CDockManager::testConfigFlag(CDockManager::OpaqueUndocking) || + (DraggingFloatingWidget != DragState); + CFloatingDockContainer* FloatingDockContainer = nullptr; + IFloatingWidget* FloatingWidget; + if (OpaqueUndocking) + { + FloatingWidget = FloatingDockContainer = new CFloatingDockContainer(DockArea); + } + else + { + auto w = new CFloatingDragPreview(DockArea); + QObject::connect(w, &CFloatingDragPreview::draggingCanceled, [=]() + { + this->DragState = DraggingInactive; + }); + FloatingWidget = w; + } + + FloatingWidget->startFloating(Offset, Size, DragState, nullptr); + if (FloatingDockContainer) + { + auto TopLevelDockWidget = FloatingDockContainer->topLevelDockWidget(); + if (TopLevelDockWidget) + { + TopLevelDockWidget->emitTopLevelChanged(true); + } + } + + return FloatingWidget; +} + + +//============================================================================ +void DockAreaTitleBarPrivate::startFloating(const QPoint& Offset) +{ + FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget); +} + + +//============================================================================ +CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) : + QFrame(parent), + d(new DockAreaTitleBarPrivate(this)) +{ + d->DockArea = parent; + + setObjectName("dockAreaTitleBar"); + d->Layout = new QBoxLayout(QBoxLayout::LeftToRight); + d->Layout->setContentsMargins(0, 0, 0, 0); + d->Layout->setSpacing(0); + setLayout(d->Layout); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + d->createTabBar(); + d->Layout->addWidget(new CSpacerWidget(this)); + d->createButtons(); + + setFocusPolicy(Qt::NoFocus); +} + + +//============================================================================ +CDockAreaTitleBar::~CDockAreaTitleBar() +{ + if (!d->CloseButton.isNull()) + { + delete d->CloseButton; + } + + if (!d->TabsMenuButton.isNull()) + { + delete d->TabsMenuButton; + } + + if (!d->UndockButton.isNull()) + { + delete d->UndockButton; + } + delete d; +} + + +//============================================================================ +CDockAreaTabBar* CDockAreaTitleBar::tabBar() const +{ + return d->TabBar; +} + +//============================================================================ +void CDockAreaTitleBar::markTabsMenuOutdated() +{ + if(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility)) + { + bool hasElidedTabTitle = false; + for (int i = 0; i < d->TabBar->count(); ++i) + { + if (!d->TabBar->isTabOpen(i)) + { + continue; + } + CDockWidgetTab* Tab = d->TabBar->tab(i); + if(Tab->isTitleElided()) + { + hasElidedTabTitle = true; + break; + } + } + bool visible = (hasElidedTabTitle && (d->TabBar->count() > 1)); + QMetaObject::invokeMethod(d->TabsMenuButton, "setVisible", Qt::QueuedConnection, Q_ARG(bool, visible)); + } + d->MenuOutdated = true; +} + +//============================================================================ +void CDockAreaTitleBar::onTabsMenuAboutToShow() +{ + if (!d->MenuOutdated) + { + return; + } + + QMenu* menu = d->TabsMenuButton->menu(); + menu->clear(); + for (int i = 0; i < d->TabBar->count(); ++i) + { + if (!d->TabBar->isTabOpen(i)) + { + continue; + } + auto Tab = d->TabBar->tab(i); + QAction* Action = menu->addAction(Tab->icon(), Tab->text()); + internal::setToolTip(Action, Tab->toolTip()); + Action->setData(i); + } + + d->MenuOutdated = false; +} + + +//============================================================================ +void CDockAreaTitleBar::onCloseButtonClicked() +{ + ADS_PRINT("CDockAreaTitleBar::onCloseButtonClicked"); + if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) + { + d->TabBar->closeTab(d->TabBar->currentIndex()); + } + else + { + d->DockArea->closeArea(); + } +} + + +//============================================================================ +void CDockAreaTitleBar::onUndockButtonClicked() +{ + if (d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)) + { + d->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive); + } +} + + +//============================================================================ +void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action) +{ + int Index = Action->data().toInt(); + d->TabBar->setCurrentIndex(Index); + Q_EMIT tabBarClicked(Index); +} + + +//============================================================================ +void CDockAreaTitleBar::updateDockWidgetActionsButtons() +{ + CDockWidget* DockWidget = d->TabBar->currentTab()->dockWidget(); + if (!d->DockWidgetActionsButtons.isEmpty()) + { + for (auto Button : d->DockWidgetActionsButtons) + { + d->Layout->removeWidget(Button); + delete Button; + } + d->DockWidgetActionsButtons.clear(); + } + + auto Actions = DockWidget->titleBarActions(); + if (Actions.isEmpty()) + { + return; + } + + int InsertIndex = indexOf(d->TabsMenuButton); + for (auto Action : Actions) + { + auto Button = new CTitleBarButton(true, this); + Button->setDefaultAction(Action); + Button->setAutoRaise(true); + Button->setPopupMode(QToolButton::InstantPopup); + Button->setObjectName(Action->objectName()); + d->Layout->insertWidget(InsertIndex++, Button, 0); + d->DockWidgetActionsButtons.append(Button); + } +} + + +//============================================================================ +void CDockAreaTitleBar::onCurrentTabChanged(int Index) +{ + if (Index < 0) + { + return; + } + + if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) + { + CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget(); + d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable)); + } + + updateDockWidgetActionsButtons(); +} + + +//============================================================================ +QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const +{ + switch (which) + { + case TitleBarButtonTabsMenu: return d->TabsMenuButton; + case TitleBarButtonUndock: return d->UndockButton; + case TitleBarButtonClose: return d->CloseButton; + default: + return nullptr; + } +} + + +//============================================================================ +void CDockAreaTitleBar::setVisible(bool Visible) +{ + Super::setVisible(Visible); + markTabsMenuOutdated(); +} + + +//============================================================================ +void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev) +{ + if (ev->button() == Qt::LeftButton) + { + ev->accept(); + d->DragStartMousePos = ev->pos(); + d->DragState = DraggingMousePressed; + + if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) + { + //d->TabBar->currentTab()->setFocus(Qt::OtherFocusReason); + d->dockManager()->dockFocusController()->setDockWidgetTabFocused(d->TabBar->currentTab()); + } + return; + } + Super::mousePressEvent(ev); +} + + +//============================================================================ +void CDockAreaTitleBar::mouseReleaseEvent(QMouseEvent* ev) +{ + if (ev->button() == Qt::LeftButton) + { + ADS_PRINT("CDockAreaTitleBar::mouseReleaseEvent"); + ev->accept(); + auto CurrentDragState = d->DragState; + d->DragStartMousePos = QPoint(); + d->DragState = DraggingInactive; + if (DraggingFloatingWidget == CurrentDragState) + { + d->FloatingWidget->finishDragging(); + } + + return; + } + Super::mouseReleaseEvent(ev); +} + + +//============================================================================ +void CDockAreaTitleBar::mouseMoveEvent(QMouseEvent* ev) +{ + Super::mouseMoveEvent(ev); + if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive)) + { + d->DragState = DraggingInactive; + return; + } + + // move floating window + if (d->isDraggingState(DraggingFloatingWidget)) + { + d->FloatingWidget->moveFloating(); + return; + } + + // If this is the last dock area in a floating dock container it does not make + // sense to move it to a new floating widget and leave this one + // empty + if (d->DockArea->dockContainer()->isFloating() + && d->DockArea->dockContainer()->visibleDockAreaCount() == 1) + { + return; + } + + // If one single dock widget in this area is not floatable then the whole + // area is not floatable + // If we do non opaque undocking, then we can create the floating drag + // preview if the dock widget is movable + auto Features = d->DockArea->features(); + if (!Features.testFlag(CDockWidget::DockWidgetFloatable) + && !(Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking))) + { + return; + } + + int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength(); + if (DragDistance >= CDockManager::startDragDistance()) + { + ADS_PRINT("CDockAreaTitlBar::startFloating"); + d->startFloating(d->DragStartMousePos); + auto Overlay = d->DockArea->dockManager()->containerOverlay(); + Overlay->setAllowedAreas(OuterDockAreas); + } + + return; +} + + +//============================================================================ +void CDockAreaTitleBar::mouseDoubleClickEvent(QMouseEvent *event) +{ + // If this is the last dock area in a dock container it does not make + // sense to move it to a new floating widget and leave this one + // empty + if (d->DockArea->dockContainer()->isFloating() && d->DockArea->dockContainer()->dockAreaCount() == 1) + { + return; + } + + if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)) + { + return; + } + d->makeAreaFloating(event->pos(), DraggingInactive); +} + + +//============================================================================ +void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) +{ + ev->accept(); + if (d->isDraggingState(DraggingFloatingWidget)) + { + return; + } + + QMenu Menu(this); + auto Action = Menu.addAction(tr("Detach Group"), this, SLOT(onUndockButtonClicked())); + Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)); + Menu.addSeparator(); + Action = Menu.addAction(tr("Close Group"), this, SLOT(onCloseButtonClicked())); + Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable)); + Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas())); + Menu.exec(ev->globalPos()); +} + + +//============================================================================ +void CDockAreaTitleBar::insertWidget(int index, QWidget *widget) +{ + d->Layout->insertWidget(index, widget); +} + + +//============================================================================ +int CDockAreaTitleBar::indexOf(QWidget *widget) const +{ + return d->Layout->indexOf(widget); +} + +//============================================================================ +CTitleBarButton::CTitleBarButton(bool visible, QWidget* parent) + : tTitleBarButton(parent), + Visible(visible), + HideWhenDisabled(CDockManager::testConfigFlag(CDockManager::DockAreaHideDisabledButtons)) +{ + setFocusPolicy(Qt::NoFocus); +} + +//============================================================================ +void CTitleBarButton::setVisible(bool visible) +{ + // 'visible' can stay 'true' if and only if this button is configured to generaly visible: + visible = visible && this->Visible; + + // 'visible' can stay 'true' unless: this button is configured to be invisible when it is disabled and it is currently disabled: + if (visible && HideWhenDisabled) + { + visible = isEnabled(); + } + + Super::setVisible(visible); +} + +//============================================================================ +bool CTitleBarButton::event(QEvent *ev) +{ + if (QEvent::EnabledChange == ev->type() && HideWhenDisabled) + { + // force setVisible() call + // Calling setVisible() directly here doesn't work well when button is expected to be shown first time + QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled())); + } + + return Super::event(ev); +} + +//============================================================================ +CSpacerWidget::CSpacerWidget(QWidget* Parent /*= 0*/) : Super(Parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setStyleSheet("border: none; background: none;"); +} + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockAreaTitleBar.cpp diff --git a/ads/DockAreaTitleBar.h b/ads/DockAreaTitleBar.h new file mode 100644 index 0000000..37f3a91 --- /dev/null +++ b/ads/DockAreaTitleBar.h @@ -0,0 +1,162 @@ +#ifndef DockAreaTitleBarH +#define DockAreaTitleBarH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaTitleBar.h +/// \author Uwe Kindler +/// \date 12.10.2018 +/// \brief Declaration of CDockAreaTitleBar class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include "ads_globals.h" + +QT_FORWARD_DECLARE_CLASS(QAbstractButton) + +namespace ads +{ +class CDockAreaTabBar; +class CDockAreaWidget; +struct DockAreaTitleBarPrivate; + +/** + * Title bar of a dock area. + * The title bar contains a tabbar with all tabs for a dock widget group and + * with a tabs menu button, a undock button and a close button. + */ +class ADS_EXPORT CDockAreaTitleBar : public QFrame +{ + Q_OBJECT +private: + DockAreaTitleBarPrivate* d; ///< private data (pimpl) + friend struct DockAreaTitleBarPrivate; + +private Q_SLOTS: + void onTabsMenuAboutToShow(); + void onCloseButtonClicked(); + void onUndockButtonClicked(); + void onTabsMenuActionTriggered(QAction* Action); + void onCurrentTabChanged(int Index); + +protected: + /** + * Stores mouse position to detect dragging + */ + virtual void mousePressEvent(QMouseEvent* ev) override; + + /** + * Stores mouse position to detect dragging + */ + virtual void mouseReleaseEvent(QMouseEvent* ev) override; + + /** + * Starts floating the complete docking area including all dock widgets, + * if it is not the last dock area in a floating widget + */ + virtual void mouseMoveEvent(QMouseEvent* ev) override; + + /** + * Double clicking the title bar also starts floating of the complete area + */ + virtual void mouseDoubleClickEvent(QMouseEvent *event) override; + + /** + * Show context menu + */ + virtual void contextMenuEvent(QContextMenuEvent *event) override; + +public Q_SLOTS: + /** + * Call this slot to tell the title bar that it should update the tabs menu + * the next time it is shown. + */ + void markTabsMenuOutdated(); + + +public: + using Super = QFrame; + + /** + * Default Constructor + */ + CDockAreaTitleBar(CDockAreaWidget* parent); + + /** + * Virtual Destructor + */ + virtual ~CDockAreaTitleBar(); + + /** + * Returns the pointer to the tabBar() + */ + CDockAreaTabBar* tabBar() const; + + /** + * Returns the button corresponding to the given title bar button identifier + */ + QAbstractButton* button(TitleBarButton which) const; + + /** + * Updates the visibility of the dock widget actions in the title bar + */ + void updateDockWidgetActionsButtons(); + + /** + * Marks the tabs menu outdated before it calls its base class + * implementation + */ + virtual void setVisible(bool Visible) override; + + /** + * Inserts a custom widget at position index into this title bar. + * If index is negative, the widget is added at the end. + * You can use this function to insert custom widgets into the title bar. + */ + void insertWidget(int index, QWidget *widget); + + /** + * Searches for widget widget in this title bar. + * You can use this function, to get the position of the default + * widget in the tile bar. + * \code + * int tabBarIndex = TitleBar->indexOf(TitleBar->tabBar()); + * int closeButtonIndex = TitleBar->indexOf(TitleBar->button(TitleBarButtonClose)); + * \endcode + */ + int indexOf(QWidget *widget) const; + +Q_SIGNALS: + /** + * This signal is emitted if a tab in the tab bar is clicked by the user + * or if the user clicks on a tab item in the title bar tab menu. + */ + void tabBarClicked(int index); +}; // class name + +} + // namespace ads +//----------------------------------------------------------------------------- +#endif // DockAreaTitleBarH diff --git a/ads/DockAreaTitleBar_p.h b/ads/DockAreaTitleBar_p.h new file mode 100644 index 0000000..b94a510 --- /dev/null +++ b/ads/DockAreaTitleBar_p.h @@ -0,0 +1,94 @@ +#ifndef DockAreaTitleBar_pH +#define DockAreaTitleBar_pH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaTitleBar_p.h +/// \author Uwe Kindler +/// \date 12.10.2018 +/// \brief Declaration of classes CTitleBarButton and CSpacerWidget +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include + +#include "ads_globals.h" + +namespace ads +{ +using tTitleBarButton = QToolButton; + +/** +* Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour +* according to various config flags such as: +* CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible +* CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled +*/ +class CTitleBarButton : public tTitleBarButton +{ + Q_OBJECT + +private: + bool Visible = true; + bool HideWhenDisabled = false; + +public: + using Super = tTitleBarButton; + CTitleBarButton(bool visible = true, QWidget* parent = nullptr); + + /** + * Adjust this visibility change request with our internal settings: + */ + virtual void setVisible(bool visible) override; + +protected: + /** + * Handle EnabledChanged signal to set button invisible if the configured + */ + bool event(QEvent *ev) override; +}; + + +/** +* This spacer widget is here because of the following problem. +* The dock area title bar handles mouse dragging and moving the floating widget. +* The problem is, that if the title bar becomes invisible, i.e. if the dock +* area contains only one single dock widget and the dock area is moved +* into a floating widget, then mouse events are not handled anymore and dragging +* of the floating widget stops. +*/ +class CSpacerWidget : public QWidget +{ + Q_OBJECT +public: + using Super = QWidget; + CSpacerWidget(QWidget* Parent = 0); + virtual QSize sizeHint() const override {return QSize(0, 0);} + virtual QSize minimumSizeHint() const override {return QSize(0, 0);} +}; + +} + // namespace ads +//----------------------------------------------------------------------------- +#endif // DockAreaTitleBar_pH diff --git a/ads/DockAreaWidget.cpp b/ads/DockAreaWidget.cpp new file mode 100644 index 0000000..2a33484 --- /dev/null +++ b/ads/DockAreaWidget.cpp @@ -0,0 +1,1051 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaWidget.cpp +/// \author Uwe Kindler +/// \date 24.02.2017 +/// \brief Implementation of CDockAreaWidget class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockAreaWidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "DockContainerWidget.h" +#include "DockWidget.h" +#include "FloatingDockContainer.h" +#include "DockManager.h" +#include "DockOverlay.h" +#include "DockAreaTabBar.h" +#include "DockSplitter.h" +#include "DockAreaTitleBar.h" +#include "DockComponentsFactory.h" +#include "DockWidgetTab.h" + + +namespace ads +{ +static const char* const INDEX_PROPERTY = "index"; +static const char* const ACTION_PROPERTY = "action"; + +/** + * Internal dock area layout mimics stack layout but only inserts the current + * widget into the internal QLayout object. + * \warning Only the current widget has a parent. All other widgets + * do not have a parent. That means, a widget that is in this layout may + * return nullptr for its parent() function if it is not the current widget. + */ +class CDockAreaLayout +{ +private: + QBoxLayout* m_ParentLayout; + QList m_Widgets; + int m_CurrentIndex = -1; + QWidget* m_CurrentWidget = nullptr; + +public: + /** + * Creates an instance with the given parent layout + */ + CDockAreaLayout(QBoxLayout* ParentLayout) + : m_ParentLayout(ParentLayout) + { + + } + + /** + * Returns the number of widgets in this layout + */ + int count() const + { + return m_Widgets.count(); + } + + /** + * Inserts the widget at the given index position into the internal widget + * list + */ + void insertWidget(int index, QWidget* Widget) + { + Widget->setParent(nullptr); + if (index < 0) + { + index = m_Widgets.count(); + } + m_Widgets.insert(index, Widget); + if (m_CurrentIndex < 0) + { + setCurrentIndex(index); + } + else + { + if (index <= m_CurrentIndex ) + { + ++m_CurrentIndex; + } + } + } + + /** + * Removes the given widget from the layout + */ + void removeWidget(QWidget* Widget) + { + if (currentWidget() == Widget) + { + auto LayoutItem = m_ParentLayout->takeAt(1); + if (LayoutItem) + { + LayoutItem->widget()->setParent(nullptr); + } + m_CurrentWidget = nullptr; + m_CurrentIndex = -1; + } + else if (indexOf(Widget) < m_CurrentIndex) + { + --m_CurrentIndex; + } + m_Widgets.removeOne(Widget); + } + + /** + * Returns the current selected widget + */ + QWidget* currentWidget() const + { + return m_CurrentWidget; + } + + /** + * Activates the widget with the give index. + */ + void setCurrentIndex(int index) + { + QWidget *prev = currentWidget(); + QWidget *next = widget(index); + if (!next || (next == prev && !m_CurrentWidget)) + { + return; + } + + bool reenableUpdates = false; + QWidget *parent = m_ParentLayout->parentWidget(); + + if (parent && parent->updatesEnabled()) + { + reenableUpdates = true; + parent->setUpdatesEnabled(false); + } + + auto LayoutItem = m_ParentLayout->takeAt(1); + if (LayoutItem) + { + LayoutItem->widget()->setParent(nullptr); + } + delete LayoutItem; + + m_ParentLayout->addWidget(next); + if (prev) + { + prev->hide(); + } + m_CurrentIndex = index; + m_CurrentWidget = next; + + + if (reenableUpdates) + { + parent->setUpdatesEnabled(true); + } + } + + /** + * Returns the index of the current active widget + */ + int currentIndex() const + { + return m_CurrentIndex; + } + + /** + * Returns true if there are no widgets in the layout + */ + bool isEmpty() const + { + return m_Widgets.empty(); + } + + /** + * Returns the index of the given widget + */ + int indexOf(QWidget* w) const + { + return m_Widgets.indexOf(w); + } + + /** + * Returns the widget for the given index + */ + QWidget* widget(int index) const + { + return (index < m_Widgets.size()) ? m_Widgets.at(index) : nullptr; + } + + /** + * Returns the geometry of the current active widget + */ + QRect geometry() const + { + return m_Widgets.empty() ? QRect() : currentWidget()->geometry(); + } +}; + + + +using DockAreaLayout = CDockAreaLayout; +static const DockWidgetAreas DefaultAllowedAreas = AllDockAreas; + + +/** + * Private data class of CDockAreaWidget class (pimpl) + */ +struct DockAreaWidgetPrivate +{ + CDockAreaWidget* _this = nullptr; + QBoxLayout* Layout = nullptr; + DockAreaLayout* ContentsLayout = nullptr; + CDockAreaTitleBar* TitleBar = nullptr; + CDockManager* DockManager = nullptr; + bool UpdateTitleBarButtons = false; + DockWidgetAreas AllowedAreas = DefaultAllowedAreas; + QSize MinSizeHint; + CDockAreaWidget::DockAreaFlags Flags{CDockAreaWidget::DefaultFlags}; + + /** + * Private data constructor + */ + DockAreaWidgetPrivate(CDockAreaWidget* _public); + + /** + * Creates the layout for top area with tabs and close button + */ + void createTitleBar(); + + /** + * Returns the dock widget with the given index + */ + CDockWidget* dockWidgetAt(int index) + { + return qobject_cast(ContentsLayout->widget(index)); + } + + /** + * Convenience function to ease title widget access by index + */ + CDockWidgetTab* tabWidgetAt(int index) + { + return dockWidgetAt(index)->tabWidget(); + } + + + /** + * Returns the tab action of the given dock widget + */ + QAction* dockWidgetTabAction(CDockWidget* DockWidget) const + { + return qvariant_cast(DockWidget->property(ACTION_PROPERTY)); + } + + /** + * Returns the index of the given dock widget + */ + int dockWidgetIndex(CDockWidget* DockWidget) const + { + return DockWidget->property(INDEX_PROPERTY).toInt(); + } + + /** + * Convenience function for tabbar access + */ + CDockAreaTabBar* tabBar() const + { + return TitleBar->tabBar(); + } + + /** + * Udpates the enable state of the close and detach button + */ + void updateTitleBarButtonStates(); + + /** + * Scans all contained dock widgets for the max. minimum size hint + */ + void updateMinimumSizeHint() + { + MinSizeHint = QSize(); + for (int i = 0; i < ContentsLayout->count(); ++i) + { + auto Widget = ContentsLayout->widget(i); + MinSizeHint.setHeight(qMax(MinSizeHint.height(), Widget->minimumSizeHint().height())); + MinSizeHint.setWidth(qMax(MinSizeHint.width(), Widget->minimumSizeHint().width())); + } + } +}; + + +//============================================================================ +DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockAreaWidgetPrivate::createTitleBar() +{ + TitleBar = componentsFactory()->createDockAreaTitleBar(_this); + Layout->addWidget(TitleBar); + QObject::connect(tabBar(), &CDockAreaTabBar::tabCloseRequested, _this, &CDockAreaWidget::onTabCloseRequested); + QObject::connect(TitleBar, &CDockAreaTitleBar::tabBarClicked, _this, &CDockAreaWidget::setCurrentIndex); + QObject::connect(tabBar(), &CDockAreaTabBar::tabMoved, _this, &CDockAreaWidget::reorderDockWidget); +} + + +//============================================================================ +void DockAreaWidgetPrivate::updateTitleBarButtonStates() +{ + if (_this->isHidden()) + { + UpdateTitleBarButtons = true; + return; + } + + TitleBar->button(TitleBarButtonClose)->setEnabled( + _this->features().testFlag(CDockWidget::DockWidgetClosable)); + TitleBar->button(TitleBarButtonUndock)->setEnabled( + _this->features().testFlag(CDockWidget::DockWidgetFloatable)); + TitleBar->updateDockWidgetActionsButtons(); + UpdateTitleBarButtons = false; +} + + +//============================================================================ +CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) : + QFrame(parent), + d(new DockAreaWidgetPrivate(this)) +{ + d->DockManager = DockManager; + d->Layout = new QBoxLayout(QBoxLayout::TopToBottom); + d->Layout->setContentsMargins(0, 0, 0, 0); + d->Layout->setSpacing(0); + setLayout(d->Layout); + + d->createTitleBar(); + d->ContentsLayout = new DockAreaLayout(d->Layout); + if (d->DockManager) + { + Q_EMIT d->DockManager->dockAreaCreated(this); + } +} + +//============================================================================ +CDockAreaWidget::~CDockAreaWidget() +{ + ADS_PRINT("~CDockAreaWidget()"); + delete d->ContentsLayout; + delete d; +} + + +//============================================================================ +CDockManager* CDockAreaWidget::dockManager() const +{ + return d->DockManager; +} + + +//============================================================================ +CDockContainerWidget* CDockAreaWidget::dockContainer() const +{ + return internal::findParent(this); +} + + +//============================================================================ +void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget) +{ + insertDockWidget(d->ContentsLayout->count(), DockWidget); +} + + +//============================================================================ +void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget, + bool Activate) +{ + d->ContentsLayout->insertWidget(index, DockWidget); + DockWidget->setDockArea(this); + DockWidget->tabWidget()->setDockAreaWidget(this); + auto TabWidget = DockWidget->tabWidget(); + // Inserting the tab will change the current index which in turn will + // make the tab widget visible in the slot + d->tabBar()->blockSignals(true); + d->tabBar()->insertTab(index, TabWidget); + d->tabBar()->blockSignals(false); + TabWidget->setVisible(!DockWidget->isClosed()); + DockWidget->setProperty(INDEX_PROPERTY, index); + d->MinSizeHint.setHeight(qMax(d->MinSizeHint.height(), DockWidget->minimumSizeHint().height())); + d->MinSizeHint.setWidth(qMax(d->MinSizeHint.width(), DockWidget->minimumSizeHint().width())); + if (Activate) + { + setCurrentIndex(index); + } + // If this dock area is hidden, then we need to make it visible again + // by calling DockWidget->toggleViewInternal(true); + if (!this->isVisible() && d->ContentsLayout->count() > 1 && !dockManager()->isRestoringState()) + { + DockWidget->toggleViewInternal(true); + } + d->updateTitleBarButtonStates(); + updateTitleBarVisibility(); +} + + +//============================================================================ +void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget) +{ + ADS_PRINT("CDockAreaWidget::removeDockWidget"); + auto CurrentDockWidget = currentDockWidget(); + auto NextOpenDockWidget = (DockWidget == CurrentDockWidget) ? nextOpenDockWidget(DockWidget) : nullptr; + + d->ContentsLayout->removeWidget(DockWidget); + auto TabWidget = DockWidget->tabWidget(); + TabWidget->hide(); + d->tabBar()->removeTab(TabWidget); + TabWidget->setParent(DockWidget); + DockWidget->setDockArea(nullptr); + CDockContainerWidget* DockContainer = dockContainer(); + if (NextOpenDockWidget) + { + setCurrentDockWidget(NextOpenDockWidget); + } + else if (d->ContentsLayout->isEmpty() && DockContainer->dockAreaCount() >= 1) + { + ADS_PRINT("Dock Area empty"); + DockContainer->removeDockArea(this); + this->deleteLater(); + if(DockContainer->dockAreaCount() == 0) + { + if(CFloatingDockContainer* FloatingDockContainer = DockContainer->floatingWidget()) + { + FloatingDockContainer->hide(); + FloatingDockContainer->deleteLater(); + } + } + } + else if (DockWidget == CurrentDockWidget) + { + // if contents layout is not empty but there are no more open dock + // widgets, then we need to hide the dock area because it does not + // contain any visible content + hideAreaWithNoVisibleContent(); + } + + d->updateTitleBarButtonStates(); + updateTitleBarVisibility(); + d->updateMinimumSizeHint(); + auto TopLevelDockWidget = DockContainer->topLevelDockWidget(); + if (TopLevelDockWidget) + { + TopLevelDockWidget->emitTopLevelChanged(true); + } + +#if (ADS_DEBUG_LEVEL > 0) + DockContainer->dumpLayout(); +#endif +} + + +//============================================================================ +void CDockAreaWidget::hideAreaWithNoVisibleContent() +{ + this->toggleView(false); + + // Hide empty parent splitters + auto Splitter = internal::findParent(this); + internal::hideEmptyParentSplitters(Splitter); + + //Hide empty floating widget + CDockContainerWidget* Container = this->dockContainer(); + if (!Container->isFloating() && !CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar)) + { + return; + } + + updateTitleBarVisibility(); + auto TopLevelWidget = Container->topLevelDockWidget(); + auto FloatingWidget = Container->floatingWidget(); + if (TopLevelWidget) + { + if (FloatingWidget) + { + FloatingWidget->updateWindowTitle(); + } + CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true); + } + else if (Container->openedDockAreas().isEmpty() && FloatingWidget) + { + FloatingWidget->hide(); + } +} + + +//============================================================================ +void CDockAreaWidget::onTabCloseRequested(int Index) +{ + ADS_PRINT("CDockAreaWidget::onTabCloseRequested " << Index); + auto* DockWidget = dockWidget(Index); + if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose)) + { + DockWidget->closeDockWidgetInternal(); + } + else + { + DockWidget->toggleView(false); + } +} + + +//============================================================================ +CDockWidget* CDockAreaWidget::currentDockWidget() const +{ + int CurrentIndex = currentIndex(); + if (CurrentIndex < 0) + { + return nullptr; + } + + return dockWidget(CurrentIndex); +} + + +//============================================================================ +void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget) +{ + if (dockManager()->isRestoringState()) + { + return; + } + + internalSetCurrentDockWidget(DockWidget); +} + + +//============================================================================ +void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget) +{ + int Index = index(DockWidget); + if (Index < 0) + { + return; + } + + setCurrentIndex(Index); +} + + +//============================================================================ +void CDockAreaWidget::setCurrentIndex(int index) +{ + auto TabBar = d->tabBar(); + if (index < 0 || index > (TabBar->count() - 1)) + { + qWarning() << Q_FUNC_INFO << "Invalid index" << index; + return; + } + + auto cw = d->ContentsLayout->currentWidget(); + auto nw = d->ContentsLayout->widget(index); + if (cw == nw && !nw->isHidden()) + { + return; + } + + Q_EMIT currentChanging(index); + TabBar->setCurrentIndex(index); + d->ContentsLayout->setCurrentIndex(index); + d->ContentsLayout->currentWidget()->show(); + Q_EMIT currentChanged(index); +} + + +//============================================================================ +int CDockAreaWidget::currentIndex() const +{ + return d->ContentsLayout->currentIndex(); +} + + +//============================================================================ +QRect CDockAreaWidget::titleBarGeometry() const +{ + return d->TitleBar->geometry(); +} + +//============================================================================ +QRect CDockAreaWidget::contentAreaGeometry() const +{ + return d->ContentsLayout->geometry(); +} + + +//============================================================================ +int CDockAreaWidget::index(CDockWidget* DockWidget) +{ + return d->ContentsLayout->indexOf(DockWidget); +} + + +//============================================================================ +QList CDockAreaWidget::dockWidgets() const +{ + QList DockWidgetList; + for (int i = 0; i < d->ContentsLayout->count(); ++i) + { + DockWidgetList.append(dockWidget(i)); + } + return DockWidgetList; +} + + +//============================================================================ +int CDockAreaWidget::openDockWidgetsCount() const +{ + int Count = 0; + for (int i = 0; i < d->ContentsLayout->count(); ++i) + { + if (!dockWidget(i)->isClosed()) + { + ++Count; + } + } + return Count; +} + + +//============================================================================ +QList CDockAreaWidget::openedDockWidgets() const +{ + QList DockWidgetList; + for (int i = 0; i < d->ContentsLayout->count(); ++i) + { + CDockWidget* DockWidget = dockWidget(i); + if (!DockWidget->isClosed()) + { + DockWidgetList.append(dockWidget(i)); + } + } + return DockWidgetList; +} + + +//============================================================================ +int CDockAreaWidget::indexOfFirstOpenDockWidget() const +{ + for (int i = 0; i < d->ContentsLayout->count(); ++i) + { + if (!dockWidget(i)->isClosed()) + { + return i; + } + } + + return -1; +} + + +//============================================================================ +int CDockAreaWidget::dockWidgetsCount() const +{ + return d->ContentsLayout->count(); +} + + +//============================================================================ +CDockWidget* CDockAreaWidget::dockWidget(int Index) const +{ + return qobject_cast(d->ContentsLayout->widget(Index)); +} + + +//============================================================================ +void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex) +{ + ADS_PRINT("CDockAreaWidget::reorderDockWidget"); + if (fromIndex >= d->ContentsLayout->count() || fromIndex < 0 + || toIndex >= d->ContentsLayout->count() || toIndex < 0 || fromIndex == toIndex) + { + ADS_PRINT("Invalid index for tab movement" << fromIndex << toIndex); + return; + } + + auto Widget = d->ContentsLayout->widget(fromIndex); + d->ContentsLayout->removeWidget(Widget); + d->ContentsLayout->insertWidget(toIndex, Widget); + setCurrentIndex(toIndex); +} + + +//============================================================================ +void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open) +{ + Q_UNUSED(DockWidget); + Q_UNUSED(Open); + updateTitleBarVisibility(); +} + + +//============================================================================ +void CDockAreaWidget::updateTitleBarVisibility() +{ + CDockContainerWidget* Container = dockContainer(); + if (!Container) + { + return; + } + + if (CDockManager::testConfigFlag(CDockManager::AlwaysShowTabs)) + { + return; + } + + if (d->TitleBar) + { + bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating() + || CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar)); + Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1); + d->TitleBar->setVisible(!Hidden); + } +} + + +//============================================================================ +void CDockAreaWidget::markTitleBarMenuOutdated() +{ + if (d->TitleBar) + { + d->TitleBar->markTabsMenuOutdated(); + } +} + + + +//============================================================================ +void CDockAreaWidget::saveState(QXmlStreamWriter& s) const +{ + s.writeStartElement("Area"); + s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count())); + auto CurrentDockWidget = currentDockWidget(); + QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : ""; + s.writeAttribute("Current", Name); + // To keep the saved XML data small, we only save the allowed areas and the + // dock area flags if the values are different from the default values + if (d->AllowedAreas != DefaultAllowedAreas) + { + s.writeAttribute("AllowedAreas", QString::number(d->AllowedAreas, 16)); + } + + if (d->Flags != DefaultFlags) + { + s.writeAttribute("Flags", QString::number(d->Flags, 16)); + } + ADS_PRINT("CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count() + << " Current: " << Name); + for (int i = 0; i < d->ContentsLayout->count(); ++i) + { + dockWidget(i)->saveState(s); + } + s.writeEndElement(); +} + + +//============================================================================ +CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const +{ + auto OpenDockWidgets = openedDockWidgets(); + if (OpenDockWidgets.count() > 1 || (OpenDockWidgets.count() == 1 && OpenDockWidgets[0] != DockWidget)) + { + if (OpenDockWidgets.last() == DockWidget) + { + CDockWidget* NextDockWidget = OpenDockWidgets[OpenDockWidgets.count() - 2]; + // search backwards for widget with tab + for (int i = OpenDockWidgets.count() - 2; i >= 0; --i) + { + auto dw = OpenDockWidgets[i]; + if (!dw->features().testFlag(CDockWidget::NoTab)) + { + return dw; + } + } + + // return widget without tab + return NextDockWidget; + } + else + { + int IndexOfDockWidget = OpenDockWidgets.indexOf(DockWidget); + CDockWidget* NextDockWidget = OpenDockWidgets[IndexOfDockWidget + 1]; + // search forwards for widget with tab + for (int i = IndexOfDockWidget + 1; i < OpenDockWidgets.count(); ++i) + { + auto dw = OpenDockWidgets[i]; + if (!dw->features().testFlag(CDockWidget::NoTab)) + { + return dw; + } + } + + // search backwards for widget with tab + for (int i = IndexOfDockWidget - 1; i >= 0; --i) + { + auto dw = OpenDockWidgets[i]; + if (!dw->features().testFlag(CDockWidget::NoTab)) + { + return dw; + } + } + + // return widget without tab + return NextDockWidget; + } + } + else + { + return nullptr; + } +} + + +//============================================================================ +CDockWidget::DockWidgetFeatures CDockAreaWidget::features(eBitwiseOperator Mode) const +{ + if (BitwiseAnd == Mode) + { + CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures); + for (const auto DockWidget : dockWidgets()) + { + Features &= DockWidget->features(); + } + return Features; + } + else + { + CDockWidget::DockWidgetFeatures Features(CDockWidget::NoDockWidgetFeatures); + for (const auto DockWidget : dockWidgets()) + { + Features |= DockWidget->features(); + } + return Features; + } +} + + +//============================================================================ +void CDockAreaWidget::toggleView(bool Open) +{ + setVisible(Open); + + Q_EMIT viewToggled(Open); +} + + +//============================================================================ +void CDockAreaWidget::setVisible(bool Visible) +{ + Super::setVisible(Visible); + if (d->UpdateTitleBarButtons) + { + d->updateTitleBarButtonStates(); + } +} + + +//============================================================================ +void CDockAreaWidget::setAllowedAreas(DockWidgetAreas areas) +{ + d->AllowedAreas = areas; +} + + +//============================================================================ +DockWidgetAreas CDockAreaWidget::allowedAreas() const +{ + return d->AllowedAreas; +} + + +//============================================================================ +CDockAreaWidget::DockAreaFlags CDockAreaWidget::dockAreaFlags() const +{ + return d->Flags; +} + + +//============================================================================ +void CDockAreaWidget::setDockAreaFlags(DockAreaFlags Flags) +{ + auto ChangedFlags = d->Flags ^ Flags; + d->Flags = Flags; + if (ChangedFlags.testFlag(HideSingleWidgetTitleBar)) + { + updateTitleBarVisibility(); + } +} + + +//============================================================================ +void CDockAreaWidget::setDockAreaFlag(eDockAreaFlag Flag, bool On) +{ + auto flags = dockAreaFlags(); + internal::setFlag(flags, Flag, On); + setDockAreaFlags(flags); +} + + +//============================================================================ +QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const +{ + return d->TitleBar->button(which); +} + + +//============================================================================ +void CDockAreaWidget::closeArea() +{ + // If there is only one single dock widget and this widget has the + // DeleteOnClose feature, then we delete the dock widget now + auto OpenDockWidgets = openedDockWidgets(); + if (OpenDockWidgets.count() == 1 && OpenDockWidgets[0]->features().testFlag(CDockWidget::DockWidgetDeleteOnClose)) + { + OpenDockWidgets[0]->closeDockWidgetInternal(); + } + else + { + for (auto DockWidget : openedDockWidgets()) + { + if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose) && DockWidget->features().testFlag(CDockWidget::DockWidgetForceCloseWithArea)) + DockWidget->closeDockWidgetInternal(); + else + DockWidget->toggleView(false); + } + } +} + + +//============================================================================ +void CDockAreaWidget::closeOtherAreas() +{ + dockContainer()->closeOtherAreas(this); +} + + +//============================================================================ +CDockAreaTitleBar* CDockAreaWidget::titleBar() const +{ + return d->TitleBar; +} + + +//============================================================================ +bool CDockAreaWidget::isCentralWidgetArea() const +{ + if (dockWidgetsCount()!= 1) + { + return false; + } + + return dockManager()->centralWidget() == dockWidgets()[0]; +} + + +//============================================================================ +QSize CDockAreaWidget::minimumSizeHint() const +{ + if (!d->MinSizeHint.isValid()) + { + return Super::minimumSizeHint(); + } + + if (d->TitleBar->isVisible()) + { + return d->MinSizeHint + QSize(0, d->TitleBar->minimumSizeHint().height()); + } + else + { + return d->MinSizeHint; + } +} + + +//============================================================================ +void CDockAreaWidget::onDockWidgetFeaturesChanged() +{ + if (d->TitleBar) + { + d->updateTitleBarButtonStates(); + } +} + + +#ifdef Q_OS_WIN +//============================================================================ +bool CDockAreaWidget::event(QEvent *e) +{ + switch (e->type()) + { + case QEvent::PlatformSurface: return true; + default: + break; + } + + return Super::event(e); +} +#endif + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockAreaWidget.cpp diff --git a/ads/DockAreaWidget.h b/ads/DockAreaWidget.h new file mode 100644 index 0000000..24146bc --- /dev/null +++ b/ads/DockAreaWidget.h @@ -0,0 +1,374 @@ +#ifndef DockAreaWidgetH +#define DockAreaWidgetH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockAreaWidget.h +/// \author Uwe Kindler +/// \date 24.02.2017 +/// \brief Declaration of CDockAreaWidget class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include "ads_globals.h" +#include "DockWidget.h" + +QT_FORWARD_DECLARE_CLASS(QXmlStreamWriter) +QT_FORWARD_DECLARE_CLASS(QAbstractButton) + +namespace ads +{ +struct DockAreaWidgetPrivate; +class CDockManager; +class CDockContainerWidget; +class DockContainerWidgetPrivate; +class CDockAreaTitleBar; + + +/** + * DockAreaWidget manages multiple instances of DockWidgets. + * It displays a title tab, which is clickable and will switch to + * the contents associated to the title when clicked. + */ +class ADS_EXPORT CDockAreaWidget : public QFrame +{ + Q_OBJECT +private: + DockAreaWidgetPrivate* d; ///< private data (pimpl) + friend struct DockAreaWidgetPrivate; + friend class CDockContainerWidget; + friend class DockContainerWidgetPrivate; + friend class CDockWidgetTab; + friend struct DockWidgetPrivate; + friend class CDockWidget; + friend struct DockManagerPrivate; + friend class CDockManager; + void onDockWidgetFeaturesChanged(); + +private Q_SLOTS: + void onTabCloseRequested(int Index); + + /** + * Reorder the index position of DockWidget at fromIndx to toIndex + * if a tab in the tabbar is dragged from one index to another one + */ + void reorderDockWidget(int fromIndex, int toIndex); + +protected: + +#ifdef Q_OS_WIN + /** + * Reimplements QWidget::event to handle QEvent::PlatformSurface + * This is here to fix issue #294 Tab refresh problem with a QGLWidget + * that exists since Qt version 5.12.7. So this function is here to + * work around a Qt issue. + */ + virtual bool event(QEvent *event) override; +#endif + + /** + * Inserts a dock widget into dock area. + * All dockwidgets in the dock area tabified in a stacked layout with tabs. + * The index indicates the index of the new dockwidget in the tabbar and + * in the stacked layout. If the Activate parameter is true, the new + * DockWidget will be the active one in the stacked layout + */ + void insertDockWidget(int index, CDockWidget* DockWidget, bool Activate = true); + + /** + * Add a new dock widget to dock area. + * All dockwidgets in the dock area tabified in a stacked layout with tabs + */ + void addDockWidget(CDockWidget* DockWidget); + + /** + * Removes the given dock widget from the dock area + */ + void removeDockWidget(CDockWidget* DockWidget); + + /** + * Called from dock widget if it is opened or closed + */ + void toggleDockWidgetView(CDockWidget* DockWidget, bool Open); + + /** + * This is a helper function to get the next open dock widget to activate + * if the given DockWidget will be closed or removed. + * The function returns the next widget that should be activated or + * nullptr in case there are no more open widgets in this area. + */ + CDockWidget* nextOpenDockWidget(CDockWidget* DockWidget) const; + + /** + * Returns the index of the given DockWidget in the internal layout + */ + int index(CDockWidget* DockWidget); + + /** + * Call this function, if you already know, that the dock does not + * contain any visible content (any open dock widgets). + */ + void hideAreaWithNoVisibleContent(); + + /** + * Updates the dock area layout and components visibility + */ + void updateTitleBarVisibility(); + + /** + * This is the internal private function for setting the current widget. + * This function is called by the public setCurrentDockWidget() function + * and by the dock manager when restoring the state + */ + void internalSetCurrentDockWidget(CDockWidget* DockWidget); + + /** + * Marks tabs menu to update + */ + void markTitleBarMenuOutdated(); + +protected Q_SLOTS: + void toggleView(bool Open); + +public: + using Super = QFrame; + + /** + * Dock area related flags + */ + enum eDockAreaFlag + { + HideSingleWidgetTitleBar = 0x0001, + DefaultFlags = 0x0000 + }; + Q_DECLARE_FLAGS(DockAreaFlags, eDockAreaFlag) + + /** + * Default Constructor + */ + CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent); + + /** + * Virtual Destructor + */ + virtual ~CDockAreaWidget(); + + /** + * Returns the dock manager object this dock area belongs to + */ + CDockManager* dockManager() const; + + /** + * Returns the dock container widget this dock area widget belongs to or 0 + * if there is no + */ + CDockContainerWidget* dockContainer() const; + + /** + * Returns the largest minimumSizeHint() of the dock widgets in this + * area. + * The minimum size hint is updated if a dock widget is removed or added. + */ + virtual QSize minimumSizeHint() const override; + + /** + * Returns the rectangle of the title area + */ + QRect titleBarGeometry() const; + + /** + * Returns the rectangle of the content + */ + QRect contentAreaGeometry() const; + + /** + * Returns the number of dock widgets in this area + */ + int dockWidgetsCount() const; + + /** + * Returns a list of all dock widgets in this dock area. + * This list contains open and closed dock widgets. + */ + QList dockWidgets() const; + + /** + * Returns the number of open dock widgets in this area + */ + int openDockWidgetsCount() const; + + /** + * Returns a list of dock widgets that are not closed. + */ + QList openedDockWidgets() const; + + /** + * Returns a dock widget by its index + */ + CDockWidget* dockWidget(int Index) const; + + /** + * Returns the index of the current active dock widget or -1 if there + * are is no active dock widget (ie.e if all dock widgets are closed) + */ + int currentIndex() const; + + /** + * Returns the index of the first open dock widgets in the list of + * dock widgets. + * This function is here for performance reasons. Normally it would + * be possible to take the first dock widget from the list returned by + * openedDockWidgets() function. But that function enumerates all + * dock widgets while this functions stops after the first open dock widget. + * If there are no open dock widgets, the function returns -1. + */ + int indexOfFirstOpenDockWidget() const; + + /** + * Returns the current active dock widget or a nullptr if there is no + * active dock widget (i.e. if all dock widgets are closed) + */ + CDockWidget* currentDockWidget() const; + + /** + * Shows the tab with the given dock widget + */ + void setCurrentDockWidget(CDockWidget* DockWidget); + + /** + * Saves the state into the given stream + */ + void saveState(QXmlStreamWriter& Stream) const; + + /** + * This functions returns the dock widget features of all dock widget in + * this area. + * A bitwise and is used to combine the flags of all dock widgets. That + * means, if only one single dock widget does not support a certain flag, + * the whole dock are does not support the flag. I.e. if one single + * dock widget in this area is not closable, the whole dock are is not + * closable. + */ + CDockWidget::DockWidgetFeatures features(eBitwiseOperator Mode = BitwiseAnd) const; + + /** + * Returns the title bar button corresponding to the given title bar + * button identifier + */ + QAbstractButton* titleBarButton(TitleBarButton which) const; + + /** + * Update the close button if visibility changed + */ + virtual void setVisible(bool Visible) override; + + /** + * Configures the areas of this particular dock area that are allowed for docking + */ + void setAllowedAreas(DockWidgetAreas areas); + + /** + * Returns flags with all allowed drop areas of this particular dock area + */ + DockWidgetAreas allowedAreas() const; + + /** + * Returns the title bar of this dock area + */ + CDockAreaTitleBar* titleBar() const; + + /** + * Returns the dock area flags - a combination of flags that configure the + * appearance and features of the dock area. + * \see setDockAreaFlasg() + */ + DockAreaFlags dockAreaFlags() const; + + /** + * Sets the dock area flags - a combination of flags that configure the + * appearance and features of the dock area + */ + void setDockAreaFlags(DockAreaFlags Flags); + + /** + * Sets the dock area flag Flag on this widget if on is true; otherwise + * clears the flag. + */ + void setDockAreaFlag(eDockAreaFlag Flag, bool On); + + /** + * Returns true if the area contains the central widget of it's manager. + */ + bool isCentralWidgetArea() const; + +public Q_SLOTS: + /** + * This activates the tab for the given tab index. + * If the dock widget for the given tab is not visible, the this function + * call will make it visible. + */ + void setCurrentIndex(int index); + + /** + * Closes the dock area and all dock widgets in this area + */ + void closeArea(); + + /** + * This function closes all other areas except of this area + */ + void closeOtherAreas(); + +Q_SIGNALS: + /** + * This signal is emitted when user clicks on a tab at an index. + */ + void tabBarClicked(int index); + + /** + * This signal is emitted when the tab bar's current tab is about to be changed. The new + * current has the given index, or -1 if there isn't a new one. + * @param index + */ + void currentChanging(int index); + + /** + * This signal is emitted when the tab bar's current tab changes. The new + * current has the given index, or -1 if there isn't a new one + * @param index + */ + void currentChanged(int index); + + /** + * This signal is emitted if the visibility of this dock area is toggled + * via toggle view function + */ + void viewToggled(bool Open); +}; // class DockAreaWidget +} // namespace ads + +Q_DECLARE_OPERATORS_FOR_FLAGS(ads::CDockAreaWidget::DockAreaFlags) +//----------------------------------------------------------------------------- +#endif // DockAreaWidgetH diff --git a/ads/DockComponentsFactory.cpp b/ads/DockComponentsFactory.cpp new file mode 100644 index 0000000..1f8be65 --- /dev/null +++ b/ads/DockComponentsFactory.cpp @@ -0,0 +1,69 @@ +//============================================================================ +/// \file DockComponentsFactory.cpp +/// \author Uwe Kindler +/// \date 10.02.2020 +/// \brief Implementation of DockComponentsFactory +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockComponentsFactory.h" + +#include + +#include "DockWidgetTab.h" +#include "DockAreaTabBar.h" +#include "DockAreaTitleBar.h" +#include "DockWidget.h" +#include "DockAreaWidget.h" + +namespace ads +{ +static std::unique_ptr DefaultFactory(new CDockComponentsFactory()); + + +//============================================================================ +CDockWidgetTab* CDockComponentsFactory::createDockWidgetTab(CDockWidget* DockWidget) const +{ + return new CDockWidgetTab(DockWidget); +} + + +//============================================================================ +CDockAreaTabBar* CDockComponentsFactory::createDockAreaTabBar(CDockAreaWidget* DockArea) const +{ + return new CDockAreaTabBar(DockArea); +} + + +//============================================================================ +CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidget* DockArea) const +{ + return new CDockAreaTitleBar(DockArea); +} + + +//============================================================================ +const CDockComponentsFactory* CDockComponentsFactory::factory() +{ + return DefaultFactory.get(); +} + + +//============================================================================ +void CDockComponentsFactory::setFactory(CDockComponentsFactory* Factory) +{ + DefaultFactory.reset(Factory); +} + + +//============================================================================ +void CDockComponentsFactory::resetDefaultFactory() +{ + DefaultFactory.reset(new CDockComponentsFactory()); +} +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockComponentsFactory.cpp diff --git a/ads/DockComponentsFactory.h b/ads/DockComponentsFactory.h new file mode 100644 index 0000000..f0598e9 --- /dev/null +++ b/ads/DockComponentsFactory.h @@ -0,0 +1,90 @@ +#ifndef DockComponentsFactoryH +#define DockComponentsFactoryH +//============================================================================ +/// \file DockComponentsFactory.h +/// \author Uwe Kindler +/// \date 10.02.2020 +/// \brief Declaration of DockComponentsFactory +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "ads_globals.h" + +namespace ads +{ +class CDockWidgetTab; +class CDockAreaTitleBar; +class CDockAreaTabBar; +class CDockAreaWidget; +class CDockWidget; + + + +/** + * Factory for creation of certain GUI elements for the docking framework. + * A default unique instance provided by CDockComponentsFactory is used for + * creation of all supported components. To inject your custom components, + * you can create your own derived dock components factory and register + * it via setDefaultFactory() function. + * \code + * CDockComponentsFactory::setDefaultFactory(new MyComponentsFactory())); + * \endcode + */ +class ADS_EXPORT CDockComponentsFactory +{ +public: + /** + * Force virtual destructor + */ + virtual ~CDockComponentsFactory() {} + + /** + * This default implementation just creates a dock widget tab with + * new CDockWidgetTab(DockWIdget). + */ + virtual CDockWidgetTab* createDockWidgetTab(CDockWidget* DockWidget) const; + + /** + * This default implementation just creates a dock area tab bar with + * new CDockAreaTabBar(DockArea). + */ + virtual CDockAreaTabBar* createDockAreaTabBar(CDockAreaWidget* DockArea) const; + + /** + * This default implementation just creates a dock area title bar with + * new CDockAreaTitleBar(DockArea). + */ + virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const; + + /** + * Returns the default components factory + */ + static const CDockComponentsFactory* factory(); + + /** + * Sets a new default factory for creation of GUI elements. + * This function takes ownership of the given Factory. + */ + static void setFactory(CDockComponentsFactory* Factory); + + /** + * Resets the current factory to the + */ + static void resetDefaultFactory(); +}; + + +/** + * Convenience function to ease factory instance access + */ +inline const CDockComponentsFactory* componentsFactory() +{ + return CDockComponentsFactory::factory(); +} + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // DockComponentsFactoryH diff --git a/ads/DockContainerWidget.cpp b/ads/DockContainerWidget.cpp new file mode 100644 index 0000000..61e3b8b --- /dev/null +++ b/ads/DockContainerWidget.cpp @@ -0,0 +1,1901 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockContainerWidget.cpp +/// \author Uwe Kindler +/// \date 24.02.2017 +/// \brief Implementation of CDockContainerWidget class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockContainerWidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DockManager.h" +#include "DockAreaWidget.h" +#include "DockWidget.h" +#include "DockingStateReader.h" +#include "FloatingDockContainer.h" +#include "DockOverlay.h" +#include "ads_globals.h" +#include "DockSplitter.h" + +#include +#include + +#if QT_VERSION < 0x050900 + +inline char toHexLower(uint value) +{ + return "0123456789abcdef"[value & 0xF]; +} + +QByteArray qByteArrayToHex(const QByteArray& src, char separator) +{ + if(src.size() == 0) + return QByteArray(); + + const int length = separator ? (src.size() * 3 - 1) : (src.size() * 2); + QByteArray hex(length, Qt::Uninitialized); + char *hexData = hex.data(); + const uchar *data = reinterpret_cast(src.data()); + for (int i = 0, o = 0; i < src.size(); ++i) { + hexData[o++] = toHexLower(data[i] >> 4); + hexData[o++] = toHexLower(data[i] & 0xf); + + if ((separator) && (o < length)) + hexData[o++] = separator; + } + return hex; +} +#endif + +namespace ads +{ +static unsigned int zOrderCounter = 0; + +enum eDropMode +{ + DropModeIntoArea,///< drop widget into a dock area + DropModeIntoContainer,///< drop into container + DropModeInvalid///< invalid mode - do not drop +}; + +/** + * Converts dock area ID to an index for array access + */ +static int areaIdToIndex(DockWidgetArea area) +{ + switch (area) + { + case LeftDockWidgetArea: return 0; + case RightDockWidgetArea: return 1; + case TopDockWidgetArea: return 2; + case BottomDockWidgetArea: return 3; + case CenterDockWidgetArea: return 4; + default: + return 4; + } +} + +/** + * Helper function to ease insertion of dock area into splitter + */ +static void insertWidgetIntoSplitter(QSplitter* Splitter, QWidget* widget, bool Append) +{ + if (Append) + { + Splitter->addWidget(widget); + } + else + { + Splitter->insertWidget(0, widget); + } +} + +/** + * Private data class of CDockContainerWidget class (pimpl) + */ +class DockContainerWidgetPrivate +{ +public: + CDockContainerWidget* _this; + QPointer DockManager; + unsigned int zOrderIndex = 0; + QList DockAreas; + QGridLayout* Layout = nullptr; + QSplitter* RootSplitter = nullptr; + bool isFloating = false; + CDockAreaWidget* LastAddedAreaCache[5]; + int VisibleDockAreaCount = -1; + CDockAreaWidget* TopLevelDockArea = nullptr; + + /** + * Private data constructor + */ + DockContainerWidgetPrivate(CDockContainerWidget* _public); + + /** + * Adds dock widget to container and returns the dock area that contains + * the inserted dock widget + */ + CDockAreaWidget* addDockWidgetToContainer(DockWidgetArea area, CDockWidget* Dockwidget); + + /** + * Adds dock widget to a existing DockWidgetArea + */ + CDockAreaWidget* addDockWidgetToDockArea(DockWidgetArea area, CDockWidget* Dockwidget, + CDockAreaWidget* TargetDockArea); + + /** + * Add dock area to this container + */ + void addDockArea(CDockAreaWidget* NewDockWidget, DockWidgetArea area = CenterDockWidgetArea); + + /** + * Drop floating widget into container + */ + void dropIntoContainer(CFloatingDockContainer* FloatingWidget, DockWidgetArea area); + + /** + * Drop floating widget into dock area + */ + void dropIntoSection(CFloatingDockContainer* FloatingWidget, + CDockAreaWidget* TargetArea, DockWidgetArea area); + + /** + * Moves the dock widget or dock area given in Widget parameter to a + * new dock widget area + */ + void moveToNewSection(QWidget* Widget, CDockAreaWidget* TargetArea, DockWidgetArea area); + + /** + * Moves the dock widget or dock area given in Widget parameter to a + * a dock area in container + */ + void moveToContainer(QWidget* Widgett, DockWidgetArea area); + + /** + * Creates a new tab for a widget dropped into the center of a section + */ + void dropIntoCenterOfSection(CFloatingDockContainer* FloatingWidget, + CDockAreaWidget* TargetArea); + + /** + * Creates a new tab for a widget dropped into the center of a section + */ + void moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea); + + + /** + * Adds new dock areas to the internal dock area list + */ + void addDockAreasToList(const QList NewDockAreas); + + /** + * Wrapper function for DockAreas append, that ensures that dock area signals + * are properly connected to dock container slots + */ + void appendDockAreas(const QList NewDockAreas); + + /** + * Save state of child nodes + */ + void saveChildNodesState(QXmlStreamWriter& Stream, QWidget* Widget); + + /** + * Restore state of child nodes. + * \param[in] Stream The data stream that contains the serialized state + * \param[out] CreatedWidget The widget created from parsed data or 0 if + * the parsed widget was an empty splitter + * \param[in] Testing If Testing is true, only the stream data is + * parsed without modifiying anything. + */ + bool restoreChildNodes(CDockingStateReader& Stream, QWidget*& CreatedWidget, + bool Testing); + + /** + * Restores a splitter. + * \see restoreChildNodes() for details + */ + bool restoreSplitter(CDockingStateReader& Stream, QWidget*& CreatedWidget, + bool Testing); + + /** + * Restores a dock area. + * \see restoreChildNodes() for details + */ + bool restoreDockArea(CDockingStateReader& Stream, QWidget*& CreatedWidget, + bool Testing); + + /** + * Helper function for recursive dumping of layout + */ + void dumpRecursive(int level, QWidget* widget); + + /** + * Calculate the drop mode from the given target position + */ + eDropMode getDropMode(const QPoint& TargetPos); + + /** + * Initializes the visible dock area count variable if it is not initialized + * yet + */ + void initVisibleDockAreaCount() + { + if (VisibleDockAreaCount > -1) + { + return; + } + + VisibleDockAreaCount = 0; + for (auto DockArea : DockAreas) + { + VisibleDockAreaCount += DockArea->isHidden() ? 0 : 1; + } + } + + /** + * Access function for the visible dock area counter + */ + int& visibleDockAreaCount() + { + // Lazy initialisation - we initialize the VisibleDockAreaCount variable + // on first use + initVisibleDockAreaCount(); + return VisibleDockAreaCount; + } + + /** + * The visible dock area count changes, if dock areas are remove, added or + * when its view is toggled + */ + void onVisibleDockAreaCountChanged(); + + void emitDockAreasRemoved() + { + onVisibleDockAreaCountChanged(); + Q_EMIT _this->dockAreasRemoved(); + } + + void emitDockAreasAdded() + { + onVisibleDockAreaCountChanged(); + Q_EMIT _this->dockAreasAdded(); + } + + /** + * Helper function for creation of new splitter + */ + CDockSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent = nullptr) + { + CDockSplitter* s = new CDockSplitter(orientation, parent); + s->setOpaqueResize(CDockManager::testConfigFlag(CDockManager::OpaqueSplitterResize)); + s->setChildrenCollapsible(false); + return s; + } + + /** + * Ensures equal distribution of the sizes of a splitter if an dock widget + * is inserted from code + */ + void adjustSplitterSizesOnInsertion(QSplitter* Splitter, qreal LastRatio = 1.0) + { + int AreaSize = (Splitter->orientation() == Qt::Horizontal) ? Splitter->width() : Splitter->height(); + auto SplitterSizes = Splitter->sizes(); + + qreal TotRatio = SplitterSizes.size() - 1.0 + LastRatio; + for(int i = 0; i < SplitterSizes.size() -1; i++) + { + SplitterSizes[i] = AreaSize / TotRatio; + } + SplitterSizes.back() = AreaSize * LastRatio / TotRatio; + Splitter->setSizes(SplitterSizes); + } + + /** + * This function forces the dock container widget to update handles of splitters + * based if a central widget exists. + */ + void updateSplitterHandles(QSplitter* splitter); + + /** + * If no central widget exists, the widgets resize with the container. + * If a central widget exists, the widgets surrounding the central widget + * do not resize its height or width. + */ + bool widgetResizesWithContainer(QWidget* widget); + +// private slots: ------------------------------------------------------------ + void onDockAreaViewToggled(bool Visible) + { + CDockAreaWidget* DockArea = qobject_cast(_this->sender()); + VisibleDockAreaCount += Visible ? 1 : -1; + onVisibleDockAreaCountChanged(); + Q_EMIT _this->dockAreaViewToggled(DockArea, Visible); + } +}; // struct DockContainerWidgetPrivate + + +//============================================================================ +DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _public) : + _this(_public) +{ + std::fill(std::begin(LastAddedAreaCache),std::end(LastAddedAreaCache), nullptr); +} + + +//============================================================================ +eDropMode DockContainerWidgetPrivate::getDropMode(const QPoint& TargetPos) +{ + CDockAreaWidget* DockArea = _this->dockAreaAt(TargetPos); + auto dropArea = InvalidDockWidgetArea; + auto ContainerDropArea = DockManager->containerOverlay()->dropAreaUnderCursor(); + + if (DockArea) + { + auto dropOverlay = DockManager->dockAreaOverlay(); + dropOverlay->setAllowedAreas(DockArea->allowedAreas()); + dropArea = dropOverlay->showOverlay(DockArea); + if (ContainerDropArea != InvalidDockWidgetArea && + ContainerDropArea != dropArea) + { + dropArea = InvalidDockWidgetArea; + } + + if (dropArea != InvalidDockWidgetArea) + { + ADS_PRINT("Dock Area Drop Content: " << dropArea); + return DropModeIntoArea; + } + } + + // mouse is over container + if (InvalidDockWidgetArea == dropArea) + { + dropArea = ContainerDropArea; + ADS_PRINT("Container Drop Content: " << dropArea); + if (dropArea != InvalidDockWidgetArea) + { + return DropModeIntoContainer; + } + } + + return DropModeInvalid; +} + + +//============================================================================ +void DockContainerWidgetPrivate::onVisibleDockAreaCountChanged() +{ + auto TopLevelDockArea = _this->topLevelDockArea(); + + if (TopLevelDockArea) + { + this->TopLevelDockArea = TopLevelDockArea; + TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(false || !_this->isFloating()); + TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(false || !_this->isFloating()); + } + else if (this->TopLevelDockArea) + { + this->TopLevelDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true); + this->TopLevelDockArea->titleBarButton(TitleBarButtonClose)->setVisible(true); + this->TopLevelDockArea = nullptr; + } +} + + +//============================================================================ +void DockContainerWidgetPrivate::dropIntoContainer(CFloatingDockContainer* FloatingWidget, + DockWidgetArea area) +{ + auto InsertParam = internal::dockAreaInsertParameters(area); + CDockContainerWidget* FloatingDockContainer = FloatingWidget->dockContainer(); + auto NewDockAreas = FloatingDockContainer->findChildren( + QString(), Qt::FindChildrenRecursively); + QSplitter* Splitter = RootSplitter; + + if (DockAreas.count() <= 1) + { + Splitter->setOrientation(InsertParam.orientation()); + } + else if (Splitter->orientation() != InsertParam.orientation()) + { + QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter); + NewSplitter->addWidget(Splitter); + updateSplitterHandles(NewSplitter); + Splitter = NewSplitter; + delete li; + } + + // Now we can insert the floating widget content into this container + auto FloatingSplitter = FloatingDockContainer->rootSplitter(); + if (FloatingSplitter->count() == 1) + { + insertWidgetIntoSplitter(Splitter, FloatingSplitter->widget(0), InsertParam.append()); + updateSplitterHandles(Splitter); + } + else if (FloatingSplitter->orientation() == InsertParam.orientation()) + { + int InsertIndex = InsertParam.append() ? Splitter->count() : 0; + while (FloatingSplitter->count()) + { + Splitter->insertWidget(InsertIndex++, FloatingSplitter->widget(0)); + updateSplitterHandles(Splitter); + } + } + else + { + insertWidgetIntoSplitter(Splitter, FloatingSplitter, InsertParam.append()); + } + + RootSplitter = Splitter; + addDockAreasToList(NewDockAreas); + + // If we dropped the floating widget into the main dock container that does + // not contain any dock widgets, then splitter is invisible and we need to + // show it to display the docked widgets + if (!Splitter->isVisible()) + { + Splitter->show(); + } + _this->dumpLayout(); +} + + +//============================================================================ +void DockContainerWidgetPrivate::dropIntoCenterOfSection( + CFloatingDockContainer* FloatingWidget, CDockAreaWidget* TargetArea) +{ + CDockContainerWidget* FloatingContainer = FloatingWidget->dockContainer(); + auto NewDockWidgets = FloatingContainer->dockWidgets(); + auto TopLevelDockArea = FloatingContainer->topLevelDockArea(); + int NewCurrentIndex = -1; + + // If the floating widget contains only one single dock are, then the + // current dock widget of the dock area will also be the future current + // dock widget in the drop area. + if (TopLevelDockArea) + { + NewCurrentIndex = TopLevelDockArea->currentIndex(); + } + + for (int i = 0; i < NewDockWidgets.count(); ++i) + { + CDockWidget* DockWidget = NewDockWidgets[i]; + TargetArea->insertDockWidget(i, DockWidget, false); + // If the floating widget contains multiple visible dock areas, then we + // simply pick the first visible open dock widget and make it + // the current one. + if (NewCurrentIndex < 0 && !DockWidget->isClosed()) + { + NewCurrentIndex = i; + } + } + TargetArea->setCurrentIndex(NewCurrentIndex); + TargetArea->updateTitleBarVisibility(); + return; +} + + +//============================================================================ +void DockContainerWidgetPrivate::dropIntoSection(CFloatingDockContainer* FloatingWidget, + CDockAreaWidget* TargetArea, DockWidgetArea area) +{ + // Dropping into center means all dock widgets in the dropped floating + // widget will become tabs of the drop area + if (CenterDockWidgetArea == area) + { + dropIntoCenterOfSection(FloatingWidget, TargetArea); + return; + } + + auto InsertParam = internal::dockAreaInsertParameters(area); + auto NewDockAreas = FloatingWidget->dockContainer()->findChildren( + QString(), Qt::FindChildrenRecursively); + QSplitter* TargetAreaSplitter = internal::findParent(TargetArea); + + if (!TargetAreaSplitter) + { + QSplitter* Splitter = newSplitter(InsertParam.orientation()); + Layout->replaceWidget(TargetArea, Splitter); + Splitter->addWidget(TargetArea); + updateSplitterHandles(Splitter); + TargetAreaSplitter = Splitter; + } + int AreaIndex = TargetAreaSplitter->indexOf(TargetArea); + auto Widget = FloatingWidget->dockContainer()->findChild(QString(), Qt::FindDirectChildrenOnly); + auto FloatingSplitter = qobject_cast(Widget); + + if (TargetAreaSplitter->orientation() == InsertParam.orientation()) + { + auto Sizes = TargetAreaSplitter->sizes(); + int TargetAreaSize = (InsertParam.orientation() == Qt::Horizontal) ? TargetArea->width() : TargetArea->height(); + bool AdjustSplitterSizes = true; + if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1) + { + TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), Widget); + updateSplitterHandles(TargetAreaSplitter); + } + else + { + AdjustSplitterSizes = (FloatingSplitter->count() == 1); + int InsertIndex = AreaIndex + InsertParam.insertOffset(); + while (FloatingSplitter->count()) + { + TargetAreaSplitter->insertWidget(InsertIndex++, FloatingSplitter->widget(0)); + updateSplitterHandles(TargetAreaSplitter); + } + } + + if (AdjustSplitterSizes) + { + int Size = (TargetAreaSize - TargetAreaSplitter->handleWidth()) / 2; + Sizes[AreaIndex] = Size; + Sizes.insert(AreaIndex, Size); + TargetAreaSplitter->setSizes(Sizes); + } + } + else + { + QList NewSplitterSizes; + QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + int TargetAreaSize = (InsertParam.orientation() == Qt::Horizontal) ? TargetArea->width() : TargetArea->height(); + bool AdjustSplitterSizes = true; + if ((FloatingSplitter->orientation() != InsertParam.orientation()) && FloatingSplitter->count() > 1) + { + NewSplitter->addWidget(Widget); + updateSplitterHandles(NewSplitter); + } + else + { + AdjustSplitterSizes = (FloatingSplitter->count() == 1); + while (FloatingSplitter->count()) + { + NewSplitter->addWidget(FloatingSplitter->widget(0)); + updateSplitterHandles(NewSplitter); + } + } + + // Save the sizes before insertion and restore it later to prevent + // shrinking of existing area + auto Sizes = TargetAreaSplitter->sizes(); + insertWidgetIntoSplitter(NewSplitter, TargetArea, !InsertParam.append()); + updateSplitterHandles(NewSplitter); + if (AdjustSplitterSizes) + { + int Size = TargetAreaSize / 2; + NewSplitter->setSizes({Size, Size}); + } + TargetAreaSplitter->insertWidget(AreaIndex, NewSplitter); + TargetAreaSplitter->setSizes(Sizes); + updateSplitterHandles(TargetAreaSplitter); + } + + addDockAreasToList(NewDockAreas); + _this->dumpLayout(); +} + + +//============================================================================ +void DockContainerWidgetPrivate::moveIntoCenterOfSection(QWidget* Widget, CDockAreaWidget* TargetArea) +{ + auto DroppedDockWidget = qobject_cast(Widget); + auto DroppedArea = qobject_cast(Widget); + + if (DroppedDockWidget) + { + CDockAreaWidget* OldDockArea = DroppedDockWidget->dockAreaWidget(); + if (OldDockArea == TargetArea) + { + return; + } + + if (OldDockArea) + { + OldDockArea->removeDockWidget(DroppedDockWidget); + } + TargetArea->insertDockWidget(0, DroppedDockWidget, true); + } + else + { + QList NewDockWidgets = DroppedArea->dockWidgets(); + int NewCurrentIndex = DroppedArea->currentIndex(); + for (int i = 0; i < NewDockWidgets.count(); ++i) + { + CDockWidget* DockWidget = NewDockWidgets[i]; + TargetArea->insertDockWidget(i, DockWidget, false); + } + TargetArea->setCurrentIndex(NewCurrentIndex); + DroppedArea->dockContainer()->removeDockArea(DroppedArea); + DroppedArea->deleteLater(); + } + + TargetArea->updateTitleBarVisibility(); + return; +} + + +//============================================================================ +void DockContainerWidgetPrivate::moveToNewSection(QWidget* Widget, CDockAreaWidget* TargetArea, DockWidgetArea area) +{ + // Dropping into center means all dock widgets in the dropped floating + // widget will become tabs of the drop area + if (CenterDockWidgetArea == area) + { + moveIntoCenterOfSection(Widget, TargetArea); + return; + } + + + CDockWidget* DroppedDockWidget = qobject_cast(Widget); + CDockAreaWidget* DroppedDockArea = qobject_cast(Widget); + CDockAreaWidget* NewDockArea; + if (DroppedDockWidget) + { + NewDockArea = new CDockAreaWidget(DockManager, _this); + CDockAreaWidget* OldDockArea = DroppedDockWidget->dockAreaWidget(); + if (OldDockArea) + { + OldDockArea->removeDockWidget(DroppedDockWidget); + } + NewDockArea->addDockWidget(DroppedDockWidget); + } + else + { + DroppedDockArea->dockContainer()->removeDockArea(DroppedDockArea); + NewDockArea = DroppedDockArea; + } + + auto InsertParam = internal::dockAreaInsertParameters(area); + QSplitter* TargetAreaSplitter = internal::findParent(TargetArea); + int AreaIndex = TargetAreaSplitter->indexOf(TargetArea); + auto Sizes = TargetAreaSplitter->sizes(); + if (TargetAreaSplitter->orientation() == InsertParam.orientation()) + { + int TargetAreaSize = (InsertParam.orientation() == Qt::Horizontal) ? TargetArea->width() : TargetArea->height(); + TargetAreaSplitter->insertWidget(AreaIndex + InsertParam.insertOffset(), NewDockArea); + updateSplitterHandles(TargetAreaSplitter); + int Size = (TargetAreaSize - TargetAreaSplitter->handleWidth()) / 2; + Sizes[AreaIndex] = Size; + Sizes.insert(AreaIndex, Size); + } + else + { + auto Sizes = TargetAreaSplitter->sizes(); + int TargetAreaSize = (InsertParam.orientation() == Qt::Horizontal) ? TargetArea->width() : TargetArea->height(); + QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + NewSplitter->addWidget(TargetArea); + insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append()); + updateSplitterHandles(NewSplitter); + int Size = TargetAreaSize / 2; + NewSplitter->setSizes({Size, Size}); + TargetAreaSplitter->insertWidget(AreaIndex, NewSplitter); + updateSplitterHandles(TargetAreaSplitter); + } + TargetAreaSplitter->setSizes(Sizes); + + addDockAreasToList({NewDockArea}); +} + + +//============================================================================ +void DockContainerWidgetPrivate::updateSplitterHandles( QSplitter* splitter ) +{ + if (!DockManager->centralWidget() || !splitter) + { + return; + } + + for (int i = 0; i < splitter->count(); ++i) + { + splitter->setStretchFactor(i, widgetResizesWithContainer(splitter->widget(i)) ? 1 : 0); + } +} + + +//============================================================================ +bool DockContainerWidgetPrivate::widgetResizesWithContainer(QWidget* widget) +{ + if (!DockManager->centralWidget()) + { + return true; + } + + auto Area = qobject_cast(widget); + if(Area) + { + return Area->isCentralWidgetArea(); + } + + auto innerSplitter = qobject_cast(widget); + if (innerSplitter) + { + return innerSplitter->isResizingWithContainer(); + } + + return false; +} + + + +//============================================================================ +void DockContainerWidgetPrivate::moveToContainer(QWidget* Widget, DockWidgetArea area) +{ + CDockWidget* DroppedDockWidget = qobject_cast(Widget); + CDockAreaWidget* DroppedDockArea = qobject_cast(Widget); + CDockAreaWidget* NewDockArea; + + if (DroppedDockWidget) + { + NewDockArea = new CDockAreaWidget(DockManager, _this); + CDockAreaWidget* OldDockArea = DroppedDockWidget->dockAreaWidget(); + if (OldDockArea) + { + OldDockArea->removeDockWidget(DroppedDockWidget); + } + NewDockArea->addDockWidget(DroppedDockWidget); + } + else + { + // We check, if we insert the dropped widget into the same place that + // it already has and do nothing, if it is the same place. It would + // also work without this check, but it looks nicer with the check + // because there will be no layout updates + auto Splitter = internal::findParent(DroppedDockArea); + auto InsertParam = internal::dockAreaInsertParameters(area); + if (Splitter == RootSplitter && InsertParam.orientation() == Splitter->orientation()) + { + if (InsertParam.append() && Splitter->lastWidget() == DroppedDockArea) + { + return; + } + else if (!InsertParam.append() && Splitter->firstWidget() == DroppedDockArea) + { + return; + } + } + DroppedDockArea->dockContainer()->removeDockArea(DroppedDockArea); + NewDockArea = DroppedDockArea; + } + + addDockArea(NewDockArea, area); + LastAddedAreaCache[areaIdToIndex(area)] = NewDockArea; +} + + +//============================================================================ +void DockContainerWidgetPrivate::addDockAreasToList(const QList NewDockAreas) +{ + int CountBefore = DockAreas.count(); + int NewAreaCount = NewDockAreas.count(); + appendDockAreas(NewDockAreas); + // If the user dropped a floating widget that contains only one single + // visible dock area, then its title bar button TitleBarButtonUndock is + // likely hidden. We need to ensure, that it is visible + for (auto DockArea : NewDockAreas) + { + DockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true); + DockArea->titleBarButton(TitleBarButtonClose)->setVisible(true); + } + + // We need to ensure, that the dock area title bar is visible. The title bar + // is invisible, if the dock are is a single dock area in a floating widget. + if (1 == CountBefore) + { + DockAreas.at(0)->updateTitleBarVisibility(); + } + + if (1 == NewAreaCount) + { + DockAreas.last()->updateTitleBarVisibility(); + } + + emitDockAreasAdded(); +} + + +//============================================================================ +void DockContainerWidgetPrivate::appendDockAreas(const QList NewDockAreas) +{ + DockAreas.append(NewDockAreas); + for (auto DockArea : NewDockAreas) + { + QObject::connect(DockArea, + &CDockAreaWidget::viewToggled, + _this, + std::bind(&DockContainerWidgetPrivate::onDockAreaViewToggled, this, std::placeholders::_1)); + } +} + + +//============================================================================ +void DockContainerWidgetPrivate::saveChildNodesState(QXmlStreamWriter& s, QWidget* Widget) +{ + QSplitter* Splitter = qobject_cast(Widget); + if (Splitter) + { + s.writeStartElement("Splitter"); + s.writeAttribute("Orientation", (Splitter->orientation() == Qt::Horizontal) ? "|" : "-"); + s.writeAttribute("Count", QString::number(Splitter->count())); + ADS_PRINT("NodeSplitter orient: " << Splitter->orientation() + << " WidgetCont: " << Splitter->count()); + for (int i = 0; i < Splitter->count(); ++i) + { + saveChildNodesState(s, Splitter->widget(i)); + } + + s.writeStartElement("Sizes"); + for (auto Size : Splitter->sizes()) + { + s.writeCharacters(QString::number(Size) + " "); + } + s.writeEndElement(); + s.writeEndElement(); + } + else + { + CDockAreaWidget* DockArea = qobject_cast(Widget); + if (DockArea) + { + DockArea->saveState(s); + } + } +} + + +//============================================================================ +bool DockContainerWidgetPrivate::restoreSplitter(CDockingStateReader& s, + QWidget*& CreatedWidget, bool Testing) +{ + bool Ok; + QString OrientationStr = s.attributes().value("Orientation").toString(); + + // Check if the orientation string is right + if (!OrientationStr.startsWith("|") && !OrientationStr.startsWith("-")) + { + return false; + } + + // The "|" shall indicate a vertical splitter handle which in turn means + // a Horizontal orientation of the splitter layout. + bool HorizontalSplitter = OrientationStr.startsWith("|"); + // In version 0 we had a small bug. The "|" indicated a vertical orientation, + // but this is wrong, because only the splitter handle is vertical, the + // layout of the splitter is a horizontal layout. We fix this here + if (s.fileVersion() == 0) + { + HorizontalSplitter = !HorizontalSplitter; + } + + int Orientation = HorizontalSplitter ? Qt::Horizontal : Qt::Vertical; + int WidgetCount = s.attributes().value("Count").toInt(&Ok); + if (!Ok) + { + return false; + } + ADS_PRINT("Restore NodeSplitter Orientation: " << Orientation << + " WidgetCount: " << WidgetCount); + QSplitter* Splitter = nullptr; + if (!Testing) + { + Splitter = newSplitter(static_cast(Orientation)); + } + bool Visible = false; + QList Sizes; + while (s.readNextStartElement()) + { + QWidget* ChildNode = nullptr; + bool Result = true; + if (s.name() == QLatin1String("Splitter")) + { + Result = restoreSplitter(s, ChildNode, Testing); + } + else if (s.name() == QLatin1String("Area")) + { + Result = restoreDockArea(s, ChildNode, Testing); + } + else if (s.name() == QLatin1String("Sizes")) + { + QString sSizes = s.readElementText().trimmed(); + ADS_PRINT("Sizes: " << sSizes); + QTextStream TextStream(&sSizes); + while (!TextStream.atEnd()) + { + int value; + TextStream >> value; + Sizes.append(value); + } + } + else + { + s.skipCurrentElement(); + } + + if (!Result) + { + return false; + } + + if (Testing || !ChildNode) + { + continue; + } + + ADS_PRINT("ChildNode isVisible " << ChildNode->isVisible() + << " isVisibleTo " << ChildNode->isVisibleTo(Splitter)); + Splitter->addWidget(ChildNode); + Visible |= ChildNode->isVisibleTo(Splitter); + } + if(!Testing) + { + updateSplitterHandles(Splitter); + } + + if (Sizes.count() != WidgetCount) + { + return false; + } + + if (!Testing) + { + if (!Splitter->count()) + { + delete Splitter; + Splitter = nullptr; + } + else + { + Splitter->setSizes(Sizes); + Splitter->setVisible(Visible); + } + CreatedWidget = Splitter; + } + else + { + CreatedWidget = nullptr; + } + + return true; +} + + +//============================================================================ +bool DockContainerWidgetPrivate::restoreDockArea(CDockingStateReader& s, + QWidget*& CreatedWidget, bool Testing) +{ + bool Ok; +#ifdef ADS_DEBUG_PRINT + int Tabs = s.attributes().value("Tabs").toInt(&Ok); + if (!Ok) + { + return false; + } +#endif + + QString CurrentDockWidget = s.attributes().value("Current").toString(); + ADS_PRINT("Restore NodeDockArea Tabs: " << Tabs << " Current: " + << CurrentDockWidget); + + CDockAreaWidget* DockArea = nullptr; + if (!Testing) + { + DockArea = new CDockAreaWidget(DockManager, _this); + const auto AllowedAreasAttribute = s.attributes().value("AllowedAreas"); + if (!AllowedAreasAttribute.isEmpty()) + { + DockArea->setAllowedAreas((DockWidgetArea)AllowedAreasAttribute.toInt(nullptr, 16)); + } + + const auto FlagsAttribute = s.attributes().value("Flags"); + if (!FlagsAttribute.isEmpty()) + { + DockArea->setDockAreaFlags((CDockAreaWidget::DockAreaFlags)FlagsAttribute.toInt(nullptr, 16)); + } + } + + while (s.readNextStartElement()) + { + if (s.name() != QLatin1String("Widget")) + { + continue; + } + + auto ObjectName = s.attributes().value("Name"); + if (ObjectName.isEmpty()) + { + return false; + } + + bool Closed = s.attributes().value("Closed").toInt(&Ok); + if (!Ok) + { + return false; + } + + s.skipCurrentElement(); + CDockWidget* DockWidget = DockManager->findDockWidget(ObjectName.toString()); + if (!DockWidget || Testing) + { + continue; + } + + ADS_PRINT("Dock Widget found - parent " << DockWidget->parent()); + // We hide the DockArea here to prevent the short display (the flashing) + // of the dock areas during application startup + DockArea->hide(); + DockArea->addDockWidget(DockWidget); + DockWidget->setToggleViewActionChecked(!Closed); + DockWidget->setClosedState(Closed); + DockWidget->setProperty(internal::ClosedProperty, Closed); + DockWidget->setProperty(internal::DirtyProperty, false); + } + + if (Testing) + { + return true; + } + + if (!DockArea->dockWidgetsCount()) + { + delete DockArea; + DockArea = nullptr; + } + else + { + DockArea->setProperty("currentDockWidget", CurrentDockWidget); + appendDockAreas({DockArea}); + } + + CreatedWidget = DockArea; + return true; +} + + +//============================================================================ +bool DockContainerWidgetPrivate::restoreChildNodes(CDockingStateReader& s, + QWidget*& CreatedWidget, bool Testing) +{ + bool Result = true; + while (s.readNextStartElement()) + { + if (s.name() == QLatin1String("Splitter")) + { + Result = restoreSplitter(s, CreatedWidget, Testing); + ADS_PRINT("Splitter"); + } + else if (s.name() == QLatin1String("Area")) + { + Result = restoreDockArea(s, CreatedWidget, Testing); + ADS_PRINT("DockAreaWidget"); + } + else + { + s.skipCurrentElement(); + ADS_PRINT("Unknown element"); + } + } + + return Result; +} + + +//============================================================================ +CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToContainer(DockWidgetArea area, + CDockWidget* Dockwidget) +{ + CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this); + NewDockArea->addDockWidget(Dockwidget); + addDockArea(NewDockArea, area); + NewDockArea->updateTitleBarVisibility(); + LastAddedAreaCache[areaIdToIndex(area)] = NewDockArea; + return NewDockArea; +} + + +//============================================================================ +void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockWidgetArea area) +{ + auto InsertParam = internal::dockAreaInsertParameters(area); + // As long as we have only one dock area in the splitter we can adjust + // its orientation + if (DockAreas.count() <= 1) + { + RootSplitter->setOrientation(InsertParam.orientation()); + } + + QSplitter* Splitter = RootSplitter; + if (Splitter->orientation() == InsertParam.orientation()) + { + insertWidgetIntoSplitter(Splitter, NewDockArea, InsertParam.append()); + updateSplitterHandles(Splitter); + if (Splitter->isHidden()) + { + Splitter->show(); + } + } + else + { + QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + if (InsertParam.append()) + { + QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter); + NewSplitter->addWidget(Splitter); + NewSplitter->addWidget(NewDockArea); + updateSplitterHandles(NewSplitter); + delete li; + } + else + { + NewSplitter->addWidget(NewDockArea); + QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter); + NewSplitter->addWidget(Splitter); + updateSplitterHandles(NewSplitter); + delete li; + } + RootSplitter = NewSplitter; + } + + addDockAreasToList({NewDockArea}); +} + + +//============================================================================ +void DockContainerWidgetPrivate::dumpRecursive(int level, QWidget* widget) +{ +#if defined(QT_DEBUG) + QSplitter* Splitter = qobject_cast(widget); + QByteArray buf; + buf.fill(' ', level * 4); + if (Splitter) + { +#ifdef ADS_DEBUG_PRINT + qDebug("%sSplitter %s v: %s c: %s", + (const char*)buf, + (Splitter->orientation() == Qt::Vertical) ? "--" : "|", + Splitter->isHidden() ? " " : "v", + QString::number(Splitter->count()).toStdString().c_str()); + std::cout << (const char*)buf << "Splitter " + << ((Splitter->orientation() == Qt::Vertical) ? "--" : "|") << " " + << (Splitter->isHidden() ? " " : "v") << " " + << QString::number(Splitter->count()).toStdString() << std::endl; +#endif + for (int i = 0; i < Splitter->count(); ++i) + { + dumpRecursive(level + 1, Splitter->widget(i)); + } + } + else + { + CDockAreaWidget* DockArea = qobject_cast(widget); + if (!DockArea) + { + return; + } +#ifdef ADS_DEBUG_PRINT + qDebug("%sDockArea", (const char*)buf); + std::cout << (const char*)buf + << (DockArea->isHidden() ? " " : "v") + << (DockArea->openDockWidgetsCount() > 0 ? " " : "c") + << " DockArea " << "[hs: " << DockArea->sizePolicy().horizontalStretch() << ", vs: " << DockArea->sizePolicy().verticalStretch() << "]" << std::endl; + buf.fill(' ', (level + 1) * 4); + for (int i = 0; i < DockArea->dockWidgetsCount(); ++i) + { + std::cout << (const char*)buf << (i == DockArea->currentIndex() ? "*" : " "); + CDockWidget* DockWidget = DockArea->dockWidget(i); + std::cout << (DockWidget->isHidden() ? " " : "v"); + std::cout << (DockWidget->isClosed() ? "c" : " ") << " "; + std::cout << DockWidget->windowTitle().toStdString() << std::endl; + } +#endif + } +#else + Q_UNUSED(level); + Q_UNUSED(widget); +#endif +} + + +//============================================================================ +CDockAreaWidget* DockContainerWidgetPrivate::addDockWidgetToDockArea(DockWidgetArea area, + CDockWidget* Dockwidget, CDockAreaWidget* TargetDockArea) +{ + if (CenterDockWidgetArea == area) + { + TargetDockArea->addDockWidget(Dockwidget); + TargetDockArea->updateTitleBarVisibility(); + return TargetDockArea; + } + + CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this); + NewDockArea->addDockWidget(Dockwidget); + auto InsertParam = internal::dockAreaInsertParameters(area); + + QSplitter* TargetAreaSplitter = internal::findParent(TargetDockArea); + int index = TargetAreaSplitter ->indexOf(TargetDockArea); + if (TargetAreaSplitter->orientation() == InsertParam.orientation()) + { + ADS_PRINT("TargetAreaSplitter->orientation() == InsertParam.orientation()"); + TargetAreaSplitter->insertWidget(index + InsertParam.insertOffset(), NewDockArea); + updateSplitterHandles(TargetAreaSplitter); + // do nothing, if flag is not enabled + if (CDockManager::testConfigFlag(CDockManager::EqualSplitOnInsertion)) + { + adjustSplitterSizesOnInsertion(TargetAreaSplitter); + } + } + else + { + ADS_PRINT("TargetAreaSplitter->orientation() != InsertParam.orientation()"); + auto TargetAreaSizes = TargetAreaSplitter->sizes(); + QSplitter* NewSplitter = newSplitter(InsertParam.orientation()); + NewSplitter->addWidget(TargetDockArea); + + insertWidgetIntoSplitter(NewSplitter, NewDockArea, InsertParam.append()); + updateSplitterHandles(NewSplitter); + TargetAreaSplitter->insertWidget(index, NewSplitter); + updateSplitterHandles(TargetAreaSplitter); + if (CDockManager::testConfigFlag(CDockManager::EqualSplitOnInsertion)) + { + TargetAreaSplitter->setSizes(TargetAreaSizes); + adjustSplitterSizesOnInsertion(NewSplitter); + } + } + + addDockAreasToList({NewDockArea}); + return NewDockArea; +} + + +//============================================================================ +CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *parent) : + QFrame(parent), + d(new DockContainerWidgetPrivate(this)) +{ + d->DockManager = DockManager; + d->isFloating = floatingWidget() != nullptr; + + d->Layout = new QGridLayout(); + d->Layout->setContentsMargins(0, 0, 0, 0); + d->Layout->setSpacing(0); + setLayout(d->Layout); + + // The function d->newSplitter() accesses the config flags from dock + // manager which in turn requires a properly constructed dock manager. + // If this dock container is the dock manager, then it is not properly + // constructed yet because this base class constructor is called before + // the constructor of the DockManager private class + if (DockManager != this) + { + d->DockManager->registerDockContainer(this); + createRootSplitter(); + } +} + +//============================================================================ +CDockContainerWidget::~CDockContainerWidget() +{ + if (d->DockManager) + { + d->DockManager->removeDockContainer(this); + } + delete d; +} + + +//============================================================================ +CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, + CDockAreaWidget* DockAreaWidget) +{ + CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget(); + if (OldDockArea) + { + OldDockArea->removeDockWidget(Dockwidget); + } + + Dockwidget->setDockManager(d->DockManager); + if (DockAreaWidget) + { + return d->addDockWidgetToDockArea(area, Dockwidget, DockAreaWidget); + } + else + { + return d->addDockWidgetToContainer(area, Dockwidget); + } +} + +//============================================================================ +void CDockContainerWidget::removeDockWidget(CDockWidget* Dockwidget) +{ + CDockAreaWidget* Area = Dockwidget->dockAreaWidget(); + if (Area) + { + Area->removeDockWidget(Dockwidget); + } +} + +//============================================================================ +unsigned int CDockContainerWidget::zOrderIndex() const +{ + return d->zOrderIndex; +} + + +//============================================================================ +bool CDockContainerWidget::isInFrontOf(CDockContainerWidget* Other) const +{ + return this->zOrderIndex() > Other->zOrderIndex(); +} + + +//============================================================================ +bool CDockContainerWidget::event(QEvent *e) +{ + bool Result = QWidget::event(e); + if (e->type() == QEvent::WindowActivate) + { + d->zOrderIndex = ++zOrderCounter; + } + else if (e->type() == QEvent::Show && !d->zOrderIndex) + { + d->zOrderIndex = ++zOrderCounter; + } + + return Result; +} + + +//============================================================================ +void CDockContainerWidget::addDockArea(CDockAreaWidget* DockAreaWidget, + DockWidgetArea area) +{ + CDockContainerWidget* Container = DockAreaWidget->dockContainer(); + if (Container && Container != this) + { + Container->removeDockArea(DockAreaWidget); + } + + d->addDockArea(DockAreaWidget, area); +} + + +//============================================================================ +void CDockContainerWidget::removeDockArea(CDockAreaWidget* area) +{ + ADS_PRINT("CDockContainerWidget::removeDockArea"); + area->disconnect(this); + d->DockAreas.removeAll(area); + CDockSplitter* Splitter = internal::findParent(area); + + // Remove are from parent splitter and recursively hide tree of parent + // splitters if it has no visible content + area->setParent(nullptr); + internal::hideEmptyParentSplitters(Splitter); + + // Remove this area from cached areas + auto p = std::find(std::begin(d->LastAddedAreaCache), std::end(d->LastAddedAreaCache), area); + if (p != std::end(d->LastAddedAreaCache)) { + *p = nullptr; + } + + // If splitter has more than 1 widgets, we are finished and can leave + if (Splitter->count() > 1) + { + goto emitAndExit; + } + + // If this is the RootSplitter we need to remove empty splitters to + // avoid too many empty splitters + if (Splitter == d->RootSplitter) + { + ADS_PRINT("Removed from RootSplitter"); + // If splitter is empty, we are finished + if (!Splitter->count()) + { + Splitter->hide(); + goto emitAndExit; + } + + QWidget* widget = Splitter->widget(0); + QSplitter* ChildSplitter = qobject_cast(widget); + // If the one and only content widget of the splitter is not a splitter + // then we are finished + if (!ChildSplitter) + { + goto emitAndExit; + } + + // We replace the superfluous RootSplitter with the ChildSplitter + ChildSplitter->setParent(nullptr); + QLayoutItem* li = d->Layout->replaceWidget(Splitter, ChildSplitter); + d->RootSplitter = ChildSplitter; + delete li; + ADS_PRINT("RootSplitter replaced by child splitter"); + } + else if (Splitter->count() == 1) + { + ADS_PRINT("Replacing splitter with content"); + QSplitter* ParentSplitter = internal::findParent(Splitter); + auto Sizes = ParentSplitter->sizes(); + QWidget* widget = Splitter->widget(0); + widget->setParent(this); + internal::replaceSplitterWidget(ParentSplitter, Splitter, widget); + ParentSplitter->setSizes(Sizes); + } + + delete Splitter; + Splitter = nullptr; + +emitAndExit: + updateSplitterHandles(Splitter); + CDockWidget* TopLevelWidget = topLevelDockWidget(); + + // Updated the title bar visibility of the dock widget if there is only + // one single visible dock widget + CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true); + dumpLayout(); + d->emitDockAreasRemoved(); +} + + +//============================================================================ +CDockAreaWidget* CDockContainerWidget::dockAreaAt(const QPoint& GlobalPos) const +{ + for (const auto& DockArea : d->DockAreas) + { + if (DockArea->isVisible() && DockArea->rect().contains(DockArea->mapFromGlobal(GlobalPos))) + { + return DockArea; + } + } + + return nullptr; +} + + +//============================================================================ +CDockAreaWidget* CDockContainerWidget::dockArea(int Index) const +{ + return (Index < dockAreaCount()) ? d->DockAreas[Index] : nullptr; +} + + +//============================================================================ +bool CDockContainerWidget::isFloating() const +{ + return d->isFloating; +} + + +//============================================================================ +int CDockContainerWidget::dockAreaCount() const +{ + return d->DockAreas.count(); +} + + +//============================================================================ +int CDockContainerWidget::visibleDockAreaCount() const +{ + int Result = 0; + for (auto DockArea : d->DockAreas) + { + Result += DockArea->isHidden() ? 0 : 1; + } + + return Result; + + // TODO Cache or precalculate this to speed it up because it is used during + // movement of floating widget + //return d->visibleDockAreaCount(); +} + + +//============================================================================ +void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWidget, + const QPoint& TargetPos) +{ + ADS_PRINT("CDockContainerWidget::dropFloatingWidget"); + CDockWidget* SingleDroppedDockWidget = FloatingWidget->topLevelDockWidget(); + CDockWidget* SingleDockWidget = topLevelDockWidget(); + CDockAreaWidget* DockArea = dockAreaAt(TargetPos); + auto dropArea = InvalidDockWidgetArea; + auto ContainerDropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor(); + bool Dropped = false; + + if (DockArea) + { + auto dropOverlay = d->DockManager->dockAreaOverlay(); + dropOverlay->setAllowedAreas(DockArea->allowedAreas()); + dropArea = dropOverlay->showOverlay(DockArea); + if (ContainerDropArea != InvalidDockWidgetArea && + ContainerDropArea != dropArea) + { + dropArea = InvalidDockWidgetArea; + } + + if (dropArea != InvalidDockWidgetArea) + { + ADS_PRINT("Dock Area Drop Content: " << dropArea); + d->dropIntoSection(FloatingWidget, DockArea, dropArea); + Dropped = true; + } + } + + // mouse is over container + if (InvalidDockWidgetArea == dropArea) + { + dropArea = ContainerDropArea; + ADS_PRINT("Container Drop Content: " << dropArea); + if (dropArea != InvalidDockWidgetArea) + { + d->dropIntoContainer(FloatingWidget, dropArea); + Dropped = true; + } + } + + if (Dropped) + { + // Fix https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues/351 + FloatingWidget->hideAndDeleteLater(); + + // If we dropped a floating widget with only one single dock widget, then we + // drop a top level widget that changes from floating to docked now + CDockWidget::emitTopLevelEventForWidget(SingleDroppedDockWidget, false); + + // If there was a top level widget before the drop, then it is not top + // level widget anymore + CDockWidget::emitTopLevelEventForWidget(SingleDockWidget, false); + } + + window()->activateWindow(); + if (SingleDroppedDockWidget) + { + d->DockManager->notifyWidgetOrAreaRelocation(SingleDroppedDockWidget); + } + d->DockManager->notifyFloatingWidgetDrop(FloatingWidget); +} + + +//============================================================================ +void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget) +{ + CDockWidget* SingleDockWidget = topLevelDockWidget(); + if (TargetAreaWidget) + { + d->moveToNewSection(Widget, TargetAreaWidget, DropArea); + } + else + { + d->moveToContainer(Widget, DropArea); + } + + // If there was a top level widget before the drop, then it is not top + // level widget anymore + CDockWidget::emitTopLevelEventForWidget(SingleDockWidget, false); + + window()->activateWindow(); + d->DockManager->notifyWidgetOrAreaRelocation(Widget); +} + + +//============================================================================ +QList CDockContainerWidget::openedDockAreas() const +{ + QList Result; + for (auto DockArea : d->DockAreas) + { + if (!DockArea->isHidden()) + { + Result.append(DockArea); + } + } + + return Result; +} + + +//============================================================================ +QList CDockContainerWidget::openedDockWidgets() const +{ + QList DockWidgetList; + for (auto DockArea : d->DockAreas) + { + if (!DockArea->isHidden()) + { + DockWidgetList.append(DockArea->openedDockWidgets()); + } + } + + return DockWidgetList; +} + + +//============================================================================ +bool CDockContainerWidget::hasOpenDockAreas() const +{ + for (auto DockArea : d->DockAreas) + { + if (!DockArea->isHidden()) + { + return true; + } + } + + return false; +} + + +//============================================================================ +void CDockContainerWidget::saveState(QXmlStreamWriter& s) const +{ + ADS_PRINT("CDockContainerWidget::saveState isFloating " + << isFloating()); + + s.writeStartElement("Container"); + s.writeAttribute("Floating", QString::number(isFloating() ? 1 : 0)); + if (isFloating()) + { + CFloatingDockContainer* FloatingWidget = floatingWidget(); + QByteArray Geometry = FloatingWidget->saveGeometry(); +#if QT_VERSION < 0x050900 + s.writeTextElement("Geometry", qByteArrayToHex(Geometry, ' ')); +#else + s.writeTextElement("Geometry", Geometry.toHex(' ')); +#endif + } + d->saveChildNodesState(s, d->RootSplitter); + s.writeEndElement(); +} + + +//============================================================================ +bool CDockContainerWidget::restoreState(CDockingStateReader& s, bool Testing) +{ + bool IsFloating = s.attributes().value("Floating").toInt(); + ADS_PRINT("Restore CDockContainerWidget Floating" << IsFloating); + + QWidget*NewRootSplitter {}; + if (!Testing) + { + d->VisibleDockAreaCount = -1;// invalidate the dock area count + d->DockAreas.clear(); + std::fill(std::begin(d->LastAddedAreaCache),std::end(d->LastAddedAreaCache), nullptr); + } + + if (IsFloating) + { + ADS_PRINT("Restore floating widget"); + if (!s.readNextStartElement() || s.name() != QLatin1String("Geometry")) + { + return false; + } + + QByteArray GeometryString = s.readElementText(CDockingStateReader::ErrorOnUnexpectedElement).toLocal8Bit(); + QByteArray Geometry = QByteArray::fromHex(GeometryString); + if (Geometry.isEmpty()) + { + return false; + } + + if (!Testing) + { + CFloatingDockContainer* FloatingWidget = floatingWidget(); + if (FloatingWidget) + { + FloatingWidget->restoreGeometry(Geometry); + } + } + } + + if (!d->restoreChildNodes(s, NewRootSplitter, Testing)) + { + return false; + } + + if (Testing) + { + return true; + } + + // If the root splitter is empty, rostoreChildNodes returns a 0 pointer + // and we need to create a new empty root splitter + if (!NewRootSplitter) + { + NewRootSplitter = d->newSplitter(Qt::Horizontal); + } + + d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter); + QSplitter* OldRoot = d->RootSplitter; + d->RootSplitter = qobject_cast(NewRootSplitter); + OldRoot->deleteLater(); + + return true; +} + + +//============================================================================ +QSplitter* CDockContainerWidget::rootSplitter() const +{ + return d->RootSplitter; +} + + +//============================================================================ +void CDockContainerWidget::createRootSplitter() +{ + if (d->RootSplitter) + { + return; + } + d->RootSplitter = d->newSplitter(Qt::Horizontal); + d->Layout->addWidget(d->RootSplitter); +} + + +//============================================================================ +void CDockContainerWidget::dumpLayout() +{ +#if (ADS_DEBUG_LEVEL > 0) + qDebug("\n\nDumping layout --------------------------"); + std::cout << "\n\nDumping layout --------------------------" << std::endl; + d->dumpRecursive(0, d->RootSplitter); + qDebug("--------------------------\n\n"); + std::cout << "--------------------------\n\n" << std::endl; +#endif +} + + +//============================================================================ +CDockAreaWidget* CDockContainerWidget::lastAddedDockAreaWidget(DockWidgetArea area) const +{ + return d->LastAddedAreaCache[areaIdToIndex(area)]; +} + + +//============================================================================ +bool CDockContainerWidget::hasTopLevelDockWidget() const +{ + auto DockAreas = openedDockAreas(); + if (DockAreas.count() != 1) + { + return false; + } + + return DockAreas[0]->openDockWidgetsCount() == 1; +} + + +//============================================================================ +CDockWidget* CDockContainerWidget::topLevelDockWidget() const +{ + auto TopLevelDockArea = topLevelDockArea(); + if (!TopLevelDockArea) + { + return nullptr; + } + + auto DockWidgets = TopLevelDockArea->openedDockWidgets(); + if (DockWidgets.count() != 1) + { + return nullptr; + } + + return DockWidgets[0]; + +} + + +//============================================================================ +CDockAreaWidget* CDockContainerWidget::topLevelDockArea() const +{ + auto DockAreas = openedDockAreas(); + if (DockAreas.count() != 1) + { + return nullptr; + } + + return DockAreas[0]; +} + + +//============================================================================ +QList CDockContainerWidget::dockWidgets() const +{ + QList Result; + for (const auto DockArea : d->DockAreas) + { + Result.append(DockArea->dockWidgets()); + } + + return Result; +} + + +//============================================================================ +void CDockContainerWidget::updateSplitterHandles(QSplitter* splitter) +{ + d->updateSplitterHandles(splitter); +} + + +//============================================================================ +CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const +{ + CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures); + for (const auto DockArea : d->DockAreas) + { + Features &= DockArea->features(); + } + + return Features; +} + + +//============================================================================ +CFloatingDockContainer* CDockContainerWidget::floatingWidget() const +{ + return internal::findParent(this); +} + + +//============================================================================ +void CDockContainerWidget::closeOtherAreas(CDockAreaWidget* KeepOpenArea) +{ + for (const auto DockArea : d->DockAreas) + { + if (DockArea == KeepOpenArea) + { + continue; + } + + if (!DockArea->features(BitwiseAnd).testFlag(CDockWidget::DockWidgetClosable)) + { + continue; + } + + // We do not close areas with widgets with custom close handling + if (DockArea->features(BitwiseOr).testFlag(CDockWidget::CustomCloseHandling)) + { + continue; + } + + DockArea->closeArea(); + } +} + + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockContainerWidget.cpp diff --git a/ads/DockContainerWidget.h b/ads/DockContainerWidget.h new file mode 100644 index 0000000..49a3e80 --- /dev/null +++ b/ads/DockContainerWidget.h @@ -0,0 +1,302 @@ +#ifndef DockContainerWidgetH +#define DockContainerWidgetH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockContainerWidget.h +/// \author Uwe Kindler +/// \date 24.02.2017 +/// \brief Declaration of CDockContainerWidget class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include "ads_globals.h" +#include "DockWidget.h" + +QT_FORWARD_DECLARE_CLASS(QXmlStreamWriter) + + +namespace ads +{ +class DockContainerWidgetPrivate; +class CDockAreaWidget; +class CDockWidget; +class CDockManager; +struct DockManagerPrivate; +class CFloatingDockContainer; +struct FloatingDockContainerPrivate; +class CFloatingDragPreview; +struct FloatingDragPreviewPrivate; +class CDockingStateReader; + + +/** + * Container that manages a number of dock areas with single dock widgets + * or tabyfied dock widgets in each area. + * Each window that support docking has a DockContainerWidget. That means + * the main application window and all floating windows contain a + * DockContainerWidget instance. + */ +class ADS_EXPORT CDockContainerWidget : public QFrame +{ + Q_OBJECT +private: + DockContainerWidgetPrivate* d; ///< private data (pimpl) + friend class DockContainerWidgetPrivate; + friend class CDockManager; + friend struct DockManagerPrivate; + friend class CDockAreaWidget; + friend struct DockAreaWidgetPrivate; + friend class CFloatingDockContainer; + friend struct FloatingDockContainerPrivate; + friend class CDockWidget; + friend class CFloatingDragPreview; + friend struct FloatingDragPreviewPrivate; + +protected: + /** + * Handles activation events to update zOrderIndex + */ + virtual bool event(QEvent *e) override; + + /** + * Access function for the internal root splitter + */ + QSplitter* rootSplitter() const; + + /** + * Helper function for creation of the root splitter + */ + void createRootSplitter(); + + /** + * Drop floating widget into the container + */ + void dropFloatingWidget(CFloatingDockContainer* FloatingWidget, const QPoint& TargetPos); + + /** + * Drop a dock area or a dock widget given in widget parameter. + * If the TargetAreaWidget is a nullptr, then the DropArea indicates + * the drop area for the container. If the given TargetAreaWidget is not + * a nullptr, then the DropArea indicates the drop area in the given + * TargetAreaWidget + */ + void dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget); + + /** + * Adds the given dock area to this container widget + */ + void addDockArea(CDockAreaWidget* DockAreaWidget, DockWidgetArea area = CenterDockWidgetArea); + + /** + * Removes the given dock area from this container + */ + void removeDockArea(CDockAreaWidget* area); + + /** + * Saves the state into the given stream + */ + void saveState(QXmlStreamWriter& Stream) const; + + /** + * Restores the state from given stream. + * If Testing is true, the function only parses the data from the given + * stream but does not restore anything. You can use this check for + * faulty files before you start restoring the state + */ + bool restoreState(CDockingStateReader& Stream, bool Testing); + + /** + * This function returns the last added dock area widget for the given + * area identifier or 0 if no dock area widget has been added for the given + * area + */ + CDockAreaWidget* lastAddedDockAreaWidget(DockWidgetArea area) const; + + /** + * If hasSingleVisibleDockWidget() returns true, this function returns the + * one and only visible dock widget. Otherwise it returns a nullptr. + */ + CDockWidget* topLevelDockWidget() const; + + /** + * Returns the top level dock area. + */ + CDockAreaWidget* topLevelDockArea() const; + + /** + * This function returns a list of all dock widgets in this floating widget. + * It may be possible, depending on the implementation, that dock widgets, + * that are not visible to the user have no parent widget. Therefore simply + * calling findChildren() would not work here. Therefore this function + * iterates over all dock areas and creates a list that contains all + * dock widgets returned from all dock areas. + */ + QList dockWidgets() const; + + /** + * This function forces the dock container widget to update handles of splitters + * based on resize modes of dock widgets contained in the container. + */ + void updateSplitterHandles(QSplitter* splitter); + +public: + /** + * Default Constructor + */ + CDockContainerWidget(CDockManager* DockManager, QWidget* parent = 0); + + /** + * Virtual Destructor + */ + virtual ~CDockContainerWidget(); + + /** + * Adds dockwidget into the given area. + * If DockAreaWidget is not null, then the area parameter indicates the area + * into the DockAreaWidget. If DockAreaWidget is null, the Dockwidget will + * be dropped into the container. + * \return Returns the dock area widget that contains the new DockWidget + */ + CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, + CDockAreaWidget* DockAreaWidget = nullptr); + + /** + * Removes dockwidget + */ + void removeDockWidget(CDockWidget* Dockwidget); + + /** + * Returns the current zOrderIndex + */ + virtual unsigned int zOrderIndex() const; + + /** + * This function returns true if this container widgets z order index is + * higher than the index of the container widget given in Other parameter + */ + bool isInFrontOf(CDockContainerWidget* Other) const; + + /** + * Returns the dock area at the given global position or 0 if there is no + * dock area at this position + */ + CDockAreaWidget* dockAreaAt(const QPoint& GlobalPos) const; + + /** + * Returns the dock area at the given Index or 0 if the index is out of + * range + */ + CDockAreaWidget* dockArea(int Index) const; + + /** + * Returns the list of dock areas that are not closed + * If all dock widgets in a dock area are closed, the dock area will be closed + */ + QList openedDockAreas() const; + + /** + * Returns a list for all open dock widgets in all open dock areas + */ + QList openedDockWidgets() const; + + /** + * This function returns true, if the container has open dock areas. + * This functions is a little bit faster than calling openedDockAreas().isEmpty() + * because it returns as soon as it finds an open dock area + */ + bool hasOpenDockAreas() const; + + /** + * This function returns true if this dock area has only one single + * visible dock widget. + * A top level widget is a real floating widget. Only the isFloating() + * function of top level widgets may returns true. + */ + bool hasTopLevelDockWidget() const; + + /** + * Returns the number of dock areas in this container + */ + int dockAreaCount() const; + + /** + * Returns the number of visible dock areas + */ + int visibleDockAreaCount() const; + + /** + * This function returns true, if this container is in a floating widget + */ + bool isFloating() const; + + /** + * Dumps the layout for debugging purposes + */ + void dumpLayout(); + + /** + * This functions returns the dock widget features of all dock widget in + * this container. + * A bitwise and is used to combine the flags of all dock widgets. That + * means, if only dock widget does not support a certain flag, the whole + * dock are does not support the flag. + */ + CDockWidget::DockWidgetFeatures features() const; + + /** + * If this dock container is in a floating widget, this function returns + * the floating widget. + * Else, it returns a nullptr. + */ + CFloatingDockContainer* floatingWidget() const; + + /** + * Call this function to close all dock areas except the KeepOpenArea + */ + void closeOtherAreas(CDockAreaWidget* KeepOpenArea); + +Q_SIGNALS: + /** + * This signal is emitted if one or multiple dock areas has been added to + * the internal list of dock areas. + * If multiple dock areas are inserted, this signal is emitted only once + */ + void dockAreasAdded(); + + /** + * This signal is emitted if one or multiple dock areas has been removed + */ + void dockAreasRemoved(); + + /** + * This signal is emitted if a dock area is opened or closed via + * toggleView() function + */ + void dockAreaViewToggled(ads::CDockAreaWidget* DockArea, bool Open); +}; // class DockContainerWidget +} // namespace ads +//----------------------------------------------------------------------------- +#endif // DockContainerWidgetH diff --git a/ads/DockFocusController.cpp b/ads/DockFocusController.cpp new file mode 100644 index 0000000..595c9fa --- /dev/null +++ b/ads/DockFocusController.cpp @@ -0,0 +1,415 @@ +//============================================================================ +/// \file DockFocusController.cpp +/// \author Uwe Kindler +/// \date 05.06.2020 +/// \brief Implementation of CDockFocusController class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockFocusController.h" + +#include +#include + +#include +#include +#include +#include + +#include "DockWidget.h" +#include "DockAreaWidget.h" +#include "DockWidgetTab.h" +#include "DockContainerWidget.h" +#include "FloatingDockContainer.h" +#include "DockManager.h" +#include "DockAreaTitleBar.h" + +#ifdef Q_OS_LINUX +#include "linux/FloatingWidgetTitleBar.h" +#endif + +namespace ads +{ +static const char* const FocusedDockWidgetProperty = "FocusedDockWidget"; + +/** + * Private data class of CDockFocusController class (pimpl) + */ +struct DockFocusControllerPrivate +{ + CDockFocusController *_this; + QPointer FocusedDockWidget = nullptr; + QPointer FocusedArea = nullptr; + CDockWidget* OldFocusedDockWidget = nullptr; +#ifdef Q_OS_LINUX + QPointer FloatingWidget = nullptr; +#endif + CDockManager* DockManager; + bool ForceFocusChangedSignal = false; + + /** + * Private data constructor + */ + DockFocusControllerPrivate(CDockFocusController *_public); + + /** + * This function updates the focus style of the given dock widget and + * the dock area that it belongs to + */ + void updateDockWidgetFocus(CDockWidget* DockWidget); +}; // struct DockFocusControllerPrivate + + + +//=========================================================================== +static void updateDockWidgetFocusStyle(CDockWidget* DockWidget, bool Focused) +{ + DockWidget->setProperty("focused", Focused); + DockWidget->tabWidget()->setProperty("focused", Focused); + DockWidget->tabWidget()->updateStyle(); + internal::repolishStyle(DockWidget); +} + + +//=========================================================================== +static void updateDockAreaFocusStyle(CDockAreaWidget* DockArea, bool Focused) +{ + DockArea->setProperty("focused", Focused); + internal::repolishStyle(DockArea); + internal::repolishStyle(DockArea->titleBar()); +} + + +//=========================================================================== +#ifdef Q_OS_LINUX +static void updateFloatingWidgetFocusStyle(CFloatingDockContainer* FloatingWidget, bool Focused) +{ + if (FloatingWidget->hasNativeTitleBar()) + { + return; + } + auto TitleBar = qobject_cast(FloatingWidget->titleBarWidget()); + if (!TitleBar) + { + return; + } + TitleBar->setProperty("focused", Focused); + TitleBar->updateStyle(); +} +#endif + + +//============================================================================ +DockFocusControllerPrivate::DockFocusControllerPrivate( + CDockFocusController *_public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) +{ + if (!DockWidget->features().testFlag(CDockWidget::DockWidgetFocusable)) + { + return; + } + + QWindow* Window = nullptr; + auto DockContainer = DockWidget->dockContainer(); + if (DockContainer) + { + Window = DockContainer->window()->windowHandle(); + } + + if (Window) + { + Window->setProperty(FocusedDockWidgetProperty, QVariant::fromValue(QPointer(DockWidget))); + } + CDockAreaWidget* NewFocusedDockArea = nullptr; + if (FocusedDockWidget) + { + updateDockWidgetFocusStyle(FocusedDockWidget, false); + } + + CDockWidget* old = FocusedDockWidget; + FocusedDockWidget = DockWidget; + updateDockWidgetFocusStyle(FocusedDockWidget, true); + NewFocusedDockArea = FocusedDockWidget->dockAreaWidget(); + if (NewFocusedDockArea && (FocusedArea != NewFocusedDockArea)) + { + if (FocusedArea) + { + QObject::disconnect(FocusedArea, SIGNAL(viewToggled(bool)), _this, SLOT(onFocusedDockAreaViewToggled(bool))); + updateDockAreaFocusStyle(FocusedArea, false); + } + + FocusedArea = NewFocusedDockArea; + updateDockAreaFocusStyle(FocusedArea, true); + QObject::connect(FocusedArea, SIGNAL(viewToggled(bool)), _this, SLOT(onFocusedDockAreaViewToggled(bool))); + } + + + + CFloatingDockContainer* NewFloatingWidget = nullptr; + DockContainer = FocusedDockWidget->dockContainer(); + if (DockContainer) + { + NewFloatingWidget = DockContainer->floatingWidget(); + } + + if (NewFloatingWidget) + { + NewFloatingWidget->setProperty(FocusedDockWidgetProperty, QVariant::fromValue(QPointer(DockWidget))); + } + + +#ifdef Q_OS_LINUX + // This code is required for styling the floating widget titlebar for linux + // depending on the current focus state + if (FloatingWidget != NewFloatingWidget) + { + if (FloatingWidget) + { + updateFloatingWidgetFocusStyle(FloatingWidget, false); + } + FloatingWidget = NewFloatingWidget; + + if (FloatingWidget) + { + updateFloatingWidgetFocusStyle(FloatingWidget, true); + } + } +#endif + + if (old == DockWidget && !ForceFocusChangedSignal) + { + return; + } + + ForceFocusChangedSignal = false; + if (DockWidget->isVisible()) + { + Q_EMIT DockManager->focusedDockWidgetChanged(old, DockWidget); + } + else + { + OldFocusedDockWidget = old; + QObject::connect(DockWidget, SIGNAL(visibilityChanged(bool)), _this, SLOT(onDockWidgetVisibilityChanged(bool))); + } +} + + + +//============================================================================ +void CDockFocusController::onDockWidgetVisibilityChanged(bool Visible) +{ + auto Sender = sender(); + auto DockWidget = qobject_cast(Sender); + disconnect(Sender, SIGNAL(visibilityChanged(bool)), this, SLOT(onDockWidgetVisibilityChanged(bool))); + if (DockWidget && Visible) + { + Q_EMIT d->DockManager->focusedDockWidgetChanged(d->OldFocusedDockWidget, DockWidget); + } +} + + +//============================================================================ +CDockFocusController::CDockFocusController(CDockManager* DockManager) : + Super(DockManager), + d(new DockFocusControllerPrivate(this)) +{ + d->DockManager = DockManager; + connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), + this, SLOT(onApplicationFocusChanged(QWidget*, QWidget*))); + connect(QApplication::instance(), SIGNAL(focusWindowChanged(QWindow*)), + this, SLOT(onFocusWindowChanged(QWindow*))); + connect(d->DockManager, SIGNAL(stateRestored()), SLOT(onStateRestored())); +} + +//============================================================================ +CDockFocusController::~CDockFocusController() +{ + delete d; +} + + +//============================================================================ +void CDockFocusController::onFocusWindowChanged(QWindow *focusWindow) +{ + if (!focusWindow) + { + return; + } + + auto vDockWidget = focusWindow->property(FocusedDockWidgetProperty); + if (!vDockWidget.isValid()) + { + return; + } + + auto DockWidget = vDockWidget.value>(); + if (!DockWidget) + { + return; + } + + d->updateDockWidgetFocus(DockWidget); +} + + +//=========================================================================== +void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidget* focusedNow) +{ + Q_UNUSED(focusedOld); + + if (d->DockManager->isRestoringState()) + { + return; + } + + ADS_PRINT("CDockFocusController::onApplicationFocusChanged " + << " old: " << focusedOld << " new: " << focusedNow); + if (!focusedNow) + { + return; + } + + CDockWidget* DockWidget = qobject_cast(focusedNow); + if (!DockWidget) + { + DockWidget = internal::findParent(focusedNow); + } + +#ifdef Q_OS_LINUX + if (!DockWidget) + { + return; + } +#else + if (!DockWidget || DockWidget->tabWidget()->isHidden()) + { + return; + } +#endif + + d->updateDockWidgetFocus(DockWidget); +} + + +//=========================================================================== +void CDockFocusController::setDockWidgetTabFocused(CDockWidgetTab* Tab) +{ + auto DockWidget = Tab->dockWidget(); + if (DockWidget) + { + d->updateDockWidgetFocus(DockWidget); + } +} + + +//=========================================================================== +void CDockFocusController::setDockWidgetFocused(CDockWidget* focusedNow) +{ + d->updateDockWidgetFocus(focusedNow); +} + + +//=========================================================================== +void CDockFocusController::onFocusedDockAreaViewToggled(bool Open) +{ + if (d->DockManager->isRestoringState()) + { + return; + } + + CDockAreaWidget* DockArea = qobject_cast(sender()); + if (!DockArea || Open) + { + return; + } + auto Container = DockArea->dockContainer(); + auto OpenedDockAreas = Container->openedDockAreas(); + if (OpenedDockAreas.isEmpty()) + { + return; + } + + d->updateDockWidgetFocus(OpenedDockAreas[0]->currentDockWidget()); +} + + +//=========================================================================== +void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget) +{ + if (d->DockManager->isRestoringState()) + { + return; + } + + CDockWidget* DockWidget = qobject_cast(DroppedWidget); + if (!DockWidget) + { + CDockAreaWidget* DockArea = qobject_cast(DroppedWidget); + if (DockArea) + { + DockWidget = DockArea->currentDockWidget(); + } + } + + if (!DockWidget) + { + return; + } + + d->ForceFocusChangedSignal = true; + CDockManager::setWidgetFocus(DockWidget); +} + + +//=========================================================================== +void CDockFocusController::notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget) +{ + if (!FloatingWidget || d->DockManager->isRestoringState()) + { + return; + } + + auto vDockWidget = FloatingWidget->property(FocusedDockWidgetProperty); + if (!vDockWidget.isValid()) + { + return; + } + + auto DockWidget = vDockWidget.value>(); + if (DockWidget) + { + DockWidget->dockAreaWidget()->setCurrentDockWidget(DockWidget); + CDockManager::setWidgetFocus(DockWidget); + } +} + + +//========================================================================== +void CDockFocusController::onStateRestored() +{ + if (d->FocusedDockWidget) + { + updateDockWidgetFocusStyle(d->FocusedDockWidget, false); + } +} + + +//========================================================================== +CDockWidget* CDockFocusController::focusedDockWidget() const +{ + return d->FocusedDockWidget.data(); +} + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockFocusController.cpp diff --git a/ads/DockFocusController.h b/ads/DockFocusController.h new file mode 100644 index 0000000..b080f3b --- /dev/null +++ b/ads/DockFocusController.h @@ -0,0 +1,88 @@ +#ifndef DockFocusControllerH +#define DockFocusControllerH +//============================================================================ +/// \file DockFocusController.h +/// \author Uwe Kindler +/// \date 05.06.2020 +/// \brief Declaration of CDockFocusController class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include "ads_globals.h" +#include "DockManager.h" + +namespace ads +{ +struct DockFocusControllerPrivate; +class CDockManager; +class CFloatingDockContainer; + +/** + * Manages focus styling of dock widgets and handling of focus changes + */ +class ADS_EXPORT CDockFocusController : public QObject +{ + Q_OBJECT +private: + DockFocusControllerPrivate* d; ///< private data (pimpl) + friend struct DockFocusControllerPrivate; + +private Q_SLOTS: + void onApplicationFocusChanged(QWidget *old, QWidget *now); + void onFocusWindowChanged(QWindow *focusWindow); + void onFocusedDockAreaViewToggled(bool Open); + void onStateRestored(); + void onDockWidgetVisibilityChanged(bool Visible); + +public: + using Super = QObject; + /** + * Default Constructor + */ + CDockFocusController(CDockManager* DockManager); + + /** + * Virtual Destructor + */ + virtual ~CDockFocusController(); + + /** + * A container needs to call this function if a widget has been dropped + * into it + */ + void notifyWidgetOrAreaRelocation(QWidget* RelocatedWidget); + + /** + * This function is called, if a floating widget has been dropped into + * an new position. + * When this function is called, all dock widgets of the FloatingWidget + * are already inserted into its new position + */ + void notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget); + + /** + * Returns the dock widget that has focus style in the ui or a nullptr if + * not dock widget is painted focused. + */ + CDockWidget* focusedDockWidget() const; + + /** + * Request focus highlighting for the given dock widget assigned to the tab + * given in Tab parameter + */ + void setDockWidgetTabFocused(CDockWidgetTab* Tab); + +public Q_SLOTS: + /** + * Request a focus change to the given dock widget + */ + void setDockWidgetFocused(CDockWidget* focusedNow); +}; // class DockFocusController +} + // namespace ads +//----------------------------------------------------------------------------- +#endif // DockFocusControllerH + diff --git a/ads/DockManager.cpp b/ads/DockManager.cpp new file mode 100644 index 0000000..ecb558c --- /dev/null +++ b/ads/DockManager.cpp @@ -0,0 +1,1250 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockManager.cpp +/// \author Uwe Kindler +/// \date 26.02.2017 +/// \brief Implementation of CDockManager class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockWidgetTab.h" +#include "DockManager.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FloatingDockContainer.h" +#include "DockOverlay.h" +#include "DockWidget.h" +#include "ads_globals.h" +#include "DockAreaWidget.h" +#include "IconProvider.h" +#include "DockingStateReader.h" +#include "DockAreaTitleBar.h" +#include "DockFocusController.h" +#include "DockSplitter.h" + +#ifdef Q_OS_LINUX +#include "linux/FloatingWidgetTitleBar.h" +#endif + + +/** + * Initializes the resources specified by the .qrc file with the specified base + * name. Normally, when resources are built as part of the application, the + * resources are loaded automatically at startup. The Q_INIT_RESOURCE() macro + * is necessary on some platforms for resources stored in a static library. + * Because GCC causes a linker error if we put Q_INIT_RESOURCE into the + * loadStyleSheet() function, we place it into a function outside of the ads + * namespace + */ +static void initResource() +{ + Q_INIT_RESOURCE(ads); +} + + +namespace ads +{ +/** + * Internal file version in case the structure changes internally + */ +enum eStateFileVersion +{ + InitialVersion = 0, //!< InitialVersion + Version1 = 1, //!< Version1 + CurrentVersion = Version1//!< CurrentVersion +}; + +static CDockManager::ConfigFlags StaticConfigFlags = CDockManager::DefaultNonOpaqueConfig; + +/** + * Private data class of CDockManager class (pimpl) + */ +struct DockManagerPrivate +{ + CDockManager* _this; + QList FloatingWidgets; + QList HiddenFloatingWidgets; + QList Containers; + CDockOverlay* ContainerOverlay; + CDockOverlay* DockAreaOverlay; + QMap DockWidgetsMap; + QMap Perspectives; + QMap ViewMenuGroups; + QMenu* ViewMenu; + CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted; + bool RestoringState = false; + QVector UninitializedFloatingWidgets; + CDockFocusController* FocusController = nullptr; + CDockWidget* CentralWidget = nullptr; + + /** + * Private data constructor + */ + DockManagerPrivate(CDockManager* _public); + + /** + * Checks if the given data stream is a valid docking system state + * file. + */ + bool checkFormat(const QByteArray &state, int version); + + /** + * Restores the state + */ + bool restoreStateFromXml(const QByteArray &state, int version, bool Testing = internal::Restore); + + /** + * Restore state + */ + bool restoreState(const QByteArray &state, int version); + + void restoreDockWidgetsOpenState(); + void restoreDockAreasIndices(); + void emitTopLevelEvents(); + + void hideFloatingWidgets() + { + // Hide updates of floating widgets from user + for (auto FloatingWidget : FloatingWidgets) + { + FloatingWidget->hide(); + } + } + + void markDockWidgetsDirty() + { + for (auto DockWidget : DockWidgetsMap) + { + DockWidget->setProperty("dirty", true); + } + } + + /** + * Restores the container with the given index + */ + bool restoreContainer(int Index, CDockingStateReader& stream, bool Testing); + + /** + * Loads the stylesheet + */ + void loadStylesheet(); + + /** + * Adds action to menu - optionally in sorted order + */ + void addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted); +}; +// struct DockManagerPrivate + +//============================================================================ +DockManagerPrivate::DockManagerPrivate(CDockManager* _public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockManagerPrivate::loadStylesheet() +{ + initResource(); + QString Result; + QString FileName = ":ads/stylesheets/"; + FileName += CDockManager::testConfigFlag(CDockManager::FocusHighlighting) + ? "focus_highlighting" : "default"; +#ifdef Q_OS_LINUX + FileName += "_linux"; +#endif + FileName += ".css"; + QFile StyleSheetFile(FileName); + StyleSheetFile.open(QIODevice::ReadOnly); + QTextStream StyleSheetStream(&StyleSheetFile); + Result = StyleSheetStream.readAll(); + StyleSheetFile.close(); + _this->setStyleSheet(Result); +} + + +//============================================================================ +bool DockManagerPrivate::restoreContainer(int Index, CDockingStateReader& stream, bool Testing) +{ + if (Testing) + { + Index = 0; + } + + bool Result = false; + if (Index >= Containers.count()) + { + CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(_this); + Result = FloatingWidget->restoreState(stream, Testing); + } + else + { + ADS_PRINT("d->Containers[i]->restoreState "); + auto Container = Containers[Index]; + if (Container->isFloating()) + { + Result = Container->floatingWidget()->restoreState(stream, Testing); + } + else + { + Result = Container->restoreState(stream, Testing); + } + } + + return Result; +} + + +//============================================================================ +bool DockManagerPrivate::checkFormat(const QByteArray &state, int version) +{ + return restoreStateFromXml(state, version, internal::RestoreTesting); +} + + +//============================================================================ +bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int version, + bool Testing) +{ + Q_UNUSED(version); + + if (state.isEmpty()) + { + return false; + } + CDockingStateReader s(state); + s.readNextStartElement(); + if (s.name() != QLatin1String("QtAdvancedDockingSystem")) + { + return false; + } + ADS_PRINT(s.attributes().value("Version")); + bool ok; + int v = s.attributes().value("Version").toInt(&ok); + if (!ok || v > CurrentVersion) + { + return false; + } + s.setFileVersion(v); + + ADS_PRINT(s.attributes().value("UserVersion")); + // Older files do not support UserVersion but we still want to load them so + // we first test if the attribute exists + if (!s.attributes().value("UserVersion").isEmpty()) + { + v = s.attributes().value("UserVersion").toInt(&ok); + if (!ok || v != version) + { + return false; + } + } + + bool Result = true; +#ifdef ADS_DEBUG_PRINT + int DockContainers = s.attributes().value("Containers").toInt(); +#endif + ADS_PRINT(DockContainers); + + if (CentralWidget) + { + const auto CentralWidgetAttribute = s.attributes().value("CentralWidget"); + // If we have a central widget but a state without central widget, then + // something is wrong. + if (CentralWidgetAttribute.isEmpty()) + { + qWarning() << "Dock manager has central widget but saved state does not have central widget."; + return false; + } + + // If the object name of the central widget does not match the name of the + // saved central widget, the something is wrong + if (CentralWidget->objectName() != CentralWidgetAttribute.toString()) + { + qWarning() << "Object name of central widget does not match name of central widget in saved state."; + return false; + } + } + + int DockContainerCount = 0; + while (s.readNextStartElement()) + { + if (s.name() == QLatin1String("Container")) + { + Result = restoreContainer(DockContainerCount, s, Testing); + if (!Result) + { + break; + } + DockContainerCount++; + } + } + + if (!Testing) + { + // Delete remaining empty floating widgets + int FloatingWidgetIndex = DockContainerCount - 1; + for (int i = FloatingWidgetIndex; i < FloatingWidgets.count(); ++i) + { + auto* floatingWidget = FloatingWidgets[i]; + _this->removeDockContainer(floatingWidget->dockContainer()); + floatingWidget->deleteLater(); + } + } + + return Result; +} + + +//============================================================================ +void DockManagerPrivate::restoreDockWidgetsOpenState() +{ + // All dock widgets, that have not been processed in the restore state + // function are invisible to the user now and have no assigned dock area + // They do not belong to any dock container, until the user toggles the + // toggle view action the next time + for (auto DockWidget : DockWidgetsMap) + { + if (DockWidget->property(internal::DirtyProperty).toBool()) + { + DockWidget->flagAsUnassigned(); + Q_EMIT DockWidget->viewToggled(false); + } + else + { + DockWidget->toggleViewInternal(!DockWidget->property(internal::ClosedProperty).toBool()); + } + } +} + + +//============================================================================ +void DockManagerPrivate::restoreDockAreasIndices() +{ + // Now all dock areas are properly restored and we setup the index of + // The dock areas because the previous toggleView() action has changed + // the dock area index + int Count = 0; + for (auto DockContainer : Containers) + { + Count++; + for (int i = 0; i < DockContainer->dockAreaCount(); ++i) + { + CDockAreaWidget* DockArea = DockContainer->dockArea(i); + QString DockWidgetName = DockArea->property("currentDockWidget").toString(); + CDockWidget* DockWidget = nullptr; + if (!DockWidgetName.isEmpty()) + { + DockWidget = _this->findDockWidget(DockWidgetName); + } + + if (!DockWidget || DockWidget->isClosed()) + { + int Index = DockArea->indexOfFirstOpenDockWidget(); + if (Index < 0) + { + continue; + } + DockArea->setCurrentIndex(Index); + } + else + { + DockArea->internalSetCurrentDockWidget(DockWidget); + } + } + } +} + +//============================================================================ +void DockManagerPrivate::emitTopLevelEvents() +{ + // Finally we need to send the topLevelChanged() signals for all dock + // widgets if top level changed + for (auto DockContainer : Containers) + { + CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget(); + if (TopLevelDockWidget) + { + TopLevelDockWidget->emitTopLevelChanged(true); + } + else + { + for (int i = 0; i < DockContainer->dockAreaCount(); ++i) + { + auto DockArea = DockContainer->dockArea(i); + for (auto DockWidget : DockArea->dockWidgets()) + { + DockWidget->emitTopLevelChanged(false); + } + } + } + } +} + + +//============================================================================ +bool DockManagerPrivate::restoreState(const QByteArray& State, int version) +{ + QByteArray state = State.startsWith("dumpLayout(); + + return true; +} + + +//============================================================================ +void DockManagerPrivate::addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted) +{ + if (InsertSorted) + { + auto Actions = Menu->actions(); + auto it = std::find_if(Actions.begin(), Actions.end(), + [&Action](const QAction* a) + { + return a->text().compare(Action->text(), Qt::CaseInsensitive) > 0; + }); + + if (it == Actions.end()) + { + Menu->addAction(Action); + } + else + { + Menu->insertAction(*it, Action); + } + } + else + { + Menu->addAction(Action); + } +} + + +//============================================================================ +CDockManager::CDockManager(QWidget *parent) : + CDockContainerWidget(this, parent), + d(new DockManagerPrivate(this)) +{ + createRootSplitter(); + QMainWindow* MainWindow = qobject_cast(parent); + if (MainWindow) + { + MainWindow->setCentralWidget(this); + } + + d->ViewMenu = new QMenu(tr("Show View"), this); + d->DockAreaOverlay = new CDockOverlay(this, CDockOverlay::ModeDockAreaOverlay); + d->ContainerOverlay = new CDockOverlay(this, CDockOverlay::ModeContainerOverlay); + d->Containers.append(this); + d->loadStylesheet(); + + if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) + { + d->FocusController = new CDockFocusController(this); + } + +#ifdef Q_OS_LINUX + window()->installEventFilter(this); +#endif +} + +//============================================================================ +CDockManager::~CDockManager() +{ + // fix memory leaks, see https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues/307 + std::vector areas; + for ( int i = 0; i != dockAreaCount(); ++i ) + { + areas.push_back( dockArea(i) ); + } + for ( auto area : areas ) + { + for ( auto widget : area->dockWidgets() ) + delete widget; + + delete area; + } + + auto FloatingWidgets = d->FloatingWidgets; + for (auto FloatingWidget : FloatingWidgets) + { + delete FloatingWidget; + } + delete d; +} + +//============================================================================ +#ifdef Q_OS_LINUX +bool CDockManager::eventFilter(QObject *obj, QEvent *e) +{ + // Emulate Qt:Tool behaviour. + // Required because on some WMs Tool windows can't be maximized. + + // Window always on top of the MainWindow. + if (e->type() == QEvent::WindowActivate) + { + for (auto _window : floatingWidgets()) + { + if (!_window->isVisible() || window()->isMinimized()) + { + continue; + } + // setWindowFlags(Qt::WindowStaysOnTopHint) will hide the window and thus requires a show call. + // This then leads to flickering and a nasty endless loop (also buggy behaviour on Ubuntu). + // So we just do it ourself. + if(QGuiApplication::platformName() == QLatin1String("xcb")) + { + internal::xcb_update_prop(true, _window->window()->winId(), + "_NET_WM_STATE", "_NET_WM_STATE_ABOVE", "_NET_WM_STATE_STAYS_ON_TOP"); + } + else + { + _window->setWindowFlag(Qt::WindowStaysOnTopHint, true); + } + } + } + else if (e->type() == QEvent::WindowDeactivate) + { + for (auto _window : floatingWidgets()) + { + if (!_window->isVisible() || window()->isMinimized()) + { + continue; + } + + if(QGuiApplication::platformName() == QLatin1String("xcb")) + { + internal::xcb_update_prop(false, _window->window()->winId(), + "_NET_WM_STATE", "_NET_WM_STATE_ABOVE", "_NET_WM_STATE_STAYS_ON_TOP"); + } + else + { + _window->setWindowFlag(Qt::WindowStaysOnTopHint, false); + } + _window->raise(); + } + } + + // Sync minimize with MainWindow + if (e->type() == QEvent::WindowStateChange) + { + for (auto _window : floatingWidgets()) + { + if (! _window->isVisible()) + { + continue; + } + + if (window()->isMinimized()) + { + _window->showMinimized(); + } + else + { + _window->setWindowState(_window->windowState() & (~Qt::WindowMinimized)); + } + } + if (!window()->isMinimized()) + { + QApplication::setActiveWindow(window()); + } + } + return Super::eventFilter(obj, e); +} +#endif + +//============================================================================ +void CDockManager::registerFloatingWidget(CFloatingDockContainer* FloatingWidget) +{ + d->FloatingWidgets.append(FloatingWidget); + Q_EMIT floatingWidgetCreated(FloatingWidget); + ADS_PRINT("d->FloatingWidgets.count() " << d->FloatingWidgets.count()); +} + + +//============================================================================ +void CDockManager::removeFloatingWidget(CFloatingDockContainer* FloatingWidget) +{ + d->FloatingWidgets.removeAll(FloatingWidget); +} + + +//============================================================================ +void CDockManager::registerDockContainer(CDockContainerWidget* DockContainer) +{ + d->Containers.append(DockContainer); +} + + +//============================================================================ +void CDockManager::removeDockContainer(CDockContainerWidget* DockContainer) +{ + if (this != DockContainer) + { + d->Containers.removeAll(DockContainer); + } +} + + +//============================================================================ +CDockOverlay* CDockManager::containerOverlay() const +{ + return d->ContainerOverlay; +} + + +//============================================================================ +CDockOverlay* CDockManager::dockAreaOverlay() const +{ + return d->DockAreaOverlay; +} + + +//============================================================================ +const QList CDockManager::dockContainers() const +{ + return d->Containers; +} + + +//============================================================================ +const QList CDockManager::floatingWidgets() const +{ + return d->FloatingWidgets; +} + + +//============================================================================ +unsigned int CDockManager::zOrderIndex() const +{ + return 0; +} + + +//============================================================================ +QByteArray CDockManager::saveState(int version) const +{ + QByteArray xmldata; + QXmlStreamWriter s(&xmldata); + auto ConfigFlags = CDockManager::configFlags(); + s.setAutoFormatting(ConfigFlags.testFlag(XmlAutoFormattingEnabled)); + s.writeStartDocument(); + s.writeStartElement("QtAdvancedDockingSystem"); + s.writeAttribute("Version", QString::number(CurrentVersion)); + s.writeAttribute("UserVersion", QString::number(version)); + s.writeAttribute("Containers", QString::number(d->Containers.count())); + if (d->CentralWidget) + { + s.writeAttribute("CentralWidget", d->CentralWidget->objectName()); + } + for (auto Container : d->Containers) + { + Container->saveState(s); + } + + s.writeEndElement(); + s.writeEndDocument(); + + return ConfigFlags.testFlag(XmlCompressionEnabled) + ? qCompress(xmldata, 9) : xmldata; +} + + +//============================================================================ +bool CDockManager::restoreState(const QByteArray &state, int version) +{ + // Prevent multiple calls as long as state is not restore. This may + // happen, if QApplication::processEvents() is called somewhere + if (d->RestoringState) + { + return false; + } + + // We hide the complete dock manager here. Restoring the state means + // that DockWidgets are removed from the DockArea internal stack layout + // which in turn means, that each time a widget is removed the stack + // will show and raise the next available widget which in turn + // triggers show events for the dock widgets. To avoid this we hide the + // dock manager. Because there will be no processing of application + // events until this function is finished, the user will not see this + // hiding + bool IsHidden = this->isHidden(); + if (!IsHidden) + { + hide(); + } + d->RestoringState = true; + Q_EMIT restoringState(); + bool Result = d->restoreState(state, version); + d->RestoringState = false; + if (!IsHidden) + { + show(); + } + Q_EMIT stateRestored(); + return Result; +} + + +//============================================================================ +CFloatingDockContainer* CDockManager::addDockWidgetFloating(CDockWidget* Dockwidget) +{ + d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); + CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget(); + if (OldDockArea) + { + OldDockArea->removeDockWidget(Dockwidget); + } + + Dockwidget->setDockManager(this); + CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(Dockwidget); + FloatingWidget->resize(Dockwidget->size()); + if (isVisible()) + { + FloatingWidget->show(); + } + else + { + d->UninitializedFloatingWidgets.append(FloatingWidget); + } + Q_EMIT dockWidgetAdded(Dockwidget); + return FloatingWidget; +} + + +//============================================================================ +void CDockManager::showEvent(QShowEvent *event) +{ + Super::showEvent(event); + + // Fix Issue #380 + restoreHiddenFloatingWidgets(); + if (d->UninitializedFloatingWidgets.empty()) + { + return; + } + + for (auto FloatingWidget : d->UninitializedFloatingWidgets) + { + // Check, if someone closed a floating dock widget before the dock + // manager is shown + if (FloatingWidget->dockContainer()->hasOpenDockAreas()) + { + FloatingWidget->show(); + } + } + d->UninitializedFloatingWidgets.clear(); +} + + +//============================================================================ +void CDockManager::restoreHiddenFloatingWidgets() +{ + if (d->HiddenFloatingWidgets.isEmpty()) + { + return; + } + + // Restore floating widgets that were hidden upon hideManagerAndFloatingWidgets + for (auto FloatingWidget : d->HiddenFloatingWidgets) + { + bool hasDockWidgetVisible = false; + + // Needed to prevent CFloatingDockContainer being shown empty + // Could make sense to move this to CFloatingDockContainer::showEvent(QShowEvent *event) + // if experiencing CFloatingDockContainer being shown empty in other situations, but let's keep + // it here for now to make sure changes to fix Issue #380 does not impact existing behaviours + for (auto dockWidget : FloatingWidget->dockWidgets()) + { + if (dockWidget->toggleViewAction()->isChecked()) + { + dockWidget->toggleView(true); + hasDockWidgetVisible = true; + } + } + + if (hasDockWidgetVisible) + { + FloatingWidget->show(); + } + } + + d->HiddenFloatingWidgets.clear(); +} + +//============================================================================ +CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area, + CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) +{ + d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); + auto Container = DockAreaWidget ? DockAreaWidget->dockContainer(): this; + auto AreaOfAddedDockWidget = Container->addDockWidget(area, Dockwidget, DockAreaWidget); + Q_EMIT dockWidgetAdded(Dockwidget); + return AreaOfAddedDockWidget; +} + +//============================================================================ +CDockAreaWidget* CDockManager::addDockWidgetToContainer(DockWidgetArea area, + CDockWidget* Dockwidget, CDockContainerWidget* DockContainerWidget) +{ + d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget); + auto AreaOfAddedDockWidget = DockContainerWidget->addDockWidget(area, Dockwidget); + Q_EMIT dockWidgetAdded(Dockwidget); + return AreaOfAddedDockWidget; +} + + +//============================================================================ +CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area, + CDockWidget* Dockwidget) +{ + CDockAreaWidget* AreaWidget = lastAddedDockAreaWidget(area); + if (AreaWidget) + { + return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, AreaWidget); + } + else + { + return addDockWidget(area, Dockwidget, nullptr); + } +} + + +//============================================================================ +CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget, + CDockAreaWidget* DockAreaWidget) +{ + return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget); +} + + +//============================================================================ +CDockWidget* CDockManager::findDockWidget(const QString& ObjectName) const +{ + return d->DockWidgetsMap.value(ObjectName, nullptr); +} + +//============================================================================ +void CDockManager::removeDockWidget(CDockWidget* Dockwidget) +{ + Q_EMIT dockWidgetAboutToBeRemoved(Dockwidget); + d->DockWidgetsMap.remove(Dockwidget->objectName()); + CDockContainerWidget::removeDockWidget(Dockwidget); + Dockwidget->setDockManager(nullptr); + Q_EMIT dockWidgetRemoved(Dockwidget); +} + +//============================================================================ +QMap CDockManager::dockWidgetsMap() const +{ + return d->DockWidgetsMap; +} + + +//============================================================================ +void CDockManager::addPerspective(const QString& UniquePrespectiveName) +{ + d->Perspectives.insert(UniquePrespectiveName, saveState()); + Q_EMIT perspectiveListChanged(); +} + + +//============================================================================ +void CDockManager::removePerspective(const QString& Name) +{ + removePerspectives({Name}); +} + + +//============================================================================ +void CDockManager::removePerspectives(const QStringList& Names) +{ + int Count = 0; + for (auto Name : Names) + { + Count += d->Perspectives.remove(Name); + } + + if (Count) + { + Q_EMIT perspectivesRemoved(); + Q_EMIT perspectiveListChanged(); + } +} + + +//============================================================================ +QStringList CDockManager::perspectiveNames() const +{ + return d->Perspectives.keys(); +} + + +//============================================================================ +void CDockManager::openPerspective(const QString& PerspectiveName) +{ + const auto Iterator = d->Perspectives.find(PerspectiveName); + if (d->Perspectives.end() == Iterator) + { + return; + } + + Q_EMIT openingPerspective(PerspectiveName); + restoreState(Iterator.value()); + Q_EMIT perspectiveOpened(PerspectiveName); +} + + +//============================================================================ +void CDockManager::savePerspectives(QSettings& Settings) const +{ + Settings.beginWriteArray("Perspectives", d->Perspectives.size()); + int i = 0; + for (auto it = d->Perspectives.constBegin(); it != d->Perspectives.constEnd(); ++it) + { + Settings.setArrayIndex(i); + Settings.setValue("Name", it.key()); + Settings.setValue("State", it.value()); + ++i; + } + Settings.endArray(); +} + + +//============================================================================ +void CDockManager::loadPerspectives(QSettings& Settings) +{ + d->Perspectives.clear(); + int Size = Settings.beginReadArray("Perspectives"); + if (!Size) + { + Settings.endArray(); + return; + } + + for (int i = 0; i < Size; ++i) + { + Settings.setArrayIndex(i); + QString Name = Settings.value("Name").toString(); + QByteArray Data = Settings.value("State").toByteArray(); + if (Name.isEmpty() || Data.isEmpty()) + { + continue; + } + + d->Perspectives.insert(Name, Data); + } + + Settings.endArray(); + Q_EMIT perspectiveListChanged(); + Q_EMIT perspectiveListLoaded(); +} + + +//============================================================================ +CDockWidget* CDockManager::centralWidget() const +{ + return d->CentralWidget; +} + + +//============================================================================ +CDockAreaWidget* CDockManager::setCentralWidget(CDockWidget* widget) +{ + if (!widget) + { + d->CentralWidget = nullptr; + return nullptr; + } + + // Setting a new central widget is now allowed if there is already a central + // widget or if there are already other dock widgets + if (d->CentralWidget) + { + qWarning("Setting a central widget not possible because there is already a central widget."); + return nullptr; + } + + // Setting a central widget is now allowed if there are already other + // dock widgets. + if (!d->DockWidgetsMap.isEmpty()) + { + qWarning("Setting a central widget not possible - the central widget need to be the first " + "dock widget that is added to the dock manager."); + return nullptr; + } + + + widget->setFeature(CDockWidget::DockWidgetClosable, false); + widget->setFeature(CDockWidget::DockWidgetMovable, false); + widget->setFeature(CDockWidget::DockWidgetFloatable, false); + d->CentralWidget = widget; + CDockAreaWidget* CentralArea = addDockWidget(CenterDockWidgetArea, widget); + CentralArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); + return CentralArea; +} + +//============================================================================ +QAction* CDockManager::addToggleViewActionToMenu(QAction* ToggleViewAction, + const QString& Group, const QIcon& GroupIcon) +{ + bool AlphabeticallySorted = (MenuAlphabeticallySorted == d->MenuInsertionOrder); + if (!Group.isEmpty()) + { + QMenu* GroupMenu = d->ViewMenuGroups.value(Group, 0); + if (!GroupMenu) + { + GroupMenu = new QMenu(Group, this); + GroupMenu->setIcon(GroupIcon); + d->addActionToMenu(GroupMenu->menuAction(), d->ViewMenu, AlphabeticallySorted); + d->ViewMenuGroups.insert(Group, GroupMenu); + } + else if (GroupMenu->icon().isNull() && !GroupIcon.isNull()) + { + GroupMenu->setIcon(GroupIcon); + } + + d->addActionToMenu(ToggleViewAction, GroupMenu, AlphabeticallySorted); + return GroupMenu->menuAction(); + } + else + { + d->addActionToMenu(ToggleViewAction, d->ViewMenu, AlphabeticallySorted); + return ToggleViewAction; + } +} + + +//============================================================================ +QMenu* CDockManager::viewMenu() const +{ + return d->ViewMenu; +} + + +//============================================================================ +void CDockManager::setViewMenuInsertionOrder(eViewMenuInsertionOrder Order) +{ + d->MenuInsertionOrder = Order; +} + + +//=========================================================================== +bool CDockManager::isRestoringState() const +{ + return d->RestoringState; +} + + +//=========================================================================== +int CDockManager::startDragDistance() +{ + return QApplication::startDragDistance() * 1.5; +} + + +//=========================================================================== +CDockManager::ConfigFlags CDockManager::configFlags() +{ + return StaticConfigFlags; +} + + +//=========================================================================== +void CDockManager::setConfigFlags(const ConfigFlags Flags) +{ + StaticConfigFlags = Flags; +} + + +//=========================================================================== +void CDockManager::setConfigFlag(eConfigFlag Flag, bool On) +{ + internal::setFlag(StaticConfigFlags, Flag, On); +} + +//=========================================================================== +bool CDockManager::testConfigFlag(eConfigFlag Flag) +{ + return configFlags().testFlag(Flag); +} + + +//=========================================================================== +CIconProvider& CDockManager::iconProvider() +{ + static CIconProvider Instance; + return Instance; +} + + +//=========================================================================== +void CDockManager::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget) +{ + if (d->FocusController) + { + d->FocusController->notifyWidgetOrAreaRelocation(DroppedWidget); + } +} + + +//=========================================================================== +void CDockManager::notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget) +{ + if (d->FocusController) + { + d->FocusController->notifyFloatingWidgetDrop(FloatingWidget); + } +} + + +//=========================================================================== +void CDockManager::setDockWidgetFocused(CDockWidget* DockWidget) +{ + if (d->FocusController) + { + d->FocusController->setDockWidgetFocused(DockWidget); + } +} + +//=========================================================================== +void CDockManager::hideManagerAndFloatingWidgets() +{ + hide(); + + d->HiddenFloatingWidgets.clear(); + // Hide updates of floating widgets from user + for (auto FloatingWidget : d->FloatingWidgets) + { + if ( FloatingWidget->isVisible() ) + { + QList VisibleWidgets; + for ( auto dockWidget : FloatingWidget->dockWidgets() ) + { + if ( dockWidget->toggleViewAction()->isChecked() ) + VisibleWidgets.push_back( dockWidget ); + } + + // save as floating widget to be shown when CDockManager will be shown back + d->HiddenFloatingWidgets.push_back( FloatingWidget ); + FloatingWidget->hide(); + + // hidding floating widget automatically marked contained CDockWidgets as hidden + // but they must remain marked as visible as we want them to be restored visible + // when CDockManager will be shown back + for ( auto dockWidget : VisibleWidgets ) + { + dockWidget->toggleViewAction()->setChecked(true); + } + } + } +} + +//=========================================================================== +CDockWidget* CDockManager::focusedDockWidget() const +{ + if (!d->FocusController) + { + return nullptr; + } + else + { + return d->FocusController->focusedDockWidget(); + } +} + +//=========================================================================== +QList CDockManager::splitterSizes(CDockAreaWidget *ContainedArea) const +{ + if (ContainedArea) + { + auto Splitter = internal::findParent(ContainedArea); + if (Splitter) + { + return Splitter->sizes(); + } + } + return QList(); +} + +//=========================================================================== +void CDockManager::setSplitterSizes(CDockAreaWidget *ContainedArea, const QList& sizes) +{ + if (!ContainedArea) + { + return; + } + + auto Splitter = internal::findParent(ContainedArea); + if (Splitter && Splitter->count() == sizes.count()) + { + Splitter->setSizes(sizes); + } +} + + +//=========================================================================== +CDockFocusController* CDockManager::dockFocusController() const +{ + return d->FocusController; +} + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockManager.cpp diff --git a/ads/DockManager.h b/ads/DockManager.h new file mode 100644 index 0000000..7747d23 --- /dev/null +++ b/ads/DockManager.h @@ -0,0 +1,643 @@ +#ifndef DockManagerH +#define DockManagerH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockManager.h +/// \author Uwe Kindler +/// \date 26.02.2017 +/// \brief Declaration of CDockManager class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include "ads_globals.h" +#include "DockContainerWidget.h" +#include "DockWidget.h" +#include "FloatingDockContainer.h" + + +QT_FORWARD_DECLARE_CLASS(QSettings) +QT_FORWARD_DECLARE_CLASS(QMenu) + +namespace ads +{ +struct DockManagerPrivate; +class CFloatingDockContainer; +struct FloatingDockContainerPrivate; +class CDockContainerWidget; +class DockContainerWidgetPrivate; +class CDockOverlay; +class CDockAreaTabBar; +class CDockWidgetTab; +struct DockWidgetTabPrivate; +struct DockAreaWidgetPrivate; +class CIconProvider; +class CDockComponentsFactory; +class CDockFocusController; + +/** + * The central dock manager that maintains the complete docking system. + * With the configuration flags you can globally control the functionality + * of the docking system. The dock manager uses an internal stylesheet to + * style its components like splitters, tabs and buttons. If you want to + * disable this stylesheet because your application uses its own, + * just call the function for settings the stylesheet with an empty + * string. + * \code + * DockManager->setStyleSheet(""); + * \endcode + **/ +class ADS_EXPORT CDockManager : public CDockContainerWidget +{ + Q_OBJECT +private: + DockManagerPrivate* d; ///< private data (pimpl) + friend struct DockManagerPrivate; + friend class CFloatingDockContainer; + friend struct FloatingDockContainerPrivate; + friend class CDockContainerWidget; + friend class DockContainerWidgetPrivate; + friend class CDockAreaTabBar; + friend class CDockWidgetTab; + friend struct DockAreaWidgetPrivate; + friend struct DockWidgetTabPrivate; + friend class CFloatingDragPreview; + friend struct FloatingDragPreviewPrivate; + friend class CDockAreaTitleBar; + + +protected: + /** + * Registers the given floating widget in the internal list of + * floating widgets + */ + void registerFloatingWidget(CFloatingDockContainer* FloatingWidget); + + /** + * Remove the given floating widget from the list of registered floating + * widgets + */ + void removeFloatingWidget(CFloatingDockContainer* FloatingWidget); + + /** + * Registers the given dock container widget + */ + void registerDockContainer(CDockContainerWidget* DockContainer); + + /** + * Remove dock container from the internal list of registered dock + * containers + */ + void removeDockContainer(CDockContainerWidget* DockContainer); + + /** + * Overlay for containers + */ + CDockOverlay* containerOverlay() const; + + /** + * Overlay for dock areas + */ + CDockOverlay* dockAreaOverlay() const; + + + /** + * A container needs to call this function if a widget has been dropped + * into it + */ + void notifyWidgetOrAreaRelocation(QWidget* RelocatedWidget); + + /** + * This function is called, if a floating widget has been dropped into + * an new position. + * When this function is called, all dock widgets of the FloatingWidget + * are already inserted into its new position + */ + void notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget); + + /** + * Show the floating widgets that has been created floating + */ + virtual void showEvent(QShowEvent *event) override; + + /** + * Acces for the internal dock focus controller. + * This function only returns a valid object, if the FocusHighlighting + * flag is set. + */ + CDockFocusController* dockFocusController() const; + + /** + * Restore floating widgets hidden by an earlier call to hideManagerAndFloatingWidgets. + */ + void restoreHiddenFloatingWidgets(); + +public: + using Super = CDockContainerWidget; + + enum eViewMenuInsertionOrder + { + MenuSortedByInsertion, + MenuAlphabeticallySorted + }; + + /** + * These global configuration flags configure some global dock manager + * settings. + * Set the dock manager flags, before you create the dock manager instance. + */ + enum eConfigFlag + { + ActiveTabHasCloseButton = 0x0001, //!< If this flag is set, the active tab in a tab area has a close button + DockAreaHasCloseButton = 0x0002, //!< If the flag is set each dock area has a close button + DockAreaCloseButtonClosesTab = 0x0004,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete dock area + OpaqueSplitterResize = 0x0008, //!< See QSplitter::setOpaqueResize() documentation + XmlAutoFormattingEnabled = 0x0010,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace). + XmlCompressionEnabled = 0x0020,//!< If enabled, the XML output will be compressed and is not human readable anymore + TabCloseButtonIsToolButton = 0x0040,//! If enabled the tab close buttons will be QToolButtons instead of QPushButtons - disabled by default + AllTabsHaveCloseButton = 0x0080, //!< if this flag is set, then all tabs that are closable show a close button + RetainTabSizeWhenCloseButtonHidden = 0x0100, //!< if this flag is set, the space for the close button is reserved even if the close button is not visible + OpaqueUndocking = 0x0200,///< If enabled, the widgets are immediately undocked into floating widgets, if disabled, only a draw preview is undocked and the real undocking is deferred until the mouse is released + DragPreviewIsDynamic = 0x0400,///< If opaque undocking is disabled, this flag defines the behavior of the drag preview window, if this flag is enabled, the preview will be adjusted dynamically to the drop area + DragPreviewShowsContentPixmap = 0x0800,///< If opaque undocking is disabled, the created drag preview window shows a copy of the content of the dock widget / dock are that is dragged + DragPreviewHasWindowFrame = 0x1000,///< If opaque undocking is disabled, then this flag configures if the drag preview is frameless or looks like a real window + AlwaysShowTabs = 0x2000,///< If this option is enabled, the tab of a dock widget is always displayed - even if it is the only visible dock widget in a floating widget. + DockAreaHasUndockButton = 0x4000, //!< If the flag is set each dock area has an undock button + DockAreaHasTabsMenuButton = 0x8000, //!< If the flag is set each dock area has a tabs menu button + DockAreaHideDisabledButtons = 0x10000, //!< If the flag is set disabled dock area buttons will not appear on the toolbar at all (enabling them will bring them back) + DockAreaDynamicTabsMenuButtonVisibility = 0x20000, //!< If the flag is set, the tabs menu button will be shown only when it is required - that means, if the tabs are elided. If the tabs are not elided, it is hidden + FloatingContainerHasWidgetTitle = 0x40000, //!< If set, the Floating Widget window title reflects the title of the current dock widget otherwise it displays application name as window title + FloatingContainerHasWidgetIcon = 0x80000, //!< If set, the Floating Widget icon reflects the icon of the current dock widget otherwise it displays application icon + HideSingleCentralWidgetTitleBar = 0x100000, //!< If there is only one single visible dock widget in the main dock container (the dock manager) and if this flag is set, then the titlebar of this dock widget will be hidden + //!< this only makes sense for non draggable and non floatable widgets and enables the creation of some kind of "central" widget + + FocusHighlighting = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar + EqualSplitOnInsertion = 0x400000, ///!< if enabled, the space is equally distributed to all widgets in a splitter + + FloatingContainerForceNativeTitleBar = 0x800000, //!< Linux only ! Forces all FloatingContainer to use the native title bar. This might break docking for FloatinContainer on some Window Managers (like Kwin/KDE). + //!< If neither this nor FloatingContainerForceCustomTitleBar is set (the default) native titlebars are used except on known bad systems. + //! Users can overwrite this by setting the environment variable ADS_UseNativeTitle to "1" or "0". + FloatingContainerForceQWidgetTitleBar = 0x1000000,//!< Linux only ! Forces all FloatingContainer to use a QWidget based title bar. + //!< If neither this nor FloatingContainerForceNativeTitleBar is set (the default) native titlebars are used except on known bad systems. + //! Users can overwrite this by setting the environment variable ADS_UseNativeTitle to "1" or "0". + MiddleMouseButtonClosesTab = 0x2000000, //! If the flag is set, the user can use the mouse middle button to close the tab under the mouse + + DefaultDockAreaButtons = DockAreaHasCloseButton + | DockAreaHasUndockButton + | DockAreaHasTabsMenuButton,///< default configuration of dock area title bar buttons + + DefaultBaseConfig = DefaultDockAreaButtons + | ActiveTabHasCloseButton + | XmlCompressionEnabled + | FloatingContainerHasWidgetTitle,///< default base configuration settings + + DefaultOpaqueConfig = DefaultBaseConfig + | OpaqueSplitterResize + | OpaqueUndocking, ///< the default configuration with opaque operations - this may cause issues if ActiveX or Qt 3D windows are involved + + DefaultNonOpaqueConfig = DefaultBaseConfig + | DragPreviewShowsContentPixmap, ///< the default configuration for non opaque operations + + NonOpaqueWithWindowFrame = DefaultNonOpaqueConfig + | DragPreviewHasWindowFrame ///< the default configuration for non opaque operations that show a real window with frame + }; + Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag) + + /** + * Default Constructor. + * If the given parent is a QMainWindow, the dock manager sets itself as the + * central widget. + * Before you create any dock widgets, you should properly setup the + * configuration flags via setConfigFlags(). + */ + CDockManager(QWidget* parent = nullptr); + + /** + * Virtual Destructor + */ + virtual ~CDockManager() override; + + /** + * This function returns the global configuration flags + */ + static ConfigFlags configFlags(); + + /** + * Sets the global configuration flags for the whole docking system. + * Call this function before you create the dock manager and before + * your create the first dock widget. + */ + static void setConfigFlags(const ConfigFlags Flags); + + /** + * Set a certain config flag. + * \see setConfigFlags() + */ + static void setConfigFlag(eConfigFlag Flag, bool On = true); + + /** + * Returns true if the given config flag is set + */ + static bool testConfigFlag(eConfigFlag Flag); + + /** + * Returns the global icon provider. + * The icon provider enables the use of custom icons in case using + * styleheets for icons is not an option. + */ + static CIconProvider& iconProvider(); + + /** + * Adds dockwidget into the given area. + * If DockAreaWidget is not null, then the area parameter indicates the area + * into the DockAreaWidget. If DockAreaWidget is null, the Dockwidget will + * be dropped into the container. If you would like to add a dock widget + * tabified, then you need to add it to an existing dock area object + * into the CenterDockWidgetArea. The following code shows this: + * \code + * DockManager->addDockWidget(ads::CenterDockWidgetArea, NewDockWidget, + * ExisitingDockArea); + * \endcode + * \return Returns the dock area widget that contains the new DockWidget + */ + CDockAreaWidget* addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, + CDockAreaWidget* DockAreaWidget = nullptr); + + /** + * Adds dockwidget into the given container. + * This allows you to place the dock widget into a container, even if that + * container does not yet contain a DockAreaWidget. + * \return Returns the dock area widget that contains the new DockWidget + */ + CDockAreaWidget* addDockWidgetToContainer(DockWidgetArea area, CDockWidget* Dockwidget, + CDockContainerWidget* DockContainerWidget); + + /** + * This function will add the given Dockwidget to the given dock area as + * a new tab. + * If no dock area widget exists for the given area identifier, a new + * dock area widget is created. + */ + CDockAreaWidget* addDockWidgetTab(DockWidgetArea area, + CDockWidget* Dockwidget); + + /** + * This function will add the given Dockwidget to the given DockAreaWidget + * as a new tab. + */ + CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget, + CDockAreaWidget* DockAreaWidget); + + /** + * Adds the given DockWidget floating and returns the created + * CFloatingDockContainer instance. + */ + CFloatingDockContainer* addDockWidgetFloating(CDockWidget* Dockwidget); + + /** + * Searches for a registered doc widget with the given ObjectName + * \return Return the found dock widget or nullptr if a dock widget with the + * given name is not registered + */ + CDockWidget* findDockWidget(const QString& ObjectName) const; + + /** + * Remove the given Dock from the dock manager + */ + void removeDockWidget(CDockWidget* Dockwidget); + + /** + * This function returns a readable reference to the internal dock + * widgets map so that it is possible to iterate over all dock widgets + */ + QMap dockWidgetsMap() const; + + /** + * Returns the list of all active and visible dock containers + * Dock containers are the main dock manager and all floating widgets + */ + const QList dockContainers() const; + + /** + * Returns the list of all floating widgets + */ + const QList floatingWidgets() const; + + /** + * This function always return 0 because the main window is always behind + * any floating widget + */ + unsigned int zOrderIndex() const override; + + /** + * Saves the current state of the dockmanger and all its dock widgets + * into the returned QByteArray. + * The XmlMode enables / disables the auto formatting for the XmlStreamWriter. + * If auto formatting is enabled, the output is intended and line wrapped. + * The XmlMode XmlAutoFormattingDisabled is better if you would like to have + * a more compact XML output - i.e. for storage in ini files. + * The version number is stored as part of the data. + * To restore the saved state, pass the return value and version number + * to restoreState(). + * \see restoreState() + */ + QByteArray saveState(int version = 0) const; + + /** + * Restores the state of this dockmanagers dockwidgets. + * The version number is compared with that stored in state. If they do + * not match, the dockmanager's state is left unchanged, and this function + * returns false; otherwise, the state is restored, and this function + * returns true. + * \see saveState() + */ + bool restoreState(const QByteArray &state, int version = 0); + + /** + * Saves the current perspective to the internal list of perspectives. + * A perspective is the current state of the dock manager assigned + * with a certain name. This makes it possible for the user, + * to switch between different perspectives quickly. + * If a perspective with the given name already exists, then + * it will be overwritten with the new state. + */ + void addPerspective(const QString& UniquePrespectiveName); + + /** + * Removes the perspective with the given name from the list of perspectives + */ + void removePerspective(const QString& Name); + + /** + * Removes the given perspectives from the dock manager + */ + void removePerspectives(const QStringList& Names); + + /** + * Returns the names of all available perspectives + */ + QStringList perspectiveNames() const; + + /** + * Saves the perspectives to the given settings file. + */ + void savePerspectives(QSettings& Settings) const; + + /** + * Loads the perspectives from the given settings file + */ + void loadPerspectives(QSettings& Settings); + + /** + * This function returns managers central widget or nullptr if no central widget is set. + */ + CDockWidget* centralWidget() const; + + /** + * Adds dockwidget widget into the central area and marks it as central widget. + * If central widget is set, it will be the only dock widget + * that will resize with the dock container. A central widget if not + * movable, floatable or closable and the titlebar of the central + * dock area is not visible. + * If the given widget could be set as central widget, the function returns + * the created dock area. If the widget could not be set, because there + * is already a central widget, this function returns a nullptr. + * To clear the central widget, pass a nullptr to the function. + * \note Setting a central widget is only possible if no other dock widgets + * have been registered before. That means, this function should be the + * first function that you call before you add other dock widgets. + * \retval != 0 The dock area that contains the central widget + * \retval nullptr Indicates that the given widget can not be set as central + * widget because there is already a central widget. + */ + CDockAreaWidget* setCentralWidget(CDockWidget* widget); + + /** + * Adds a toggle view action to the the internal view menu. + * You can either manage the insertion of the toggle view actions in your + * application or you can add the actions to the internal view menu and + * then simply insert the menu object into your. + * \param[in] ToggleViewAction The action to insert. If no group is provided + * the action is directly inserted into the menu. If a group + * is provided, the action is inserted into the group and the + * group is inserted into the menu if it is not existing yet. + * \param[in] Group This is the text used for the group menu item + * \param[in] GroupIcon The icon used for grouping the workbenches in the + * view menu. I.e. if there is a workbench for each device + * like for spectrometer devices, it is good to group all these + * workbenches under a menu item + * \return If Group is not empty, this function returns the GroupAction + * for this group. If the group is empty, the function returns + * the given ToggleViewAction. + */ + QAction* addToggleViewActionToMenu(QAction* ToggleViewAction, + const QString& Group = QString(), const QIcon& GroupIcon = QIcon()); + + /** + * This function returns the internal view menu. + * To fill the view menu, you can use the addToggleViewActionToMenu() + * function. + */ + QMenu* viewMenu() const; + + /** + * Define the insertion order for toggle view menu items. + * The order defines how the actions are added to the view menu. + * The default insertion order is MenuAlphabeticallySorted to make it + * easier for users to find the menu entry for a certain dock widget. + * You need to call this function befor you insert the first menu item + * into the view menu. + */ + void setViewMenuInsertionOrder(eViewMenuInsertionOrder Order); + + /** + * This function returns true between the restoringState() and + * stateRestored() signals. + */ + bool isRestoringState() const; + + /** + * The distance the user needs to move the mouse with the left button + * hold down before a dock widget start floating + */ + static int startDragDistance(); + + /** + * Helper function to set focus depending on the configuration of the + * FocusStyling flag + */ + template + static void setWidgetFocus(QWidgetPtr widget) + { + if (!CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) + { + return; + } + + widget->setFocus(Qt::OtherFocusReason); + } + +#ifdef Q_OS_LINUX + bool eventFilter(QObject *obj, QEvent *e) override; +#endif + + /** + * Returns the dock widget that has focus style in the ui or a nullptr if + * not dock widget is painted focused. + * If the flag FocusHighlighting is disabled, this function always returns + * nullptr. + */ + CDockWidget* focusedDockWidget() const; + + /** + * Returns the sizes of the splitter that contains the dock area. + * + * If there is no splitter that contains the area, an empty list will be + * returned. + */ + QList splitterSizes(CDockAreaWidget *ContainedArea) const; + + /** + * Update the sizes of a splitter + * Programmatically updates the sizes of a given splitter by calling + * QSplitter::setSizes(). The splitter will be the splitter that + * contains the supplied dock area widget. If there is not splitter + * that contains the dock area, or the sizes supplied does not match + * the number of children of the splitter, this method will have no + * effect. + */ + void setSplitterSizes(CDockAreaWidget *ContainedArea, const QList& sizes); + +public Q_SLOTS: + /** + * Opens the perspective with the given name. + */ + void openPerspective(const QString& PerspectiveName); + + /** + * Request a focus change to the given dock widget. + * This function only has an effect, if the flag CDockManager::FocusStyling + * is enabled + */ + void setDockWidgetFocused(CDockWidget* DockWidget); + + /** + * hide CDockManager and all floating widgets (See Issue #380). Calling regular QWidget::hide() + * hides the CDockManager but not the floating widgets; + */ + void hideManagerAndFloatingWidgets(); + +Q_SIGNALS: + /** + * This signal is emitted if the list of perspectives changed. + * The list of perspectives changes if perspectives are added, removed + * or if the perspective list has been loaded + */ + void perspectiveListChanged(); + + /** + * This signal is emitted if the perspective list has been loaded + */ + void perspectiveListLoaded(); + + /** + * This signal is emitted if perspectives have been removed + */ + void perspectivesRemoved(); + + /** + * This signal is emitted, if the restore function is called, just before + * the dock manager starts restoring the state. + * If this function is called, nothing has changed yet + */ + void restoringState(); + + /** + * This signal is emitted if the state changed in restoreState. + * The signal is emitted if the restoreState() function is called or + * if the openPerspective() function is called + */ + void stateRestored(); + + /** + * This signal is emitted, if the dock manager starts opening a + * perspective. + * Opening a perspective may take more than a second if there are + * many complex widgets. The application may use this signal + * to show some progress indicator or to change the mouse cursor + * into a busy cursor. + */ + void openingPerspective(const QString& PerspectiveName); + + /** + * This signal is emitted if the dock manager finished opening a + * perspective. + */ + void perspectiveOpened(const QString& PerspectiveName); + + /** + * This signal is emitted, if a new floating widget has been created. + * An application can use this signal to e.g. subscribe to events of + * the newly created window. + */ + void floatingWidgetCreated(ads::CFloatingDockContainer* FloatingWidget); + + /** + * This signal is emitted, if a new DockArea has been created. + * An application can use this signal to set custom icons or custom + * tooltips for the DockArea buttons. + */ + void dockAreaCreated(ads::CDockAreaWidget* DockArea); + + /** + * This signal is emitted if a dock widget has been added to this + * dock manager instance. + */ + void dockWidgetAdded(ads::CDockWidget* DockWidget); + + /** + * This signal is emitted just before the given dock widget is removed + * from the dock manager + */ + void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget); + + /** + * This signal is emitted if a dock widget has been removed with the remove + * removeDockWidget() function. + * If this signal is emitted, the dock widget has been removed from the + * docking system but it is not deleted yet. + */ + void dockWidgetRemoved(ads::CDockWidget* DockWidget); + + /** + * This signal is emitted if the focused dock widget changed. + * Both old and now can be nullptr. + * The focused dock widget is the one that is highlighted in the GUI + */ + void focusedDockWidgetChanged(ads::CDockWidget* old, ads::CDockWidget* now); +}; // class DockManager +} // namespace ads + +Q_DECLARE_OPERATORS_FOR_FLAGS(ads::CDockManager::ConfigFlags) +//----------------------------------------------------------------------------- +#endif // DockManagerH diff --git a/ads/DockOverlay.cpp b/ads/DockOverlay.cpp new file mode 100644 index 0000000..c1e07cc --- /dev/null +++ b/ads/DockOverlay.cpp @@ -0,0 +1,839 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockOverlay.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DockAreaWidget.h" +#include "DockAreaTitleBar.h" + +#include + +namespace ads +{ + +/** + * Private data class of CDockOverlay + */ +struct DockOverlayPrivate +{ + CDockOverlay* _this; + DockWidgetAreas AllowedAreas = InvalidDockWidgetArea; + CDockOverlayCross* Cross; + QPointer TargetWidget; + DockWidgetArea LastLocation = InvalidDockWidgetArea; + bool DropPreviewEnabled = true; + CDockOverlay::eMode Mode = CDockOverlay::ModeDockAreaOverlay; + QRect DropAreaRect; + + /** + * Private data constructor + */ + DockOverlayPrivate(CDockOverlay* _public) : _this(_public) {} +}; + +/** + * Private data of CDockOverlayCross class + */ +struct DockOverlayCrossPrivate +{ + CDockOverlayCross* _this; + CDockOverlay::eMode Mode = CDockOverlay::ModeDockAreaOverlay; + CDockOverlay* DockOverlay; + QHash DropIndicatorWidgets; + QGridLayout* GridLayout; + QColor IconColors[5]; + bool UpdateRequired = false; + double LastDevicePixelRatio = 0.1; + + /** + * Private data constructor + */ + DockOverlayCrossPrivate(CDockOverlayCross* _public) : _this(_public) {} + + /** + * + * @param area + * @return + */ + QPoint areaGridPosition(const DockWidgetArea area); + + + /** + * Palette based default icon colors + */ + QColor defaultIconColor(CDockOverlayCross::eIconColor ColorIndex) + { + QPalette pal = _this->palette(); + switch (ColorIndex) + { + case CDockOverlayCross::FrameColor: return pal.color(QPalette::Active, QPalette::Highlight); + case CDockOverlayCross::WindowBackgroundColor: return pal.color(QPalette::Active, QPalette::Base); + case CDockOverlayCross::OverlayColor: + { + QColor Color = pal.color(QPalette::Active, QPalette::Highlight); + Color.setAlpha(64); + return Color; + } + break; + + case CDockOverlayCross::ArrowColor: return pal.color(QPalette::Active, QPalette::Base); + case CDockOverlayCross::ShadowColor: return QColor(0, 0, 0, 64); + default: + return QColor(); + } + + return QColor(); + } + + /** + * Stylehseet based icon colors + */ + QColor iconColor(CDockOverlayCross::eIconColor ColorIndex) + { + QColor Color = IconColors[ColorIndex]; + if (!Color.isValid()) + { + Color = defaultIconColor(ColorIndex); + IconColors[ColorIndex] = Color; + } + return Color; + } + + //============================================================================ + /** + * Helper function that returns the drop indicator width depending on the + * operating system + */ + qreal dropIndicatiorWidth(QLabel* l) const + { + #ifdef Q_OS_LINUX + Q_UNUSED(l) + return 40; + #else + return static_cast(l->fontMetrics().height()) * 3.f; + #endif + } + + + //============================================================================ + QWidget* createDropIndicatorWidget(DockWidgetArea DockWidgetArea, + CDockOverlay::eMode Mode) + { + QLabel* l = new QLabel(); + l->setObjectName("DockWidgetAreaLabel"); + + const qreal metric = dropIndicatiorWidth(l); + const QSizeF size(metric, metric); + + l->setPixmap(createHighDpiDropIndicatorPixmap(size, DockWidgetArea, Mode)); + l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); + l->setAttribute(Qt::WA_TranslucentBackground); + l->setProperty("dockWidgetArea", DockWidgetArea); + return l; + } + + //============================================================================ + void updateDropIndicatorIcon(QWidget* DropIndicatorWidget) + { + QLabel* l = qobject_cast(DropIndicatorWidget); + const qreal metric = dropIndicatiorWidth(l); + const QSizeF size(metric, metric); + + int Area = l->property("dockWidgetArea").toInt(); + l->setPixmap(createHighDpiDropIndicatorPixmap(size, (DockWidgetArea)Area, Mode)); + } + + //============================================================================ + QPixmap createHighDpiDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea, + CDockOverlay::eMode Mode) + { + QColor borderColor = iconColor(CDockOverlayCross::FrameColor); + QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor); + +#if QT_VERSION >= 0x050600 + double DevicePixelRatio = _this->window()->devicePixelRatioF(); +#else + double DevicePixelRatio = _this->window()->devicePixelRatio(); +#endif + QSizeF PixmapSize = size * DevicePixelRatio; + QPixmap pm(PixmapSize.toSize()); + pm.fill(QColor(0, 0, 0, 0)); + + QPainter p(&pm); + QPen pen = p.pen(); + QRectF ShadowRect(pm.rect()); + QRectF baseRect; + baseRect.setSize(ShadowRect.size() * 0.7); + baseRect.moveCenter(ShadowRect.center()); + + // Fill + QColor ShadowColor = iconColor(CDockOverlayCross::ShadowColor); + if (ShadowColor.alpha() == 255) + { + ShadowColor.setAlpha(64); + } + p.fillRect(ShadowRect, ShadowColor); + + // Drop area rect. + p.save(); + QRectF areaRect; + QLineF areaLine; + QRectF nonAreaRect; + switch (DockWidgetArea) + { + case TopDockWidgetArea: + areaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width(), baseRect.height() * .5f); + nonAreaRect = QRectF(baseRect.x(), ShadowRect.height() * .5f, baseRect.width(), baseRect.height() * .5f); + areaLine = QLineF(areaRect.bottomLeft(), areaRect.bottomRight()); + break; + case RightDockWidgetArea: + areaRect = QRectF(ShadowRect.width() * .5f, baseRect.y(), baseRect.width() * .5f, baseRect.height()); + nonAreaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width() * .5f, baseRect.height()); + areaLine = QLineF(areaRect.topLeft(), areaRect.bottomLeft()); + break; + case BottomDockWidgetArea: + areaRect = QRectF(baseRect.x(), ShadowRect.height() * .5f, baseRect.width(), baseRect.height() * .5f); + nonAreaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width(), baseRect.height() * .5f); + areaLine = QLineF(areaRect.topLeft(), areaRect.topRight()); + break; + case LeftDockWidgetArea: + areaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width() * .5f, baseRect.height()); + nonAreaRect = QRectF(ShadowRect.width() * .5f, baseRect.y(), baseRect.width() * .5f, baseRect.height()); + areaLine = QLineF(areaRect.topRight(), areaRect.bottomRight()); + break; + default: + break; + } + + QSizeF baseSize = baseRect.size(); + if (CDockOverlay::ModeContainerOverlay == Mode && DockWidgetArea != CenterDockWidgetArea) + { + baseRect = areaRect; + } + + p.fillRect(baseRect, backgroundColor); + if (areaRect.isValid()) + { + pen = p.pen(); + pen.setColor(borderColor); + QColor Color = iconColor(CDockOverlayCross::OverlayColor); + if (Color.alpha() == 255) + { + Color.setAlpha(64); + } + p.setBrush(Color); + p.setPen(Qt::NoPen); + p.drawRect(areaRect); + + pen = p.pen(); + pen.setWidth(1); + pen.setColor(borderColor); + pen.setStyle(Qt::DashLine); + p.setPen(pen); + p.drawLine(areaLine); + } + p.restore(); + + p.save(); + // Draw outer border + pen = p.pen(); + pen.setColor(borderColor); + pen.setWidth(1); + p.setBrush(Qt::NoBrush); + p.setPen(pen); + p.drawRect(baseRect); + + // draw window title bar + p.setBrush(borderColor); + QRectF FrameRect(baseRect.topLeft(), QSizeF(baseRect.width(), baseSize.height() / 10)); + p.drawRect(FrameRect); + p.restore(); + + // Draw arrow for outer container drop indicators + if (CDockOverlay::ModeContainerOverlay == Mode && DockWidgetArea != CenterDockWidgetArea) + { + QRectF ArrowRect; + ArrowRect.setSize(baseSize); + ArrowRect.setWidth(ArrowRect.width() / 4.6); + ArrowRect.setHeight(ArrowRect.height() / 2); + ArrowRect.moveCenter(QPointF(0, 0)); + QPolygonF Arrow; + Arrow << ArrowRect.topLeft() + << QPointF( ArrowRect.right(), ArrowRect.center().y()) + << ArrowRect.bottomLeft(); + p.setPen(Qt::NoPen); + p.setBrush(iconColor(CDockOverlayCross::ArrowColor)); + p.setRenderHint(QPainter::Antialiasing, true); + p.translate(nonAreaRect.center().x(), nonAreaRect.center().y()); + + switch (DockWidgetArea) + { + case TopDockWidgetArea: + p.rotate(-90); + break; + case RightDockWidgetArea: + break; + case BottomDockWidgetArea: + p.rotate(90); + break; + case LeftDockWidgetArea: + p.rotate(180); + break; + default: + break; + } + + p.drawPolygon(Arrow); + } + + pm.setDevicePixelRatio(DevicePixelRatio); + return pm; + } + +}; + + +//============================================================================ +CDockOverlay::CDockOverlay(QWidget* parent, eMode Mode) : + QFrame(parent), + d(new DockOverlayPrivate(this)) +{ + d->Mode = Mode; + d->Cross = new CDockOverlayCross(this); +#ifdef Q_OS_LINUX + setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); +#else + setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); +#endif + setWindowOpacity(1); + setWindowTitle("DockOverlay"); + setAttribute(Qt::WA_NoSystemBackground); + setAttribute(Qt::WA_TranslucentBackground); + + d->Cross->setVisible(false); + setVisible(false); +} + + +//============================================================================ +CDockOverlay::~CDockOverlay() +{ + delete d; +} + + +//============================================================================ +void CDockOverlay::setAllowedAreas(DockWidgetAreas areas) +{ + if (areas == d->AllowedAreas) + return; + d->AllowedAreas = areas; + d->Cross->reset(); +} + + +//============================================================================ +DockWidgetAreas CDockOverlay::allowedAreas() const +{ + return d->AllowedAreas; +} + + +//============================================================================ +DockWidgetArea CDockOverlay::dropAreaUnderCursor() const +{ + DockWidgetArea Result = d->Cross->cursorLocation(); + if (Result != InvalidDockWidgetArea) + { + return Result; + } + + CDockAreaWidget* DockArea = qobject_cast(d->TargetWidget.data()); + if (!DockArea) + { + return Result; + } + + if (DockArea->allowedAreas().testFlag(CenterDockWidgetArea) + && !DockArea->titleBar()->isHidden() + && DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(QCursor::pos()))) + { + return CenterDockWidgetArea; + } + + return Result; +} + + +//============================================================================ +DockWidgetArea CDockOverlay::visibleDropAreaUnderCursor() const +{ + if (isHidden() || !d->DropPreviewEnabled) + { + return InvalidDockWidgetArea; + } + else + { + return dropAreaUnderCursor(); + } +} + + +//============================================================================ +DockWidgetArea CDockOverlay::showOverlay(QWidget* target) +{ + if (d->TargetWidget == target) + { + // Hint: We could update geometry of overlay here. + DockWidgetArea da = dropAreaUnderCursor(); + if (da != d->LastLocation) + { + repaint(); + d->LastLocation = da; + } + return da; + } + + d->TargetWidget = target; + d->LastLocation = InvalidDockWidgetArea; + + // Move it over the target. + resize(target->size()); + QPoint TopLeft = target->mapToGlobal(target->rect().topLeft()); + move(TopLeft); + show(); + d->Cross->updatePosition(); + d->Cross->updateOverlayIcons(); + return dropAreaUnderCursor(); +} + + +//============================================================================ +void CDockOverlay::hideOverlay() +{ + hide(); + d->TargetWidget.clear(); + d->LastLocation = InvalidDockWidgetArea; + d->DropAreaRect = QRect(); +} + + +//============================================================================ +void CDockOverlay::enableDropPreview(bool Enable) +{ + d->DropPreviewEnabled = Enable; + update(); +} + + +//============================================================================ +bool CDockOverlay::dropPreviewEnabled() const +{ + return d->DropPreviewEnabled; +} + + +//============================================================================ +void CDockOverlay::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + // Draw rect based on location + if (!d->DropPreviewEnabled) + { + d->DropAreaRect = QRect(); + return; + } + + QRect r = rect(); + const DockWidgetArea da = dropAreaUnderCursor(); + double Factor = (CDockOverlay::ModeContainerOverlay == d->Mode) ? + 3 : 2; + + switch (da) + { + case TopDockWidgetArea: r.setHeight(r.height() / Factor); break; + case RightDockWidgetArea: r.setX(r.width() * (1 - 1 / Factor)); break; + case BottomDockWidgetArea: r.setY(r.height() * (1 - 1 / Factor)); break; + case LeftDockWidgetArea: r.setWidth(r.width() / Factor); break; + case CenterDockWidgetArea: r = rect();break; + default: return; + } + QPainter painter(this); + QColor Color = palette().color(QPalette::Active, QPalette::Highlight); + QPen Pen = painter.pen(); + Pen.setColor(Color.darker(120)); + Pen.setStyle(Qt::SolidLine); + Pen.setWidth(1); + Pen.setCosmetic(true); + painter.setPen(Pen); + Color = Color.lighter(130); + Color.setAlpha(64); + painter.setBrush(Color); + painter.drawRect(r.adjusted(0, 0, -1, -1)); + d->DropAreaRect = r; +} + + +//============================================================================ +QRect CDockOverlay::dropOverlayRect() const +{ + return d->DropAreaRect; +} + + +//============================================================================ +void CDockOverlay::showEvent(QShowEvent* e) +{ + d->Cross->show(); + QFrame::showEvent(e); +} + + +//============================================================================ +void CDockOverlay::hideEvent(QHideEvent* e) +{ + d->Cross->hide(); + QFrame::hideEvent(e); +} + + +//============================================================================ +bool CDockOverlay::event(QEvent *e) +{ + bool Result = Super::event(e); + if (e->type() == QEvent::Polish) + { + d->Cross->setupOverlayCross(d->Mode); + } + return Result; +} + + +//============================================================================ +static int areaAlignment(const DockWidgetArea area) +{ + switch (area) + { + case TopDockWidgetArea: return (int) Qt::AlignHCenter | Qt::AlignBottom; + case RightDockWidgetArea: return (int) Qt::AlignLeft | Qt::AlignVCenter; + case BottomDockWidgetArea: return (int) Qt::AlignHCenter | Qt::AlignTop; + case LeftDockWidgetArea: return (int) Qt::AlignRight | Qt::AlignVCenter; + case CenterDockWidgetArea: return (int) Qt::AlignCenter; + default: return Qt::AlignCenter; + } +} + +//============================================================================ +// DockOverlayCrossPrivate +//============================================================================ +QPoint DockOverlayCrossPrivate::areaGridPosition(const DockWidgetArea area) +{ + if (CDockOverlay::ModeDockAreaOverlay == Mode) + { + switch (area) + { + case TopDockWidgetArea: return QPoint(1, 2); + case RightDockWidgetArea: return QPoint(2, 3); + case BottomDockWidgetArea: return QPoint(3, 2); + case LeftDockWidgetArea: return QPoint(2, 1); + case CenterDockWidgetArea: return QPoint(2, 2); + default: return QPoint(); + } + } + else + { + switch (area) + { + case TopDockWidgetArea: return QPoint(0, 2); + case RightDockWidgetArea: return QPoint(2, 4); + case BottomDockWidgetArea: return QPoint(4, 2); + case LeftDockWidgetArea: return QPoint(2, 0); + case CenterDockWidgetArea: return QPoint(2, 2); + default: return QPoint(); + } + } +} + + +//============================================================================ +CDockOverlayCross::CDockOverlayCross(CDockOverlay* overlay) : + QWidget(overlay->parentWidget()), + d(new DockOverlayCrossPrivate(this)) +{ + d->DockOverlay = overlay; +#ifdef Q_OS_LINUX + setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); +#else + setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); +#endif + setWindowTitle("DockOverlayCross"); + setAttribute(Qt::WA_TranslucentBackground); + + d->GridLayout = new QGridLayout(); + d->GridLayout->setSpacing(0); + setLayout(d->GridLayout); +} + + +//============================================================================ +CDockOverlayCross::~CDockOverlayCross() +{ + delete d; +} + + +//============================================================================ +void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode) +{ + d->Mode = Mode; + + QHash areaWidgets; + areaWidgets.insert(TopDockWidgetArea, d->createDropIndicatorWidget(TopDockWidgetArea, Mode)); + areaWidgets.insert(RightDockWidgetArea, d->createDropIndicatorWidget(RightDockWidgetArea, Mode)); + areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode)); + areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode)); + areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode)); +#if QT_VERSION >= 0x050600 + d->LastDevicePixelRatio = devicePixelRatioF(); +#else + d->LastDevicePixelRatio = devicePixelRatio(); +#endif + setAreaWidgets(areaWidgets); + d->UpdateRequired = false; +} + + +//============================================================================ +void CDockOverlayCross::updateOverlayIcons() +{ + if (windowHandle()->devicePixelRatio() == d->LastDevicePixelRatio) + { + return; + } + + for (auto Widget : d->DropIndicatorWidgets) + { + d->updateDropIndicatorIcon(Widget); + } +#if QT_VERSION >= 0x050600 + d->LastDevicePixelRatio = devicePixelRatioF(); +#else + d->LastDevicePixelRatio = devicePixelRatio(); +#endif +} + + +//============================================================================ +void CDockOverlayCross::setIconColor(eIconColor ColorIndex, const QColor& Color) +{ + d->IconColors[ColorIndex] = Color; + d->UpdateRequired = true; +} + + +//============================================================================ +QColor CDockOverlayCross::iconColor(eIconColor ColorIndex) const +{ + return d->IconColors[ColorIndex]; +} + + +//============================================================================ +void CDockOverlayCross::setAreaWidgets(const QHash& widgets) +{ + // Delete old widgets. + QMutableHashIterator i(d->DropIndicatorWidgets); + while (i.hasNext()) + { + i.next(); + QWidget* widget = i.value(); + d->GridLayout->removeWidget(widget); + delete widget; + i.remove(); + } + + // Insert new widgets into grid. + d->DropIndicatorWidgets = widgets; + QHashIterator i2(d->DropIndicatorWidgets); + while (i2.hasNext()) + { + i2.next(); + const DockWidgetArea area = i2.key(); + QWidget* widget = i2.value(); + QPoint p = d->areaGridPosition(area); + d->GridLayout->addWidget(widget, p.x(), p.y(), (Qt::Alignment) areaAlignment(area)); + } + + if (CDockOverlay::ModeDockAreaOverlay == d->Mode) + { + d->GridLayout->setContentsMargins(0, 0, 0, 0); + d->GridLayout->setRowStretch(0, 1); + d->GridLayout->setRowStretch(1, 0); + d->GridLayout->setRowStretch(2, 0); + d->GridLayout->setRowStretch(3, 0); + d->GridLayout->setRowStretch(4, 1); + + d->GridLayout->setColumnStretch(0, 1); + d->GridLayout->setColumnStretch(1, 0); + d->GridLayout->setColumnStretch(2, 0); + d->GridLayout->setColumnStretch(3, 0); + d->GridLayout->setColumnStretch(4, 1); + } + else + { + d->GridLayout->setContentsMargins(4, 4, 4, 4); + d->GridLayout->setRowStretch(0, 0); + d->GridLayout->setRowStretch(1, 1); + d->GridLayout->setRowStretch(2, 1); + d->GridLayout->setRowStretch(3, 1); + d->GridLayout->setRowStretch(4, 0); + + d->GridLayout->setColumnStretch(0, 0); + d->GridLayout->setColumnStretch(1, 1); + d->GridLayout->setColumnStretch(2, 1); + d->GridLayout->setColumnStretch(3, 1); + d->GridLayout->setColumnStretch(4, 0); + } + reset(); +} + + +//============================================================================ +DockWidgetArea CDockOverlayCross::cursorLocation() const +{ + const QPoint pos = mapFromGlobal(QCursor::pos()); + QHashIterator i(d->DropIndicatorWidgets); + while (i.hasNext()) + { + i.next(); + if (d->DockOverlay->allowedAreas().testFlag(i.key()) + && i.value() + && i.value()->isVisible() + && i.value()->geometry().contains(pos)) + { + return i.key(); + } + } + return InvalidDockWidgetArea; +} + + +//============================================================================ +void CDockOverlayCross::showEvent(QShowEvent*) +{ + if (d->UpdateRequired) + { + setupOverlayCross(d->Mode); + } + this->updatePosition(); +} + + +//============================================================================ +void CDockOverlayCross::updatePosition() +{ + resize(d->DockOverlay->size()); + QPoint TopLeft = d->DockOverlay->pos(); + QPoint Offest((this->width() - d->DockOverlay->width()) / 2, + (this->height() - d->DockOverlay->height()) / 2); + QPoint CrossTopLeft = TopLeft - Offest; + move(CrossTopLeft); +} + + +//============================================================================ +void CDockOverlayCross::reset() +{ + QList allAreas; + allAreas << TopDockWidgetArea << RightDockWidgetArea + << BottomDockWidgetArea << LeftDockWidgetArea << CenterDockWidgetArea; + const DockWidgetAreas allowedAreas = d->DockOverlay->allowedAreas(); + + // Update visibility of area widgets based on allowedAreas. + for (int i = 0; i < allAreas.count(); ++i) + { + QPoint p = d->areaGridPosition(allAreas.at(i)); + QLayoutItem* item = d->GridLayout->itemAtPosition(p.x(), p.y()); + QWidget* w = nullptr; + if (item && (w = item->widget()) != nullptr) + { + w->setVisible(allowedAreas.testFlag(allAreas.at(i))); + } + } +} + + +//============================================================================ +void CDockOverlayCross::setIconColors(const QString& Colors) +{ + static const QMap ColorCompenentStringMap{ + {"Frame", CDockOverlayCross::FrameColor}, + {"Background", CDockOverlayCross::WindowBackgroundColor}, + {"Overlay", CDockOverlayCross::OverlayColor}, + {"Arrow", CDockOverlayCross::ArrowColor}, + {"Shadow", CDockOverlayCross::ShadowColor}}; + +#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) + auto SkipEmptyParts = QString::SkipEmptyParts; +#else + auto SkipEmptyParts = Qt::SkipEmptyParts; +#endif + auto ColorList = Colors.split(' ', SkipEmptyParts); + for (const auto& ColorListEntry : ColorList) + { + auto ComponentColor = ColorListEntry.split('=', SkipEmptyParts); + int Component = ColorCompenentStringMap.value(ComponentColor[0], -1); + if (Component < 0) + { + continue; + } + d->IconColors[Component] = QColor(ComponentColor[1]); + } + + d->UpdateRequired = true; +} + +//============================================================================ +QString CDockOverlayCross::iconColors() const +{ + return QString(); +} + + + +} // namespace ads +//---------------------------------------------------------------------------- + diff --git a/ads/DockOverlay.h b/ads/DockOverlay.h new file mode 100644 index 0000000..4a70990 --- /dev/null +++ b/ads/DockOverlay.h @@ -0,0 +1,264 @@ +#ifndef DockOverlayH +#define DockOverlayH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include +#include +#include + +#include "ads_globals.h" + +QT_FORWARD_DECLARE_CLASS(QGridLayout) + +namespace ads +{ +struct DockOverlayPrivate; +class CDockOverlayCross; + +/*! + * DockOverlay paints a translucent rectangle over another widget. The geometry + * of the rectangle is based on the mouse location. + */ +class ADS_EXPORT CDockOverlay : public QFrame +{ + Q_OBJECT +private: + DockOverlayPrivate* d; //< private data class + friend struct DockOverlayPrivate; + friend class DockOverlayCross; + +public: + using Super = QFrame; + + enum eMode + { + ModeDockAreaOverlay, + ModeContainerOverlay + }; + + /** + * Creates a dock overlay + */ + CDockOverlay(QWidget* parent, eMode Mode = ModeDockAreaOverlay); + + /** + * Virtual destructor + */ + virtual ~CDockOverlay(); + + /** + * Configures the areas that are allowed for docking + */ + void setAllowedAreas(DockWidgetAreas areas); + + /** + * Returns flags with all allowed drop areas + */ + DockWidgetAreas allowedAreas() const; + + /** + * Returns the drop area under the current cursor location + */ + DockWidgetArea dropAreaUnderCursor() const; + + /** + * This function returns the same like dropAreaUnderCursor() if this + * overlay is not hidden and if drop preview is enabled and returns + * InvalidDockWidgetArea if it is hidden or drop preview is disabled. + */ + DockWidgetArea visibleDropAreaUnderCursor() const; + + /** + * Show the drop overly for the given target widget + */ + DockWidgetArea showOverlay(QWidget* target); + + /** + * Hides the overlay + */ + void hideOverlay(); + + /** + * Enables / disables the semi transparent overlay rectangle that represents + * the future area of the dropped widget + */ + void enableDropPreview(bool Enable); + + /** + * Returns true if drop preview is enabled + */ + bool dropPreviewEnabled() const; + + /** + * The drop overlay rectangle for the target area + */ + QRect dropOverlayRect() const; + + /** + * Handle polish events + */ + virtual bool event(QEvent *e) override; + +protected: + virtual void paintEvent(QPaintEvent *e) override; + virtual void showEvent(QShowEvent* e) override; + virtual void hideEvent(QHideEvent* e) override; +}; + + +struct DockOverlayCrossPrivate; +/*! + * DockOverlayCross shows a cross with 5 different drop area possibilities. + * I could have handled everything inside DockOverlay, but because of some + * styling issues it's better to have a separate class for the cross. + * You can style the cross icon using the property system. + * \code + * ads--CDockOverlayCross + { + qproperty-iconFrameColor: palette(highlight); + qproperty-iconBackgroundColor: palette(base); + qproperty-iconOverlayColor: palette(highlight); + qproperty-iconArrowColor: rgb(227, 227, 227); + qproperty-iconShadowColor: rgb(0, 0, 0); + } + * \endcode + * Or you can use the iconColors property to pass in AARRGGBB values as + * hex string like shown in the example below. + * \code + * ads--CDockOverlayCross + * { + * qproperty-iconColors: "Frame=#ff3d3d3d Background=#ff929292 Overlay=#1f3d3d3d Arrow=#ffb4b4b4 Shadow=#40474747"; + * } + * \endcode + */ +class CDockOverlayCross : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QString iconColors READ iconColors WRITE setIconColors) + Q_PROPERTY(QColor iconFrameColor READ iconColor WRITE setIconFrameColor) + Q_PROPERTY(QColor iconBackgroundColor READ iconColor WRITE setIconBackgroundColor) + Q_PROPERTY(QColor iconOverlayColor READ iconColor WRITE setIconOverlayColor) + Q_PROPERTY(QColor iconArrowColor READ iconColor WRITE setIconArrowColor) + Q_PROPERTY(QColor iconShadowColor READ iconColor WRITE setIconShadowColor) + +public: + enum eIconColor + { + FrameColor,///< the color of the frame of the small window icon + WindowBackgroundColor,///< the background color of the small window in the icon + OverlayColor,///< the color that shows the overlay (the dock side) in the icon + ArrowColor,///< the arrow that points into the direction + ShadowColor///< the color of the shadow rectangle that is painted below the icons + }; + +private: + DockOverlayCrossPrivate* d; + friend struct DockOverlayCrossPrivate; + friend class CDockOverlay; + +protected: + /** + * This function returns an empty string and is only here to silence + * moc + */ + QString iconColors() const; + + /** + * This is a dummy function for the property system + */ + QColor iconColor() const {return QColor();} + void setIconFrameColor(const QColor& Color) {setIconColor(FrameColor, Color);} + void setIconBackgroundColor(const QColor& Color) {setIconColor(WindowBackgroundColor, Color);} + void setIconOverlayColor(const QColor& Color) {setIconColor(OverlayColor, Color);} + void setIconArrowColor(const QColor& Color) {setIconColor(ArrowColor, Color);} + void setIconShadowColor(const QColor& Color) {setIconColor(ShadowColor, Color);} + +public: + /** + * Creates an overlay cross for the given overlay + */ + CDockOverlayCross(CDockOverlay* overlay); + + /** + * Virtual destructor + */ + virtual ~CDockOverlayCross(); + + /** + * Sets a certain icon color + */ + void setIconColor(eIconColor ColorIndex, const QColor& Color); + + /** + * Returns the icon color given by ColorIndex + */ + QColor iconColor(eIconColor ColorIndex) const; + + /** + * Returns the dock widget area depending on the current cursor location. + * The function checks, if the mouse cursor is inside of any drop indicator + * widget and returns the corresponding DockWidgetArea. + */ + DockWidgetArea cursorLocation() const; + + /** + * Sets up the overlay cross for the given overlay mode + */ + void setupOverlayCross(CDockOverlay::eMode Mode); + + /** + * Recreates the overlay icons. + */ + void updateOverlayIcons(); + + /** + * Resets and updates the + */ + void reset(); + + /** + * Updates the current position + */ + void updatePosition(); + + /** + * A string with all icon colors to set. + * You can use this property to style the overly icon via CSS stylesheet + * file. The colors are set via a color identifier and a hex AARRGGBB value like + * in the example below. + * \code + * ads--CDockOverlayCross + * { + * qproperty-iconColors: "Frame=#ff3d3d3d Background=#ff929292 Overlay=#1f3d3d3d Arrow=#ffb4b4b4 Shadow=#40474747"; + * } + */ + void setIconColors(const QString& Colors); + +protected: + virtual void showEvent(QShowEvent* e) override; + void setAreaWidgets(const QHash& widgets); +}; // CDockOverlayCross + +} // namespace ads +#endif // DockOverlayH diff --git a/ads/DockSplitter.cpp b/ads/DockSplitter.cpp new file mode 100644 index 0000000..2aba642 --- /dev/null +++ b/ads/DockSplitter.cpp @@ -0,0 +1,122 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockSplitter.cpp +/// \author Uwe Kindler +/// \date 24.03.2017 +/// \brief Implementation of CDockSplitter +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockSplitter.h" + +#include +#include +#include +#include "DockAreaWidget.h" + +namespace ads +{ +/** + * Private dock splitter data + */ +struct DockSplitterPrivate +{ + CDockSplitter* _this; + int VisibleContentCount = 0; + + DockSplitterPrivate(CDockSplitter* _public) : _this(_public) {} +}; + +//============================================================================ +CDockSplitter::CDockSplitter(QWidget *parent) + : QSplitter(parent), + d(new DockSplitterPrivate(this)) +{ + setProperty("ads-splitter", QVariant(true)); + setChildrenCollapsible(false); +} + + +//============================================================================ +CDockSplitter::CDockSplitter(Qt::Orientation orientation, QWidget *parent) + : QSplitter(orientation, parent), + d(new DockSplitterPrivate(this)) +{ + +} + +//============================================================================ +CDockSplitter::~CDockSplitter() +{ + ADS_PRINT("~CDockSplitter"); + delete d; +} + + +//============================================================================ +bool CDockSplitter::hasVisibleContent() const +{ + // TODO Cache or precalculate this to speed up + for (int i = 0; i < count(); ++i) + { + if (!widget(i)->isHidden()) + { + return true; + } + } + + return false; +} + + +//============================================================================ +QWidget* CDockSplitter::firstWidget() const +{ + return (count() > 0) ? widget(0) : nullptr; +} + + +//============================================================================ +QWidget* CDockSplitter::lastWidget() const +{ + return (count() > 0) ? widget(count() - 1) : nullptr; +} + +//============================================================================ +bool CDockSplitter::isResizingWithContainer() const +{ + for (auto area : findChildren()) + { + if(area->isCentralWidgetArea()) + { + return true; + } + } + + return false; +} + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockSplitter.cpp diff --git a/ads/DockSplitter.h b/ads/DockSplitter.h new file mode 100644 index 0000000..0b8eea1 --- /dev/null +++ b/ads/DockSplitter.h @@ -0,0 +1,84 @@ +#ifndef DockSplitterH +#define DockSplitterH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockSplitter.h +/// \author Uwe Kindler +/// \date 24.03.2017 +/// \brief Declaration of CDockSplitter +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include "ads_globals.h" + +namespace ads +{ +struct DockSplitterPrivate; + +/** + * Splitter used internally instead of QSplitter with some additional + * fuctionality. + */ +class ADS_EXPORT CDockSplitter : public QSplitter +{ + Q_OBJECT +private: + DockSplitterPrivate* d; + friend struct DockSplitterPrivate; + +public: + CDockSplitter(QWidget *parent = Q_NULLPTR); + CDockSplitter(Qt::Orientation orientation, QWidget *parent = Q_NULLPTR); + + /** + * Prints debug info + */ + virtual ~CDockSplitter(); + + /** + * Returns true, if any of the internal widgets is visible + */ + bool hasVisibleContent() const; + + /** + * Returns first widget or nullptr if splitter is empty + */ + QWidget* firstWidget() const; + + /** + * Returns last widget of nullptr is splitter is empty + */ + QWidget* lastWidget() const; + + /** + * Returns true if the splitter contains central widget of dock manager. + */ + bool isResizingWithContainer() const; +}; // class CDockSplitter + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // DockSplitterH diff --git a/ads/DockWidget.cpp b/ads/DockWidget.cpp new file mode 100644 index 0000000..4a19f16 --- /dev/null +++ b/ads/DockWidget.cpp @@ -0,0 +1,1071 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockWidget.cpp +/// \author Uwe Kindler +/// \date 26.02.2017 +/// \brief Implementation of CDockWidget class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockWidgetTab.h" +#include "DockWidget.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "DockContainerWidget.h" +#include "DockAreaWidget.h" +#include "DockManager.h" +#include "FloatingDockContainer.h" +#include "DockSplitter.h" +#include "DockComponentsFactory.h" +#include "ads_globals.h" + + +namespace ads +{ +/** + * Private data class of CDockWidget class (pimpl) + */ +struct DockWidgetPrivate +{ + struct WidgetFactory + { + CDockWidget::FactoryFunc createWidget; + CDockWidget::eInsertMode insertMode; + }; + + CDockWidget* _this = nullptr; + QBoxLayout* Layout = nullptr; + QWidget* Widget = nullptr; + CDockWidgetTab* TabWidget = nullptr; + CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures; + CDockManager* DockManager = nullptr; + CDockAreaWidget* DockArea = nullptr; + QAction* ToggleViewAction = nullptr; + bool Closed = false; + QScrollArea* ScrollArea = nullptr; + QToolBar* ToolBar = nullptr; + Qt::ToolButtonStyle ToolBarStyleDocked = Qt::ToolButtonIconOnly; + Qt::ToolButtonStyle ToolBarStyleFloating = Qt::ToolButtonTextUnderIcon; + QSize ToolBarIconSizeDocked = QSize(16, 16); + QSize ToolBarIconSizeFloating = QSize(24, 24); + bool IsFloatingTopLevel = false; + QList TitleBarActions; + CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget; + WidgetFactory* Factory = nullptr; + + /** + * Private data constructor + */ + DockWidgetPrivate(CDockWidget* _public); + + /** + * Show dock widget + */ + void showDockWidget(); + + /** + * Hide dock widget. + */ + void hideDockWidget(); + + /** + * Hides a dock area if all dock widgets in the area are closed. + * This function updates the current selected tab and hides the parent + * dock area if it is empty + */ + void updateParentDockArea(); + + /** + * Setup the top tool bar + */ + void setupToolBar(); + + /** + * Setup the main scroll area + */ + void setupScrollArea(); + + /** + * Creates the content widget with the registered widget factory and + * returns true on success. + */ + bool createWidgetFromFactory(); +}; +// struct DockWidgetPrivate + +//============================================================================ +DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockWidgetPrivate::showDockWidget() +{ + if (!Widget) + { + if (!createWidgetFromFactory()) + { + Q_ASSERT(!Features.testFlag(CDockWidget::DeleteContentOnClose) + && "DeleteContentOnClose flag was set, but the widget " + "factory is missing or it doesn't return a valid QWidget."); + return; + } + } + + if (!DockArea) + { + CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(_this); + // We use the size hint of the content widget to provide a good + // initial size + FloatingWidget->resize(Widget ? Widget->sizeHint() : _this->sizeHint()); + TabWidget->show(); + FloatingWidget->show(); + } + else + { + DockArea->setCurrentDockWidget(_this); + DockArea->toggleView(true); + TabWidget->show(); + QSplitter* Splitter = internal::findParent(DockArea); + while (Splitter && !Splitter->isVisible()) + { + Splitter->show(); + Splitter = internal::findParent(Splitter); + } + + CDockContainerWidget* Container = DockArea->dockContainer(); + if (Container->isFloating()) + { + CFloatingDockContainer* FloatingWidget = internal::findParent< + CFloatingDockContainer*>(Container); + FloatingWidget->show(); + } + } +} + + +//============================================================================ +void DockWidgetPrivate::hideDockWidget() +{ + TabWidget->hide(); + updateParentDockArea(); + + if (Features.testFlag(CDockWidget::DeleteContentOnClose)) + { + Widget->deleteLater(); + Widget = nullptr; + } +} + + +//============================================================================ +void DockWidgetPrivate::updateParentDockArea() +{ + if (!DockArea) + { + return; + } + + // we don't need to change the current tab if the + // current dock widget is not the one being closed + if (DockArea->currentDockWidget() != _this){ + return; + } + + auto NextDockWidget = DockArea->nextOpenDockWidget(_this); + if (NextDockWidget) + { + DockArea->setCurrentDockWidget(NextDockWidget); + } + else + { + DockArea->hideAreaWithNoVisibleContent(); + } +} + + +//============================================================================ +void DockWidgetPrivate::setupToolBar() +{ + ToolBar = new QToolBar(_this); + ToolBar->setObjectName("dockWidgetToolBar"); + Layout->insertWidget(0, ToolBar); + ToolBar->setIconSize(QSize(16, 16)); + ToolBar->toggleViewAction()->setEnabled(false); + ToolBar->toggleViewAction()->setVisible(false); + _this->connect(_this, SIGNAL(topLevelChanged(bool)), SLOT(setToolbarFloatingStyle(bool))); +} + + + +//============================================================================ +void DockWidgetPrivate::setupScrollArea() +{ + ScrollArea = new QScrollArea(_this); + ScrollArea->setObjectName("dockWidgetScrollArea"); + ScrollArea->setWidgetResizable(true); + Layout->addWidget(ScrollArea); +} + + +//============================================================================ +bool DockWidgetPrivate::createWidgetFromFactory() +{ + if (!Features.testFlag(CDockWidget::DeleteContentOnClose)) + { + return false; + } + + if (!Factory) + { + return false; + } + + QWidget* w = Factory->createWidget(_this); + if (!w) + { + return false; + } + + _this->setWidget(w, Factory->insertMode); + return true; +} + + +//============================================================================ +CDockWidget::CDockWidget(const QString &title, QWidget *parent) : + QFrame(parent), + d(new DockWidgetPrivate(this)) +{ + d->Layout = new QBoxLayout(QBoxLayout::TopToBottom); + d->Layout->setContentsMargins(0, 0, 0, 0); + d->Layout->setSpacing(0); + setLayout(d->Layout); + setWindowTitle(title); + setObjectName(title); + + d->TabWidget = componentsFactory()->createDockWidgetTab(this); + d->ToggleViewAction = new QAction(title, this); + d->ToggleViewAction->setCheckable(true); + connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this, + SLOT(toggleView(bool))); + setToolbarFloatingStyle(false); + + if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) + { + setFocusPolicy(Qt::ClickFocus); + } +} + +//============================================================================ +CDockWidget::~CDockWidget() +{ + ADS_PRINT("~CDockWidget()"); + delete d; +} + + +//============================================================================ +void CDockWidget::setToggleViewActionChecked(bool Checked) +{ + QAction* Action = d->ToggleViewAction; + Action->blockSignals(true); + Action->setChecked(Checked); + Action->blockSignals(false); +} + + +//============================================================================ +void CDockWidget::setWidget(QWidget* widget, eInsertMode InsertMode) +{ + if (d->Widget) + { + takeWidget(); + } + + auto ScrollAreaWidget = qobject_cast(widget); + if (ScrollAreaWidget || ForceNoScrollArea == InsertMode) + { + d->Layout->addWidget(widget); + if (ScrollAreaWidget && ScrollAreaWidget->viewport()) + { + ScrollAreaWidget->viewport()->setProperty("dockWidgetContent", true); + } + } + else + { + d->setupScrollArea(); + d->ScrollArea->setWidget(widget); + } + + d->Widget = widget; + d->Widget->setProperty("dockWidgetContent", true); +} + +//============================================================================ +void CDockWidget::setWidgetFactory(FactoryFunc createWidget, eInsertMode insertMode) +{ + if (d->Factory) + { + delete d->Factory; + } + + d->Factory = new DockWidgetPrivate::WidgetFactory { createWidget, insertMode }; +} + + +//============================================================================ +QWidget* CDockWidget::takeWidget() +{ + QWidget* w = nullptr; + if (d->ScrollArea) + { + d->Layout->removeWidget(d->ScrollArea); + w = d->ScrollArea->takeWidget(); + delete d->ScrollArea; + d->ScrollArea = nullptr; + d->Widget = nullptr; + } + else if (d->Widget) + { + d->Layout->removeWidget(d->Widget); + w = d->Widget; + d->Widget = nullptr; + } + + if (w) + { + w->setParent(nullptr); + } + return w; +} + + +//============================================================================ +QWidget* CDockWidget::widget() const +{ + return d->Widget; +} + + +//============================================================================ +CDockWidgetTab* CDockWidget::tabWidget() const +{ + return d->TabWidget; +} + + +//============================================================================ +void CDockWidget::setFeatures(DockWidgetFeatures features) +{ + if (d->Features == features) + { + return; + } + d->Features = features; + Q_EMIT featuresChanged(d->Features); + d->TabWidget->onDockWidgetFeaturesChanged(); + if(CDockAreaWidget* DockArea = dockAreaWidget()) + DockArea->onDockWidgetFeaturesChanged(); +} + + +//============================================================================ +void CDockWidget::setFeature(DockWidgetFeature flag, bool on) +{ + auto Features = features(); + internal::setFlag(Features, flag, on); + setFeatures(Features); +} + + +//============================================================================ +CDockWidget::DockWidgetFeatures CDockWidget::features() const +{ + return d->Features; +} + + +//============================================================================ +CDockManager* CDockWidget::dockManager() const +{ + return d->DockManager; +} + + +//============================================================================ +void CDockWidget::setDockManager(CDockManager* DockManager) +{ + d->DockManager = DockManager; +} + + +//============================================================================ +CDockContainerWidget* CDockWidget::dockContainer() const +{ + if (d->DockArea) + { + return d->DockArea->dockContainer(); + } + else + { + return 0; + } +} + + +//============================================================================ +CFloatingDockContainer* CDockWidget::floatingDockContainer() const +{ + auto DockContainer = dockContainer(); + return DockContainer ? DockContainer->floatingWidget() : nullptr; +} + + +//============================================================================ +CDockAreaWidget* CDockWidget::dockAreaWidget() const +{ + return d->DockArea; +} + + +//============================================================================ +bool CDockWidget::isFloating() const +{ + if (!isInFloatingContainer()) + { + return false; + } + + return dockContainer()->topLevelDockWidget() == this; +} + + +//============================================================================ +bool CDockWidget::isInFloatingContainer() const +{ + auto Container = dockContainer(); + if (!Container) + { + return false; + } + + if (!Container->isFloating()) + { + return false; + } + + return true; +} + + +//============================================================================ +bool CDockWidget::isClosed() const +{ + return d->Closed; +} + + +//============================================================================ +QAction* CDockWidget::toggleViewAction() const +{ + return d->ToggleViewAction; +} + + +//============================================================================ +void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode) +{ + if (ActionModeToggle == Mode) + { + d->ToggleViewAction->setCheckable(true); + d->ToggleViewAction->setIcon(QIcon()); + } + else + { + d->ToggleViewAction->setCheckable(false); + d->ToggleViewAction->setIcon(d->TabWidget->icon()); + } +} + + +//============================================================================ +void CDockWidget::setMinimumSizeHintMode(eMinimumSizeHintMode Mode) +{ + d->MinimumSizeHintMode = Mode; +} + + +//============================================================================ +bool CDockWidget::isCentralWidget() const +{ + return dockManager()->centralWidget() == this; +} + + +//============================================================================ +void CDockWidget::toggleView(bool Open) +{ + // If the toggle view action mode is ActionModeShow, then Open is always + // true if the sender is the toggle view action + QAction* Sender = qobject_cast(sender()); + if (Sender == d->ToggleViewAction && !d->ToggleViewAction->isCheckable()) + { + Open = true; + } + + // If the dock widget state is different, then we really need to toggle + // the state. If we are in the right state, then we simply make this + // dock widget the current dock widget + if (d->Closed != !Open) + { + toggleViewInternal(Open); + } + else if (Open && d->DockArea) + { + raise(); + } +} + + +//============================================================================ +void CDockWidget::toggleViewInternal(bool Open) +{ + CDockContainerWidget* DockContainer = dockContainer(); + CDockWidget* TopLevelDockWidgetBefore = DockContainer + ? DockContainer->topLevelDockWidget() : nullptr; + + if (Open) + { + d->showDockWidget(); + } + else + { + d->hideDockWidget(); + } + d->Closed = !Open; + d->ToggleViewAction->blockSignals(true); + d->ToggleViewAction->setChecked(Open); + d->ToggleViewAction->blockSignals(false); + if (d->DockArea) + { + d->DockArea->toggleDockWidgetView(this, Open); + } + + if (Open && TopLevelDockWidgetBefore) + { + CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidgetBefore, false); + } + + // Here we need to call the dockContainer() function again, because if + // this dock widget was unassigned before the call to showDockWidget() then + // it has a dock container now + DockContainer = dockContainer(); + CDockWidget* TopLevelDockWidgetAfter = DockContainer + ? DockContainer->topLevelDockWidget() : nullptr; + CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidgetAfter, true); + CFloatingDockContainer* FloatingContainer = DockContainer + ? DockContainer->floatingWidget() : nullptr; + if (FloatingContainer) + { + FloatingContainer->updateWindowTitle(); + } + + if (!Open) + { + Q_EMIT closed(); + } + Q_EMIT viewToggled(Open); +} + + +//============================================================================ +void CDockWidget::setDockArea(CDockAreaWidget* DockArea) +{ + d->DockArea = DockArea; + d->ToggleViewAction->setChecked(DockArea != nullptr && !this->isClosed()); + setParent(DockArea); +} + + +//============================================================================ +void CDockWidget::saveState(QXmlStreamWriter& s) const +{ + s.writeStartElement("Widget"); + s.writeAttribute("Name", objectName()); + s.writeAttribute("Closed", QString::number(d->Closed ? 1 : 0)); + s.writeEndElement(); +} + + +//============================================================================ +void CDockWidget::flagAsUnassigned() +{ + d->Closed = true; + setParent(d->DockManager); + setVisible(false); + setDockArea(nullptr); + tabWidget()->setParent(this); +} + + +//============================================================================ +bool CDockWidget::event(QEvent *e) +{ + switch (e->type()) + { + case QEvent::Hide: + Q_EMIT visibilityChanged(false); + break; + + case QEvent::Show: + Q_EMIT visibilityChanged(geometry().right() >= 0 && geometry().bottom() >= 0); + break; + + case QEvent::WindowTitleChange : + { + const auto title = windowTitle(); + if (d->TabWidget) + { + d->TabWidget->setText(title); + } + if (d->ToggleViewAction) + { + d->ToggleViewAction->setText(title); + } + if (d->DockArea) + { + d->DockArea->markTitleBarMenuOutdated();//update tabs menu + } + + auto FloatingWidget = floatingDockContainer(); + if (FloatingWidget) + { + FloatingWidget->updateWindowTitle(); + } + Q_EMIT titleChanged(title); + } + break; + + default: + break; + } + + return Super::event(e); +} + + +#ifndef QT_NO_TOOLTIP +//============================================================================ +void CDockWidget::setTabToolTip(const QString &text) +{ + if (d->TabWidget) + { + d->TabWidget->setToolTip(text); + } + if (d->ToggleViewAction) + { + d->ToggleViewAction->setToolTip(text); + } + if (d->DockArea) + { + d->DockArea->markTitleBarMenuOutdated();//update tabs menu + } +} +#endif + + +//============================================================================ +void CDockWidget::setIcon(const QIcon& Icon) +{ + d->TabWidget->setIcon(Icon); + if (!d->ToggleViewAction->isCheckable()) + { + d->ToggleViewAction->setIcon(Icon); + } +} + + +//============================================================================ +QIcon CDockWidget::icon() const +{ + return d->TabWidget->icon(); +} + + +//============================================================================ +QToolBar* CDockWidget::toolBar() const +{ + return d->ToolBar; +} + + +//============================================================================ +QToolBar* CDockWidget::createDefaultToolBar() +{ + if (!d->ToolBar) + { + d->setupToolBar(); + } + + return d->ToolBar; +} + + +//============================================================================ +void CDockWidget::setToolBar(QToolBar* ToolBar) +{ + if (d->ToolBar) + { + delete d->ToolBar; + } + + d->ToolBar = ToolBar; + d->Layout->insertWidget(0, d->ToolBar); + this->connect(this, SIGNAL(topLevelChanged(bool)), SLOT(setToolbarFloatingStyle(bool))); + setToolbarFloatingStyle(isFloating()); +} + + +//============================================================================ +void CDockWidget::setToolBarStyle(Qt::ToolButtonStyle Style, eState State) +{ + if (StateFloating == State) + { + d->ToolBarStyleFloating = Style; + } + else + { + d->ToolBarStyleDocked = Style; + } + + setToolbarFloatingStyle(isFloating()); +} + + +//============================================================================ +Qt::ToolButtonStyle CDockWidget::toolBarStyle(eState State) const +{ + if (StateFloating == State) + { + return d->ToolBarStyleFloating; + } + else + { + return d->ToolBarStyleDocked; + } +} + + +//============================================================================ +void CDockWidget::setToolBarIconSize(const QSize& IconSize, eState State) +{ + if (StateFloating == State) + { + d->ToolBarIconSizeFloating = IconSize; + } + else + { + d->ToolBarIconSizeDocked = IconSize; + } + + setToolbarFloatingStyle(isFloating()); +} + + +//============================================================================ +QSize CDockWidget::toolBarIconSize(eState State) const +{ + if (StateFloating == State) + { + return d->ToolBarIconSizeFloating; + } + else + { + return d->ToolBarIconSizeDocked; + } +} + + +//============================================================================ +void CDockWidget::setToolbarFloatingStyle(bool Floating) +{ + if (!d->ToolBar) + { + return; + } + + auto IconSize = Floating ? d->ToolBarIconSizeFloating : d->ToolBarIconSizeDocked; + if (IconSize != d->ToolBar->iconSize()) + { + d->ToolBar->setIconSize(IconSize); + } + + auto ButtonStyle = Floating ? d->ToolBarStyleFloating : d->ToolBarStyleDocked; + if (ButtonStyle != d->ToolBar->toolButtonStyle()) + { + d->ToolBar->setToolButtonStyle(ButtonStyle); + } +} + + +//============================================================================ +void CDockWidget::emitTopLevelEventForWidget(CDockWidget* TopLevelDockWidget, bool Floating) +{ + if (TopLevelDockWidget) + { + TopLevelDockWidget->dockAreaWidget()->updateTitleBarVisibility(); + TopLevelDockWidget->emitTopLevelChanged(Floating); + } +} + + +//============================================================================ +void CDockWidget::emitTopLevelChanged(bool Floating) +{ + if (Floating != d->IsFloatingTopLevel) + { + d->IsFloatingTopLevel = Floating; + Q_EMIT topLevelChanged(d->IsFloatingTopLevel); + } +} + + +//============================================================================ +void CDockWidget::setClosedState(bool Closed) +{ + d->Closed = Closed; +} + + +//============================================================================ +QSize CDockWidget::minimumSizeHint() const +{ + if (d->MinimumSizeHintMode == CDockWidget::MinimumSizeHintFromDockWidget || !d->Widget) + { + return QSize(60, 40); + } + else + { + return d->Widget->minimumSizeHint(); + } +} + + +//============================================================================ +void CDockWidget::setFloating() +{ + if (isClosed()) + { + return; + } + d->TabWidget->detachDockWidget(); +} + + +//============================================================================ +void CDockWidget::deleteDockWidget() +{ + auto manager=dockManager(); + if(manager){ + manager->removeDockWidget(this); + } + deleteLater(); + d->Closed = true; +} + + +//============================================================================ +void CDockWidget::closeDockWidget() +{ + closeDockWidgetInternal(true); +} + + +//============================================================================ +bool CDockWidget::closeDockWidgetInternal(bool ForceClose) +{ + if (!ForceClose) + { + Q_EMIT closeRequested(); + } + + if (!ForceClose && features().testFlag(CDockWidget::CustomCloseHandling)) + { + return false; + } + + if (features().testFlag(CDockWidget::DockWidgetDeleteOnClose)) + { + // If the dock widget is floating, then we check if we also need to + // delete the floating widget + if (isFloating()) + { + CFloatingDockContainer* FloatingWidget = internal::findParent< + CFloatingDockContainer*>(this); + if (FloatingWidget->dockWidgets().count() == 1) + { + FloatingWidget->deleteLater(); + } + else + { + FloatingWidget->hide(); + } + } + deleteDockWidget(); + Q_EMIT closed(); + } + else + { + toggleView(false); + } + + return true; +} + + +//============================================================================ +void CDockWidget::setTitleBarActions(QList actions) +{ + d->TitleBarActions = actions; +} + + +//============================================================================ +QList CDockWidget::titleBarActions() const +{ + return d->TitleBarActions; +} + + +//============================================================================ +void CDockWidget::showFullScreen() +{ + if (isFloating()) + { + dockContainer()->floatingWidget()->showFullScreen(); + } + else + { + Super::showFullScreen(); + } +} + + +//============================================================================ +void CDockWidget::showNormal() +{ + if (isFloating()) + { + dockContainer()->floatingWidget()->showNormal(); + } + else + { + Super::showNormal(); + } +} + + +//============================================================================ +bool CDockWidget::isFullScreen() const +{ + if (isFloating()) + { + return dockContainer()->floatingWidget()->isFullScreen(); + } + else + { + return Super::isFullScreen(); + } +} + + +//============================================================================ +void CDockWidget::setAsCurrentTab() +{ + if (d->DockArea && !isClosed()) + { + d->DockArea->setCurrentDockWidget(this); + } +} + + +//============================================================================ +bool CDockWidget::isTabbed() const +{ + return d->DockArea && (d->DockArea->openDockWidgetsCount() > 1); +} + + + +//============================================================================ +bool CDockWidget::isCurrentTab() const +{ + return d->DockArea && (d->DockArea->currentDockWidget() == this); +} + + +//============================================================================ +void CDockWidget::raise() +{ + if (isClosed()) + { + return; + } + + setAsCurrentTab(); + if (isInFloatingContainer()) + { + auto FloatingWindow = window(); + FloatingWindow->raise(); + FloatingWindow->activateWindow(); + } +} + + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockWidget.cpp diff --git a/ads/DockWidget.h b/ads/DockWidget.h new file mode 100644 index 0000000..1886b2b --- /dev/null +++ b/ads/DockWidget.h @@ -0,0 +1,613 @@ +#ifndef DockWidgetH +#define DockWidgetH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockWidget.h +/// \author Uwe Kindler +/// \date 26.02.2017 +/// \brief Declaration of CDockWidget class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include "ads_globals.h" + +QT_FORWARD_DECLARE_CLASS(QToolBar) +QT_FORWARD_DECLARE_CLASS(QXmlStreamWriter) + +namespace ads +{ +struct DockWidgetPrivate; +class CDockWidgetTab; +class CDockManager; +class CDockContainerWidget; +class CDockAreaWidget; +class DockContainerWidgetPrivate; +class CFloatingDockContainer; + +/** + * The QDockWidget class provides a widget that can be docked inside a + * CDockManager or floated as a top-level window on the desktop. + */ +class ADS_EXPORT CDockWidget : public QFrame +{ + Q_OBJECT +private: + DockWidgetPrivate* d; ///< private data (pimpl) + friend struct DockWidgetPrivate; + +private Q_SLOTS: + /** + * Adjusts the toolbar icon sizes according to the floating state + */ + void setToolbarFloatingStyle(bool topLevel); + +protected: + friend class CDockContainerWidget; + friend class CDockAreaWidget; + friend class CFloatingDockContainer; + friend class CDockManager; + friend struct DockManagerPrivate; + friend class DockContainerWidgetPrivate; + friend class CDockAreaTabBar; + friend class CDockWidgetTab; + friend struct DockWidgetTabPrivate; + friend struct DockAreaTitleBarPrivate; + + /** + * Assigns the dock manager that manages this dock widget + */ + void setDockManager(CDockManager* DockManager); + + /** + * If this dock widget is inserted into a dock area, the dock area will + * be registered on this widget via this function. If a dock widget is + * removed from a dock area, this function will be called with nullptr + * value. + */ + void setDockArea(CDockAreaWidget* DockArea); + + /** + * This function changes the toggle view action without emitting any + * signal + */ + void setToggleViewActionChecked(bool Checked); + + /** + * Saves the state into the given stream + */ + void saveState(QXmlStreamWriter& Stream) const; + + /** + * This is a helper function for the dock manager to flag this widget + * as unassigned. + * When calling the restore function, it may happen, that the saved state + * contains less dock widgets then currently available. All widgets whose + * data is not contained in the saved state, are flagged as unassigned + * after the restore process. If the user shows an unassigned dock widget, + * a floating widget will be created to take up the dock widget. + */ + void flagAsUnassigned(); + + /** + * Call this function to emit a topLevelChanged() signal and to update + * the dock area tool bar visibility + */ + static void emitTopLevelEventForWidget(CDockWidget* TopLevelDockWidget, bool Floating); + + /** + * Use this function to emit a top level changed event. + * Do never use emit topLevelChanged(). Always use this function because + * it only emits a signal if the floating state has really changed + */ + void emitTopLevelChanged(bool Floating); + + /** + * Internal function for modifying the closed state when restoring + * a saved docking state + */ + void setClosedState(bool Closed); + + /** + * Internal toggle view function that does not check if the widget + * already is in the given state + */ + void toggleViewInternal(bool Open); + + /** + * Internal close dock widget implementation. + * The function returns true if the dock widget has been closed or hidden + */ + bool closeDockWidgetInternal(bool ForceClose = false); + +public: + using Super = QFrame; + + enum DockWidgetFeature + { + DockWidgetClosable = 0x001,///< dock widget has a close button + DockWidgetMovable = 0x002,///< dock widget is movable and can be moved to a new position in the current dock container + DockWidgetFloatable = 0x004,///< dock widget can be dragged into a floating window + DockWidgetDeleteOnClose = 0x008, ///< deletes the dock widget when it is closed + CustomCloseHandling = 0x010, ///< clicking the close button will not close the dock widget but emits the closeRequested() signal instead + DockWidgetFocusable = 0x020, ///< if this is enabled, a dock widget can get focus highlighting + DockWidgetForceCloseWithArea = 0x040, ///< dock widget will be closed when the dock area hosting it is closed + NoTab = 0x080, ///< dock widget tab will never be shown if this flag is set + DeleteContentOnClose = 0x100, ///< deletes only the contained widget on close, keeping the dock widget intact and in place. Attempts to rebuild the contents widget on show if there is a widget factory set. + DefaultDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable | DockWidgetFocusable, + AllDockWidgetFeatures = DefaultDockWidgetFeatures | DockWidgetDeleteOnClose | CustomCloseHandling, + DockWidgetAlwaysCloseAndDelete = DockWidgetForceCloseWithArea | DockWidgetDeleteOnClose, + NoDockWidgetFeatures = 0x000 + }; + Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature) + + enum eState + { + StateHidden, + StateDocked, + StateFloating + }; + + /** + * Sets the widget for the dock widget to widget. + * The InsertMode defines how the widget is inserted into the dock widget. + * The content of a dock widget should be resizable do a very small size to + * prevent the dock widget from blocking the resizing. To ensure, that a + * dock widget can be resized very well, it is better to insert the content+ + * widget into a scroll area or to provide a widget that is already a scroll + * area or that contains a scroll area. + * If the InsertMode is AutoScrollArea, the DockWidget tries to automatically + * detect how to insert the given widget. If the widget is derived from + * QScrollArea (i.e. an QAbstractItemView), then the widget is inserted + * directly. If the given widget is not a scroll area, the widget will be + * inserted into a scroll area. + * To force insertion into a scroll area, you can also provide the InsertMode + * ForceScrollArea. To prevent insertion into a scroll area, you can + * provide the InsertMode ForceNoScrollArea + */ + enum eInsertMode + { + AutoScrollArea, + ForceScrollArea, + ForceNoScrollArea + }; + + + /** + * The mode of the minimumSizeHint() that is returned by the DockWidget + * minimumSizeHint() function. + * To ensure, that a dock widget does not block resizing, the dock widget + * reimplements minimumSizeHint() function to return a very small minimum + * size hint. If you would like to adhere the minimumSizeHint() from the + * content widget, then set the minimumSizeHintMode() to + * MinimumSizeHintFromContent. + */ + enum eMinimumSizeHintMode + { + MinimumSizeHintFromDockWidget, + MinimumSizeHintFromContent + }; + + + /** + * This mode configures the behavior of the toggle view action. + * If the mode if ActionModeToggle, then the toggle view action is + * a checkable action to show / hide the dock widget. If the mode + * is ActionModeShow, then the action is not checkable an it will + * always show the dock widget if clicked. If the mode is ActionModeShow, + * the user can only close the DockWidget with the close button. + */ + enum eToggleViewActionMode + { + ActionModeToggle,//!< ActionModeToggle + ActionModeShow //!< ActionModeShow + }; + + + /** + * This constructor creates a dock widget with the given title. + * The title is the text that is shown in the window title when the dock + * widget is floating and it is the title that is shown in the titlebar + * or the tab of this dock widget if it is tabified. + * The object name of the dock widget is also set to the title. The + * object name is required by the dock manager to properly save and restore + * the state of the dock widget. That means, the title needs to be unique. + * If your title is not unique or if you would like to change the title + * during runtime, you need to set a unique object name explicitely + * by calling setObjectName() after construction. + * Use the layoutFlags to configure the layout of the dock widget. + */ + CDockWidget(const QString &title, QWidget* parent = 0); + + /** + * Virtual Destructor + */ + virtual ~CDockWidget(); + + /** + * We return a fixed minimum size hint or the size hint of the content + * widget if minimum size hint mode is MinimumSizeHintFromContent + */ + virtual QSize minimumSizeHint() const override; + + /** + * Sets the widget for the dock widget to widget. + * The InsertMode defines how the widget is inserted into the dock widget. + * The content of a dock widget should be resizable to a very small size to + * prevent the dock widget from blocking the resizing. To ensure, that a + * dock widget can be resized very well, it is better to insert the content+ + * widget into a scroll area or to provide a widget that is already a scroll + * area or that contains a scroll area. + * If the InsertMode is AutoScrollArea, the DockWidget tries to automatically + * detect how to insert the given widget. If the widget is derived from + * QScrollArea (i.e. an QAbstractItemView), then the widget is inserted + * directly. If the given widget is not a scroll area, the widget will be + * inserted into a scroll area. + * To force insertion into a scroll area, you can also provide the InsertMode + * ForceScrollArea. To prevent insertion into a scroll area, you can + * provide the InsertMode ForceNoScrollArea + */ + void setWidget(QWidget* widget, eInsertMode InsertMode = AutoScrollArea); + + /** + * Only used when the feature flag DeleteContentOnClose is set. + * Using the flag and setting a widget factory allows to free the resources + * of the widget of your application while retaining the position the next + * time you want to show your widget, unlike the flag DockWidgetDeleteOnClose + * which deletes the dock widget itself. Since we keep the dock widget, all + * regular features of ADS should work as normal, including saving and + * restoring the state of the docking system and using perspectives. + */ + using FactoryFunc = std::function; + void setWidgetFactory(FactoryFunc createWidget, eInsertMode InsertMode = AutoScrollArea); + + /** + * Remove the widget from the dock and give ownership back to the caller + */ + QWidget* takeWidget(); + + /** + * Returns the widget for the dock widget. This function returns zero if + * the widget has not been set. + */ + QWidget* widget() const; + + /** + * Returns the tab widget of this dock widget that is shown in the dock + * area title bar + */ + CDockWidgetTab* tabWidget() const; + + /** + * Sets, whether the dock widget is movable, closable, and floatable. + */ + void setFeatures(DockWidgetFeatures features); + + /** + * Sets the feature flag for this dock widget if on is true; otherwise + * clears the flag. + */ + void setFeature(DockWidgetFeature flag, bool on); + + /** + * This property holds whether the dock widget is movable, closable, and + * floatable. + * By default, this property is set to a combination of DockWidgetClosable, + * DockWidgetMovable and DockWidgetFloatable. + */ + DockWidgetFeatures features() const; + + /** + * Returns the dock manager that manages the dock widget or 0 if the widget + * has not been assigned to any dock manager yet + */ + CDockManager* dockManager() const; + + /** + * Returns the dock container widget this dock area widget belongs to or 0 + * if this dock widget has not been docked yet + */ + CDockContainerWidget* dockContainer() const; + + /** + * This function return the floating DockContainer if is isFloating() is true + * and a nullptr if this dock widget is not floating. + */ + CFloatingDockContainer* floatingDockContainer() const; + + /** + * Returns the dock area widget this dock widget belongs to or 0 + * if this dock widget has not been docked yet + */ + CDockAreaWidget* dockAreaWidget() const; + + /** + * This property holds whether the dock widget is floating. + * A dock widget is only floating, if it is the one and only widget inside + * of a floating container. If there are more than one dock widget in a + * floating container, the all dock widgets are docked and not floating. + */ + bool isFloating() const; + + /** + * This function returns true, if this dock widget is in a floating. + * The function returns true, if the dock widget is floating and it also + * returns true if it is docked inside of a floating container. + */ + bool isInFloatingContainer() const; + + /** + * Returns true, if this dock widget is closed. + */ + bool isClosed() const; + + /** + * Returns a checkable action that can be used to show or close this dock widget. + * The action's text is set to the dock widget's window title. + */ + QAction* toggleViewAction() const; + + /** + * Configures the behavior of the toggle view action. + * \see eToggleViewActionMode for a detailed description + */ + void setToggleViewActionMode(eToggleViewActionMode Mode); + + /** + * Configures the minimum size hint that is returned by the + * minimumSizeHint() function. + * \see eMinimumSizeHintMode for a detailed description + */ + void setMinimumSizeHintMode(eMinimumSizeHintMode Mode); + + /** + * Returns true if the dock widget is set as central widget of it's dock manager + */ + bool isCentralWidget() const; + + /** + * Sets the dock widget icon that is shown in tabs and in toggle view + * actions + */ + void setIcon(const QIcon& Icon); + + /** + * Returns the icon that has been assigned to the dock widget + */ + QIcon icon() const; + + /** + * This function returns the dock widget top tool bar. + * If no toolbar is assigned, this function returns nullptr. To get a vaild + * toolbar you either need to create a default empty toolbar via + * createDefaultToolBar() function or you need to assign your custom + * toolbar via setToolBar(). + */ + QToolBar* toolBar() const; + + /** + * If you would like to use the default top tool bar, then call this + * function to create the default tool bar. + * After this function the toolBar() function will return a valid toolBar() + * object. + */ + QToolBar* createDefaultToolBar(); + + /** + * Assign a new tool bar that is shown above the content widget. + * The dock widget will become the owner of the tool bar and deletes it + * on destruction + */ + void setToolBar(QToolBar* ToolBar); + + /** + * This function sets the tool button style for the given dock widget state. + * It is possible to switch the tool button style depending on the state. + * If a dock widget is floating, then here are more space and it is + * possible to select a style that requires more space like + * Qt::ToolButtonTextUnderIcon. For the docked state Qt::ToolButtonIconOnly + * might be better. + */ + void setToolBarStyle(Qt::ToolButtonStyle Style, eState State); + + /** + * Returns the tool button style for the given docking state. + * \see setToolBarStyle() + */ + Qt::ToolButtonStyle toolBarStyle(eState State) const; + + /** + * This function sets the tool button icon size for the given state. + * If a dock widget is floating, there is more space an increasing the + * icon size is possible. For docked widgets, small icon sizes, eg. 16 x 16 + * might be better. + */ + void setToolBarIconSize(const QSize& IconSize, eState State); + + /** + * Returns the icon size for a given docking state. + * \see setToolBarIconSize() + */ + QSize toolBarIconSize(eState State) const; + + /** + * Set the actions that will be shown in the dock area title bar + * if this dock widget is the active tab. + * You should not add to many actions to the title bar, because this + * will remove the available space for the tabs. If you have a number + * of actions, just add an action with a menu to show a popup menu + * button in the title bar. + */ + void setTitleBarActions(QList actions); + + /** + * Returns a list of actions that will be inserted into the dock area title + * bar if this dock widget becomes the current widget + */ + virtual QList titleBarActions() const; + + +#ifndef QT_NO_TOOLTIP + /** + * This is function sets text tooltip for title bar widget + * and tooltip for toggle view action + */ + void setTabToolTip(const QString &text); +#endif + + /** + * Returns true if the dock widget is floating and if the floating dock + * container is full screen + */ + bool isFullScreen() const; + + /** + * Returns true if this dock widget is in a dock area, that contains at + * least 2 opened dock widgets + */ + bool isTabbed() const; + + /** + * Returns true if this dock widget is the current one in the dock + * area widget that contains it. + * If the dock widget is the only opened dock widget in a dock area, + * the true is returned + */ + bool isCurrentTab() const; + +public: // reimplements QFrame ----------------------------------------------- + /** + * Emits titleChanged signal if title change event occurs + */ + virtual bool event(QEvent *e) override; + +public Q_SLOTS: + /** + * This property controls whether the dock widget is open or closed. + * The toogleViewAction triggers this slot + */ + void toggleView(bool Open = true); + + /** + * Makes this dock widget the current tab in its dock area. + * The function only has an effect, if the dock widget is open. A call + * to this function will not toggle the view, so if it is closed, + * nothing will happen + */ + void setAsCurrentTab(); + + /** + * Brings the dock widget to the front + * This means: + * - If the dock widget is tabbed with other dock widgets but its tab is not current, it's made current. + * - If the dock widget is floating, QWindow::raise() is called. + * This only applies if the dock widget is already open. If closed, does nothing. + */ + void raise(); + + /** + * This function will make a docked widget floating + */ + void setFloating(); + + /** + * This function will delete the dock widget and its content from the + * docking system + */ + void deleteDockWidget(); + + /** + * Closes the dock widget + */ + void closeDockWidget(); + + /** + * Shows the widget in full-screen mode. + * Normally this function only affects windows. To make the interface + * compatible to QDockWidget, this function also maximizes a floating + * dock widget. + * + * \note Full-screen mode works fine under Windows, but has certain + * problems (doe not work) under X (Linux). These problems are due to + * limitations of the ICCCM protocol that specifies the communication + * between X11 clients and the window manager. ICCCM simply does not + * understand the concept of non-decorated full-screen windows. + */ + void showFullScreen(); + + /** + * This function complements showFullScreen() to restore the widget + * after it has been in full screen mode. + */ + void showNormal(); + + +Q_SIGNALS: + /** + * This signal is emitted if the dock widget is opened or closed + */ + void viewToggled(bool Open); + + /** + * This signal is emitted if the dock widget is closed + */ + void closed(); + + /** + * This signal is emitted if the window title of this dock widget + * changed + */ + void titleChanged(const QString& Title); + + /** + * This signal is emitted when the floating property changes. + * The topLevel parameter is true if the dock widget is now floating; + * otherwise it is false. + */ + void topLevelChanged(bool topLevel); + + /** + * This signal is emitted, if close is requested + */ + void closeRequested(); + + /** + * This signal is emitted when the dock widget becomes visible (or invisible). + * This happens when the widget is hidden or shown, as well as when it is + * docked in a tabbed dock area and its tab becomes selected or unselected. + */ + void visibilityChanged(bool visible); + + /** + * This signal is emitted when the features property changes. + * The features parameter gives the new value of the property. + */ + void featuresChanged(ads::CDockWidget::DockWidgetFeatures features); +}; // class DockWidget +} // namespace ads + +Q_DECLARE_OPERATORS_FOR_FLAGS(ads::CDockWidget::DockWidgetFeatures) +//----------------------------------------------------------------------------- +#endif // DockWidgetH diff --git a/ads/DockWidgetTab.cpp b/ads/DockWidgetTab.cpp new file mode 100644 index 0000000..512e6b5 --- /dev/null +++ b/ads/DockWidgetTab.cpp @@ -0,0 +1,768 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockWidgetTab.cpp +/// \author Uwe Kindler +/// \date 27.02.2017 +/// \brief Implementation of CDockWidgetTab class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include "FloatingDragPreview.h" +#include "ElidingLabel.h" +#include "DockWidgetTab.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ads_globals.h" +#include "DockWidget.h" +#include "DockAreaWidget.h" +#include "FloatingDockContainer.h" +#include "DockOverlay.h" +#include "DockManager.h" +#include "IconProvider.h" +#include "DockFocusController.h" + + +namespace ads +{ + +using tTabLabel = CElidingLabel; + +/** + * Private data class of CDockWidgetTab class (pimpl) + */ +struct DockWidgetTabPrivate +{ + CDockWidgetTab* _this; + CDockWidget* DockWidget; + QLabel* IconLabel = nullptr; + tTabLabel* TitleLabel; + QPoint GlobalDragStartMousePosition; + QPoint DragStartMousePosition; + bool IsActiveTab = false; + CDockAreaWidget* DockArea = nullptr; + eDragState DragState = DraggingInactive; + IFloatingWidget* FloatingWidget = nullptr; + QIcon Icon; + QAbstractButton* CloseButton = nullptr; + QSpacerItem* IconTextSpacer; + QPoint TabDragStartPosition; + QSize IconSize; + + /** + * Private data constructor + */ + DockWidgetTabPrivate(CDockWidgetTab* _public); + + /** + * Creates the complete layout including all controls + */ + void createLayout(); + + /** + * Moves the tab depending on the position in the given mouse event + */ + void moveTab(QMouseEvent* ev); + + /** + * Test function for current drag state + */ + bool isDraggingState(eDragState dragState) const + { + return this->DragState == dragState; + } + + + /** + * Starts floating of the dock widget that belongs to this title bar + * Returns true, if floating has been started and false if floating + * is not possible for any reason + */ + bool startFloating(eDragState DraggingState = DraggingFloatingWidget); + + /** + * Returns true if the given config flag is set + */ + bool testConfigFlag(CDockManager::eConfigFlag Flag) const + { + return CDockManager::testConfigFlag(Flag); + } + + /** + * Creates the close button as QPushButton or as QToolButton + */ + QAbstractButton* createCloseButton() const + { + if (testConfigFlag(CDockManager::TabCloseButtonIsToolButton)) + { + auto Button = new QToolButton(); + Button->setAutoRaise(true); + return Button; + } + else + { + return new QPushButton(); + } + } + + /** + * Update the close button visibility from current feature/config + */ + void updateCloseButtonVisibility(bool active) + { + bool DockWidgetClosable = DockWidget->features().testFlag(CDockWidget::DockWidgetClosable); + bool ActiveTabHasCloseButton = testConfigFlag(CDockManager::ActiveTabHasCloseButton); + bool AllTabsHaveCloseButton = testConfigFlag(CDockManager::AllTabsHaveCloseButton); + bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton; + CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton); + } + + /** + * Update the size policy of the close button depending on the + * RetainTabSizeWhenCloseButtonHidden feature + */ + void updateCloseButtonSizePolicy() + { + auto Features = DockWidget->features(); + auto SizePolicy = CloseButton->sizePolicy(); + SizePolicy.setRetainSizeWhenHidden(Features.testFlag(CDockWidget::DockWidgetClosable) + && testConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden)); + CloseButton->setSizePolicy(SizePolicy); + } + + template + IFloatingWidget* createFloatingWidget(T* Widget, bool OpaqueUndocking) + { + if (OpaqueUndocking) + { + return new CFloatingDockContainer(Widget); + } + else + { + auto w = new CFloatingDragPreview(Widget); + _this->connect(w, &CFloatingDragPreview::draggingCanceled, [=]() + { + DragState = DraggingInactive; + }); + return w; + } + } + + /** + * Saves the drag start position in global and local coordinates + */ + void saveDragStartMousePosition(const QPoint& GlobalPos) + { + GlobalDragStartMousePosition = GlobalPos; + DragStartMousePosition = _this->mapFromGlobal(GlobalPos); + } + + /** + * Update the icon in case the icon size changed + */ + void updateIcon() + { + if (!IconLabel || Icon.isNull()) + { + return; + } + + if (IconSize.isValid()) + { + IconLabel->setPixmap(Icon.pixmap(IconSize)); + } + else + { + IconLabel->setPixmap(Icon.pixmap(_this->style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, _this))); + } + IconLabel->setVisible(true); + } + + /** + * Convenience function for access to the dock manager dock focus controller + */ + CDockFocusController* focusController() const + { + return DockWidget->dockManager()->dockFocusController(); + } + +}; +// struct DockWidgetTabPrivate + + +//============================================================================ +DockWidgetTabPrivate::DockWidgetTabPrivate(CDockWidgetTab* _public) : + _this(_public) +{ + +} + + +//============================================================================ +void DockWidgetTabPrivate::createLayout() +{ + TitleLabel = new tTabLabel(); + TitleLabel->setElideMode(Qt::ElideRight); + TitleLabel->setText(DockWidget->windowTitle()); + TitleLabel->setObjectName("dockWidgetTabLabel"); + TitleLabel->setAlignment(Qt::AlignCenter); + _this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool))); + + + CloseButton = createCloseButton(); + CloseButton->setObjectName("tabCloseButton"); + internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, TabCloseIcon); + CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + CloseButton->setFocusPolicy(Qt::NoFocus); + updateCloseButtonSizePolicy(); + internal::setToolTip(CloseButton, QObject::tr("Close Tab")); + _this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested())); + + QFontMetrics fm(TitleLabel->font()); + int Spacing = qRound(fm.height() / 4.0); + + // Fill the layout + QBoxLayout* Layout = new QBoxLayout(QBoxLayout::LeftToRight); + Layout->setContentsMargins(2 * Spacing,0,0,0); + Layout->setSpacing(0); + _this->setLayout(Layout); + Layout->addWidget(TitleLabel, 1); + Layout->addSpacing(Spacing); + Layout->addWidget(CloseButton); + Layout->addSpacing(qRound(Spacing * 4.0 / 3.0)); + Layout->setAlignment(Qt::AlignCenter); + + TitleLabel->setVisible(true); +} + +//============================================================================ +void DockWidgetTabPrivate::moveTab(QMouseEvent* ev) +{ + ev->accept(); + QPoint Distance = internal::globalPositionOf(ev) - GlobalDragStartMousePosition; + Distance.setY(0); + auto TargetPos = Distance + TabDragStartPosition; + TargetPos.rx() = qMax(TargetPos.x(), 0); + TargetPos.rx() = qMin(_this->parentWidget()->rect().right() - _this->width() + 1, TargetPos.rx()); + _this->move(TargetPos); + _this->raise(); +} + + +//============================================================================ +bool DockWidgetTabPrivate::startFloating(eDragState DraggingState) +{ + auto dockContainer = DockWidget->dockContainer(); + ADS_PRINT("isFloating " << dockContainer->isFloating()); + ADS_PRINT("areaCount " << dockContainer->dockAreaCount()); + ADS_PRINT("widgetCount " << DockWidget->dockAreaWidget()->dockWidgetsCount()); + // if this is the last dock widget inside of this floating widget, + // then it does not make any sense, to make it floating because + // it is already floating + if (dockContainer->isFloating() + && (dockContainer->visibleDockAreaCount() == 1) + && (DockWidget->dockAreaWidget()->dockWidgetsCount() == 1)) + { + return false; + } + + ADS_PRINT("startFloating"); + DragState = DraggingState; + IFloatingWidget* FloatingWidget = nullptr; + bool OpaqueUndocking = CDockManager::testConfigFlag(CDockManager::OpaqueUndocking) || + (DraggingFloatingWidget != DraggingState); + + // If section widget has multiple tabs, we take only one tab + // If it has only one single tab, we can move the complete + // dock area into floating widget + QSize Size; + if (DockArea->dockWidgetsCount() > 1) + { + FloatingWidget = createFloatingWidget(DockWidget, OpaqueUndocking); + Size = DockWidget->size(); + } + else + { + FloatingWidget = createFloatingWidget(DockArea, OpaqueUndocking); + Size = DockArea->size(); + } + + if (DraggingFloatingWidget == DraggingState) + { + FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingFloatingWidget, _this); + auto Overlay = DockWidget->dockManager()->containerOverlay(); + Overlay->setAllowedAreas(OuterDockAreas); + this->FloatingWidget = FloatingWidget; + } + else + { + FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingInactive, nullptr); + } + + return true; +} + + +//============================================================================ +CDockWidgetTab::CDockWidgetTab(CDockWidget* DockWidget, QWidget *parent) : + QFrame(parent), + d(new DockWidgetTabPrivate(this)) +{ + setAttribute(Qt::WA_NoMousePropagation, true); + d->DockWidget = DockWidget; + d->createLayout(); + setFocusPolicy(Qt::NoFocus); + /*if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) + { + setFocusPolicy(Qt::ClickFocus); + }*/ +} + +//============================================================================ +CDockWidgetTab::~CDockWidgetTab() +{ + ADS_PRINT("~CDockWidgetTab()"); + delete d; +} + + +//============================================================================ +void CDockWidgetTab::mousePressEvent(QMouseEvent* ev) +{ + if (ev->button() == Qt::LeftButton) + { + ev->accept(); + d->saveDragStartMousePosition(internal::globalPositionOf(ev)); + d->DragState = DraggingMousePressed; + if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) + { + d->focusController()->setDockWidgetTabFocused(this); + } + Q_EMIT clicked(); + return; + } + Super::mousePressEvent(ev); +} + + + +//============================================================================ +void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev) +{ + if (ev->button() == Qt::LeftButton) + { + auto CurrentDragState = d->DragState; + d->GlobalDragStartMousePosition = QPoint(); + d->DragStartMousePosition = QPoint(); + d->DragState = DraggingInactive; + + switch (CurrentDragState) + { + case DraggingTab: + // End of tab moving, emit signal + if (d->DockArea) + { + ev->accept(); + Q_EMIT moved(internal::globalPositionOf(ev)); + } + break; + + case DraggingFloatingWidget: + ev->accept(); + d->FloatingWidget->finishDragging(); + break; + + default:; // do nothing + } + } + else if (ev->button() == Qt::MiddleButton) + { + if (CDockManager::testConfigFlag(CDockManager::MiddleMouseButtonClosesTab) && d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable)) + { + // Only attempt to close if the mouse is still + // on top of the widget, to allow the user to cancel. + if (rect().contains(mapFromGlobal(QCursor::pos()))) { + ev->accept(); + Q_EMIT closeRequested(); + } + } + } + + Super::mouseReleaseEvent(ev); +} + + +//============================================================================ +void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) +{ + if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive)) + { + d->DragState = DraggingInactive; + Super::mouseMoveEvent(ev); + return; + } + + // move floating window + if (d->isDraggingState(DraggingFloatingWidget)) + { + d->FloatingWidget->moveFloating(); + Super::mouseMoveEvent(ev); + return; + } + + // move tab + if (d->isDraggingState(DraggingTab)) + { + // Moving the tab is always allowed because it does not mean moving the + // dock widget around + d->moveTab(ev); + } + + auto MappedPos = mapToParent(ev->pos()); + bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right()); + // Maybe a fixed drag distance is better here ? + int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - internal::globalPositionOf(ev).y()); + if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar) + { + // If this is the last dock area in a dock container with only + // one single dock widget it does not make sense to move it to a new + // floating widget and leave this one empty + if (d->DockArea->dockContainer()->isFloating() + && d->DockArea->openDockWidgetsCount() == 1 + && d->DockArea->dockContainer()->visibleDockAreaCount() == 1) + { + return; + } + + + // Floating is only allowed for widgets that are floatable + // If we do non opaque undocking, then can create the drag preview + // if the widget is movable. + auto Features = d->DockWidget->features(); + if (Features.testFlag(CDockWidget::DockWidgetFloatable) + || (Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking))) + { + // If we undock, we need to restore the initial position of this + // tab because it looks strange if it remains on its dragged position + if (d->isDraggingState(DraggingTab) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking)) + { + parentWidget()->layout()->update(); + } + d->startFloating(); + } + return; + } + else if (d->DockArea->openDockWidgetsCount() > 1 + && (internal::globalPositionOf(ev) - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving + { + // If we start dragging the tab, we save its inital position to + // restore it later + if (DraggingTab != d->DragState) + { + d->TabDragStartPosition = this->pos(); + } + d->DragState = DraggingTab; + return; + } + + Super::mouseMoveEvent(ev); +} + + +//============================================================================ +void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev) +{ + ev->accept(); + if (d->isDraggingState(DraggingFloatingWidget)) + { + return; + } + + d->saveDragStartMousePosition(ev->globalPos()); + QMenu Menu(this); + + const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable); + const bool isNotOnlyTabInContainer = !d->DockArea->dockContainer()->hasTopLevelDockWidget(); + + const bool isDetachable = isFloatable && isNotOnlyTabInContainer; + + auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget())); + Action->setEnabled(isDetachable); + Menu.addSeparator(); + Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested())); + Action->setEnabled(isClosable()); + Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested())); + Menu.exec(ev->globalPos()); +} + + +//============================================================================ +bool CDockWidgetTab::isActiveTab() const +{ + return d->IsActiveTab; +} + + +//============================================================================ +void CDockWidgetTab::setActiveTab(bool active) +{ + d->updateCloseButtonVisibility(active); + + // Focus related stuff + if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting) && !d->DockWidget->dockManager()->isRestoringState()) + { + bool UpdateFocusStyle = false; + if (active && !hasFocus()) + { + //setFocus(Qt::OtherFocusReason); + d->focusController()->setDockWidgetTabFocused(this); + UpdateFocusStyle = true; + } + + if (d->IsActiveTab == active) + { + if (UpdateFocusStyle) + { + updateStyle(); + } + return; + } + } + else if (d->IsActiveTab == active) + { + return; + } + + d->IsActiveTab = active; + updateStyle(); + update(); + updateGeometry(); + + Q_EMIT activeTabChanged(); +} + + +//============================================================================ +CDockWidget* CDockWidgetTab::dockWidget() const +{ + return d->DockWidget; +} + + +//============================================================================ +void CDockWidgetTab::setDockAreaWidget(CDockAreaWidget* DockArea) +{ + d->DockArea = DockArea; +} + + +//============================================================================ +CDockAreaWidget* CDockWidgetTab::dockAreaWidget() const +{ + return d->DockArea; +} + + +//============================================================================ +void CDockWidgetTab::setIcon(const QIcon& Icon) +{ + QBoxLayout* Layout = qobject_cast(layout()); + if (!d->IconLabel && Icon.isNull()) + { + return; + } + + if (!d->IconLabel) + { + d->IconLabel = new QLabel(); + d->IconLabel->setAlignment(Qt::AlignVCenter); + d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); + internal::setToolTip(d->IconLabel, d->TitleLabel->toolTip()); + Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter); + Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0)); + } + else if (Icon.isNull()) + { + // Remove icon label and spacer item + Layout->removeWidget(d->IconLabel); + Layout->removeItem(Layout->itemAt(0)); + delete d->IconLabel; + d->IconLabel = nullptr; + } + + d->Icon = Icon; + d->updateIcon(); +} + + +//============================================================================ +const QIcon& CDockWidgetTab::icon() const +{ + return d->Icon; +} + + +//============================================================================ +QString CDockWidgetTab::text() const +{ + return d->TitleLabel->text(); +} + + +//============================================================================ +void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + // If this is the last dock area in a dock container it does not make + // sense to move it to a new floating widget and leave this one + // empty + if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1) + && d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) + { + event->accept(); + d->saveDragStartMousePosition(internal::globalPositionOf(event)); + d->startFloating(DraggingInactive); + } + } + + Super::mouseDoubleClickEvent(event); +} + + +//============================================================================ +void CDockWidgetTab::setVisible(bool visible) +{ + visible &= !d->DockWidget->features().testFlag(CDockWidget::NoTab); + Super::setVisible(visible); +} + + +//============================================================================ +void CDockWidgetTab::setText(const QString& title) +{ + d->TitleLabel->setText(title); +} + + +//============================================================================ +bool CDockWidgetTab::isTitleElided() const +{ + return d->TitleLabel->isElided(); +} + + + +//============================================================================ +bool CDockWidgetTab::isClosable() const +{ + return d->DockWidget && d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable); +} + + +//=========================================================================== +void CDockWidgetTab::detachDockWidget() +{ + if (!d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) + { + return; + } + + d->saveDragStartMousePosition(QCursor::pos()); + d->startFloating(DraggingInactive); +} + + +//============================================================================ +bool CDockWidgetTab::event(QEvent *e) +{ +#ifndef QT_NO_TOOLTIP + if (e->type() == QEvent::ToolTipChange) + { + const auto text = toolTip(); + d->TitleLabel->setToolTip(text); + if (d->IconLabel) { + d->IconLabel->setToolTip(text); + } + } +#endif + if (e->type() == QEvent::StyleChange) + { + d->updateIcon(); + } + return Super::event(e); +} + + +//============================================================================ +void CDockWidgetTab::onDockWidgetFeaturesChanged() +{ + d->updateCloseButtonSizePolicy(); + d->updateCloseButtonVisibility(isActiveTab()); +} + + +//============================================================================ +void CDockWidgetTab::setElideMode(Qt::TextElideMode mode) +{ + d->TitleLabel->setElideMode(mode); +} + + +//============================================================================ +void CDockWidgetTab::updateStyle() +{ + internal::repolishStyle(this, internal::RepolishDirectChildren); +} + + +//============================================================================ +QSize CDockWidgetTab::iconSize() const +{ + return d->IconSize; +} + + +//============================================================================ +void CDockWidgetTab::setIconSize(const QSize& Size) +{ + d->IconSize = Size; + d->updateIcon(); +} + + + + +} // namespace ads +//--------------------------------------------------------------------------- +// EOF DockWidgetTab.cpp diff --git a/ads/DockWidgetTab.h b/ads/DockWidgetTab.h new file mode 100644 index 0000000..7ee45e3 --- /dev/null +++ b/ads/DockWidgetTab.h @@ -0,0 +1,192 @@ +#ifndef DockWidgetTabH +#define DockWidgetTabH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file DockWidgetTab.h +/// \author Uwe Kindler +/// \date 27.02.2017 +/// \brief Declaration of CDockWidgetTab class +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include + +#include "ads_globals.h" + +namespace ads +{ +class CDockWidget; +class CDockAreaWidget; +struct DockWidgetTabPrivate; +class CDockManager; + +/** + * A dock widget tab that shows a title and an icon. + * The dock widget tab is shown in the dock area title bar to switch between + * tabbed dock widgets + */ +class ADS_EXPORT CDockWidgetTab : public QFrame +{ + Q_OBJECT + Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged) + Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) + +private: + DockWidgetTabPrivate* d; ///< private data (pimpl) + friend struct DockWidgetTabPrivate; + friend class CDockWidget; + friend class CDockManager; + void onDockWidgetFeaturesChanged(); + +private Q_SLOTS: + void detachDockWidget(); + +protected: + virtual void mousePressEvent(QMouseEvent* ev) override; + virtual void mouseReleaseEvent(QMouseEvent* ev) override; + virtual void mouseMoveEvent(QMouseEvent* ev) override; + virtual void contextMenuEvent(QContextMenuEvent* ev) override; + + /** + * Double clicking the tab widget makes the assigned dock widget floating + */ + virtual void mouseDoubleClickEvent(QMouseEvent *event) override; + +public: + using Super = QFrame; + /** + * Default Constructor + * param[in] DockWidget The dock widget this title bar belongs to + * param[in] parent The parent widget of this title bar + */ + CDockWidgetTab(CDockWidget* DockWidget, QWidget* parent = 0); + + /** + * Virtual Destructor + */ + virtual ~CDockWidgetTab(); + + /** + * Returns true, if this is the active tab + */ + bool isActiveTab() const; + + /** + * Set this true to make this tab the active tab + */ + void setActiveTab(bool active); + + /** + * Sets the dock area widget the dockWidget returned by dockWidget() + * function belongs to. + */ + void setDockAreaWidget(CDockAreaWidget* DockArea); + + /** + * Returns the dock area widget this title bar belongs to. + * \return This function returns 0 if the dock widget that owns this title + * bar widget has not been added to any dock area yet. + */ + CDockAreaWidget* dockAreaWidget() const; + + /** + * Returns the dock widget this title widget belongs to + */ + CDockWidget* dockWidget() const; + + /** + * Sets the icon to show in title bar + */ + void setIcon(const QIcon& Icon); + + /** + * Returns the icon + */ + const QIcon& icon() const; + + /** + * Returns the tab text + */ + QString text() const; + + /** + * Sets the tab text + */ + void setText(const QString& title); + + /** + * Returns true if text is elided on the tab's title + */ + bool isTitleElided() const; + + /** + * This function returns true if the assigned dock widget is closable + */ + bool isClosable() const; + + /** + * Track event ToolTipChange and set child ToolTip + */ + virtual bool event(QEvent *e) override; + + /** + * Sets the text elide mode + */ + void setElideMode(Qt::TextElideMode mode); + + /** + * Update stylesheet style if a property changes + */ + void updateStyle(); + + /** + * Returns the icon size. + * If no explicit icon size has been set, the function returns an invalid + * QSize + */ + QSize iconSize() const; + + /** + * Set an explicit icon size. + * If no icon size has been set explicitely, than the tab sets the icon size + * depending on the style + */ + void setIconSize(const QSize& Size); + +public Q_SLOTS: + virtual void setVisible(bool visible) override; + +Q_SIGNALS: + void activeTabChanged(); + void clicked(); + void closeRequested(); + void closeOtherTabsRequested(); + void moved(const QPoint& GlobalPos); + void elidedChanged(bool elided); +}; // class DockWidgetTab +} + // namespace ads +//----------------------------------------------------------------------------- +#endif // DockWidgetTabH diff --git a/ads/DockingStateReader.cpp b/ads/DockingStateReader.cpp new file mode 100644 index 0000000..4ae0f3c --- /dev/null +++ b/ads/DockingStateReader.cpp @@ -0,0 +1,30 @@ +//============================================================================ +/// \file DockingStateReader.cpp +/// \author Uwe Kindler +/// \date 29.11.2019 +/// \brief Implementation of CDockingStateReader +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "DockingStateReader.h" + +namespace ads +{ + +//============================================================================ +void CDockingStateReader::setFileVersion(int FileVersion) +{ + m_FileVersion = FileVersion; +} + +//============================================================================ +int CDockingStateReader::fileVersion() const +{ + return m_FileVersion; +} +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF DockingStateReader.cpp diff --git a/ads/DockingStateReader.h b/ads/DockingStateReader.h new file mode 100644 index 0000000..5c59dc2 --- /dev/null +++ b/ads/DockingStateReader.h @@ -0,0 +1,43 @@ +#ifndef DockingStateReaderH +#define DockingStateReaderH +//============================================================================ +/// \file DockingStateReader.h +/// \author Uwe Kindler +/// \date 29.11.2019 +/// \brief Declaration of CDockingStateReader +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +namespace ads +{ + +/** + * Extends QXmlStreamReader with file version information + */ +class CDockingStateReader : public QXmlStreamReader +{ +private: + int m_FileVersion; + +public: + using QXmlStreamReader::QXmlStreamReader; + + /** + * Set the file version for this state reader + */ + void setFileVersion(int FileVersion); + + /** + * Returns the file version set via setFileVersion + */ + int fileVersion() const; +}; + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // DockingStateReaderH diff --git a/ads/ElidingLabel.cpp b/ads/ElidingLabel.cpp new file mode 100644 index 0000000..ac52122 --- /dev/null +++ b/ads/ElidingLabel.cpp @@ -0,0 +1,231 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file ElidingLabel.cpp +/// \author Uwe Kindler +/// \date 05.11.2018 +/// \brief Implementation of CElidingLabel +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "ElidingLabel.h" +#include + + +namespace ads +{ +/** + * Private data of public CClickableLabel + */ +struct ElidingLabelPrivate +{ + CElidingLabel* _this; + Qt::TextElideMode ElideMode = Qt::ElideNone; + QString Text; + bool IsElided = false; + + ElidingLabelPrivate(CElidingLabel* _public) : _this(_public) {} + + void elideText(int Width); + + /** + * Convenience function to check if the + */ + bool isModeElideNone() const + { + return Qt::ElideNone == ElideMode; + } +}; + + +//============================================================================ +void ElidingLabelPrivate::elideText(int Width) +{ + if (isModeElideNone()) + { + return; + } + QFontMetrics fm = _this->fontMetrics(); + QString str = fm.elidedText(Text, ElideMode, Width - _this->margin() * 2 - _this->indent()); + if (str == "…") + { + str = Text.at(0); + } + bool WasElided = IsElided; + IsElided = str != Text; + if(IsElided != WasElided) + { + Q_EMIT _this->elidedChanged(IsElided); + } + _this->QLabel::setText(str); +} + + +//============================================================================ +CElidingLabel::CElidingLabel(QWidget* parent, Qt::WindowFlags f) + : QLabel(parent, f), + d(new ElidingLabelPrivate(this)) +{ + +} + + +//============================================================================ +CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFlags f) + : QLabel(text, parent,f), + d(new ElidingLabelPrivate(this)) +{ + d->Text = text; + internal::setToolTip(this, text); +} + + +//============================================================================ +CElidingLabel::~CElidingLabel() +{ + delete d; +} + + +//============================================================================ +Qt::TextElideMode CElidingLabel::elideMode() const +{ + return d->ElideMode; +} + + +//============================================================================ +void CElidingLabel::setElideMode(Qt::TextElideMode mode) +{ + d->ElideMode = mode; + d->elideText(size().width()); +} + +//============================================================================ +bool CElidingLabel::isElided() const +{ + return d->IsElided; +} + + +//============================================================================ +void CElidingLabel::mouseReleaseEvent(QMouseEvent* event) +{ + Super::mouseReleaseEvent(event); + if (event->button() != Qt::LeftButton) + { + return; + } + + Q_EMIT clicked(); +} + + +//============================================================================ +void CElidingLabel::mouseDoubleClickEvent( QMouseEvent *ev ) +{ + Q_UNUSED(ev) + Q_EMIT doubleClicked(); + Super::mouseDoubleClickEvent(ev); +} + + +//============================================================================ +void CElidingLabel::resizeEvent(QResizeEvent *event) +{ + if (!d->isModeElideNone()) + { + d->elideText(event->size().width()); + } + Super::resizeEvent(event); +} + + +//============================================================================ +QSize CElidingLabel::minimumSizeHint() const +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + bool HasPixmap = !pixmap(Qt::ReturnByValue).isNull(); +#else + bool HasPixmap = (pixmap() != nullptr); +#endif + if (HasPixmap || d->isModeElideNone()) + { + return QLabel::minimumSizeHint(); + } + const QFontMetrics &fm = fontMetrics(); + #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + QSize size(fm.horizontalAdvance(d->Text.left(2) + "…"), fm.height()); + #else + QSize size(fm.width(d->Text.left(2) + "…"), fm.height()); + #endif + return size; +} + + +//============================================================================ +QSize CElidingLabel::sizeHint() const +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + bool HasPixmap = !pixmap(Qt::ReturnByValue).isNull(); +#else + bool HasPixmap = (pixmap() != nullptr); +#endif + if (HasPixmap || d->isModeElideNone()) + { + return QLabel::sizeHint(); + } + const QFontMetrics& fm = fontMetrics(); + #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + QSize size(fm.horizontalAdvance(d->Text), QLabel::sizeHint().height()); + #else + QSize size(fm.width(d->Text), QLabel::sizeHint().height()); + #endif + return size; +} + + +//============================================================================ +void CElidingLabel::setText(const QString &text) +{ + d->Text = text; + if (d->isModeElideNone()) + { + Super::setText(text); + } + else + { + internal::setToolTip(this, text); + d->elideText(this->size().width()); + } +} + + +//============================================================================ +QString CElidingLabel::text() const +{ + return d->Text; +} +} // namespace QtLabb + +//--------------------------------------------------------------------------- +// EOF ClickableLabel.cpp diff --git a/ads/ElidingLabel.h b/ads/ElidingLabel.h new file mode 100644 index 0000000..894dcb0 --- /dev/null +++ b/ads/ElidingLabel.h @@ -0,0 +1,108 @@ +#ifndef ElidingLabelH +#define ElidingLabelH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file ElidingLabel.h +/// \author Uwe Kindler +/// \date 05.11.2018 +/// \brief Declaration of CElidingLabel +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include "ads_globals.h" + +namespace ads +{ +struct ElidingLabelPrivate; + +/** + * A QLabel that supports eliding text. + * Because the functions setText() and text() are no virtual functions setting + * and reading the text via a pointer to the base class QLabel does not work + * properly + */ +class ADS_EXPORT CElidingLabel : public QLabel +{ + Q_OBJECT +private: + ElidingLabelPrivate* d; + friend struct ElidingLabelPrivate; + +protected: + virtual void mouseReleaseEvent(QMouseEvent* event) override; + virtual void resizeEvent( QResizeEvent *event ) override; + virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override; + +public: + using Super = QLabel; + + CElidingLabel(QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowFlags ()); + CElidingLabel(const QString& text, QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowFlags ()); + virtual ~CElidingLabel(); + + /** + * Returns the text elide mode. + * The default mode is ElideNone + */ + Qt::TextElideMode elideMode() const; + + /** + * Sets the text elide mode + */ + void setElideMode(Qt::TextElideMode mode); + + /** + * This function indicates whether the text on this label is currently elided + */ + bool isElided() const; + +public: // reimplements QLabel ---------------------------------------------- + virtual QSize minimumSizeHint() const override; + virtual QSize sizeHint() const override; + void setText(const QString &text); + QString text() const; + +Q_SIGNALS: + /** + * This signal is emitted if the user clicks on the label (i.e. pressed + * down then released while the mouse cursor is inside the label) + */ + void clicked(); + + /** + * This signal is emitted if the user does a double click on the label + */ + void doubleClicked(); + + /** + * This signal is emitted when isElided() state of this label is changed + */ + void elidedChanged(bool elided); +}; //class CElidingLabel + +} // namespace QtLabb + +//--------------------------------------------------------------------------- +#endif // ElidingLabelH diff --git a/ads/FloatingDockContainer.cpp b/ads/FloatingDockContainer.cpp new file mode 100644 index 0000000..26ef4fc --- /dev/null +++ b/ads/FloatingDockContainer.cpp @@ -0,0 +1,1287 @@ +/******************************************************************************* + ** Qt Advanced Docking System + ** Copyright (C) 2017 Uwe Kindler + ** + ** This library is free software; you can redistribute it and/or + ** modify it under the terms of the GNU Lesser General Public + ** License as published by the Free Software Foundation; either + ** version 2.1 of the License, or (at your option) any later version. + ** + ** This library is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. + ** + ** You should have received a copy of the GNU Lesser General Public + ** License along with this library; If not, see . + ******************************************************************************/ + +//============================================================================ +/// \file FloatingDockContainer.cpp +/// \author Uwe Kindler +/// \date 01.03.2017 +/// \brief Implementation of CFloatingDockContainer class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "FloatingDockContainer.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DockContainerWidget.h" +#include "DockAreaWidget.h" +#include "DockManager.h" +#include "DockWidget.h" +#include "DockOverlay.h" + +#ifdef Q_OS_WIN +#include +#ifdef _MSC_VER +#pragma comment(lib, "User32.lib") +#endif +#endif +#ifdef Q_OS_LINUX +#include "linux/FloatingWidgetTitleBar.h" +#include +#endif + +namespace ads +{ +#ifdef Q_OS_WIN +#if 0 // set to 1 if you need this function for debugging +/** + * Just for debuging to convert windows message identifiers to strings + */ +static const char* windowsMessageString(int MessageId) +{ + switch (MessageId) + { + case 0: return "WM_NULL"; + case 1: return "WM_CREATE"; + case 2: return "WM_DESTROY"; + case 3: return "WM_MOVE"; + case 5: return "WM_SIZE"; + case 6: return "WM_ACTIVATE"; + case 7: return "WM_SETFOCUS"; + case 8: return "WM_KILLFOCUS"; + case 10: return "WM_ENABLE"; + case 11: return "WM_SETREDRAW"; + case 12: return "WM_SETTEXT"; + case 13: return "WM_GETTEXT"; + case 14: return "WM_GETTEXTLENGTH"; + case 15: return "WM_PAINT"; + case 16: return "WM_CLOSE"; + case 17: return "WM_QUERYENDSESSION"; + case 18: return "WM_QUIT"; + case 19: return "WM_QUERYOPEN"; + case 20: return "WM_ERASEBKGND"; + case 21: return "WM_SYSCOLORCHANGE"; + case 22: return "WM_ENDSESSION"; + case 24: return "WM_SHOWWINDOW"; + case 25: return "WM_CTLCOLOR"; + case 26: return "WM_WININICHANGE"; + case 27: return "WM_DEVMODECHANGE"; + case 28: return "WM_ACTIVATEAPP"; + case 29: return "WM_FONTCHANGE"; + case 30: return "WM_TIMECHANGE"; + case 31: return "WM_CANCELMODE"; + case 32: return "WM_SETCURSOR"; + case 33: return "WM_MOUSEACTIVATE"; + case 34: return "WM_CHILDACTIVATE"; + case 35: return "WM_QUEUESYNC"; + case 36: return "WM_GETMINMAXINFO"; + case 38: return "WM_PAINTICON"; + case 39: return "WM_ICONERASEBKGND"; + case 40: return "WM_NEXTDLGCTL"; + case 42: return "WM_SPOOLERSTATUS"; + case 43: return "WM_DRAWITEM"; + case 44: return "WM_MEASUREITEM"; + case 45: return "WM_DELETEITEM"; + case 46: return "WM_VKEYTOITEM"; + case 47: return "WM_CHARTOITEM"; + case 48: return "WM_SETFONT"; + case 49: return "WM_GETFONT"; + case 50: return "WM_SETHOTKEY"; + case 51: return "WM_GETHOTKEY"; + case 55: return "WM_QUERYDRAGICON"; + case 57: return "WM_COMPAREITEM"; + case 61: return "WM_GETOBJECT"; + case 65: return "WM_COMPACTING"; + case 68: return "WM_COMMNOTIFY"; + case 70: return "WM_WINDOWPOSCHANGING"; + case 71: return "WM_WINDOWPOSCHANGED"; + case 72: return "WM_POWER"; + case 73: return "WM_COPYGLOBALDATA"; + case 74: return "WM_COPYDATA"; + case 75: return "WM_CANCELJOURNAL"; + case 78: return "WM_NOTIFY"; + case 80: return "WM_INPUTLANGCHANGEREQUEST"; + case 81: return "WM_INPUTLANGCHANGE"; + case 82: return "WM_TCARD"; + case 83: return "WM_HELP"; + case 84: return "WM_USERCHANGED"; + case 85: return "WM_NOTIFYFORMAT"; + case 123: return "WM_CONTEXTMENU"; + case 124: return "WM_STYLECHANGING"; + case 125: return "WM_STYLECHANGED"; + case 126: return "WM_DISPLAYCHANGE"; + case 127: return "WM_GETICON"; + case 128: return "WM_SETICON"; + case 129: return "WM_NCCREATE"; + case 130: return "WM_NCDESTROY"; + case 131: return "WM_NCCALCSIZE"; + case 132: return "WM_NCHITTEST"; + case 133: return "WM_NCPAINT"; + case 134: return "WM_NCACTIVATE"; + case 135: return "WM_GETDLGCODE"; + case 136: return "WM_SYNCPAINT"; + case 160: return "WM_NCMOUSEMOVE"; + case 161: return "WM_NCLBUTTONDOWN"; + case 162: return "WM_NCLBUTTONUP"; + case 163: return "WM_NCLBUTTONDBLCLK"; + case 164: return "WM_NCRBUTTONDOWN"; + case 165: return "WM_NCRBUTTONUP"; + case 166: return "WM_NCRBUTTONDBLCLK"; + case 167: return "WM_NCMBUTTONDOWN"; + case 168: return "WM_NCMBUTTONUP"; + case 169: return "WM_NCMBUTTONDBLCLK"; + case 171: return "WM_NCXBUTTONDOWN"; + case 172: return "WM_NCXBUTTONUP"; + case 173: return "WM_NCXBUTTONDBLCLK"; + case 176: return "EM_GETSEL"; + case 177: return "EM_SETSEL"; + case 178: return "EM_GETRECT"; + case 179: return "EM_SETRECT"; + case 180: return "EM_SETRECTNP"; + case 181: return "EM_SCROLL"; + case 182: return "EM_LINESCROLL"; + case 183: return "EM_SCROLLCARET"; + case 185: return "EM_GETMODIFY"; + case 187: return "EM_SETMODIFY"; + case 188: return "EM_GETLINECOUNT"; + case 189: return "EM_LINEINDEX"; + case 190: return "EM_SETHANDLE"; + case 191: return "EM_GETHANDLE"; + case 192: return "EM_GETTHUMB"; + case 193: return "EM_LINELENGTH"; + case 194: return "EM_REPLACESEL"; + case 195: return "EM_SETFONT"; + case 196: return "EM_GETLINE"; + case 197: return "EM_LIMITTEXT / EM_SETLIMITTEXT"; + case 198: return "EM_CANUNDO"; + case 199: return "EM_UNDO"; + case 200: return "EM_FMTLINES"; + case 201: return "EM_LINEFROMCHAR"; + case 202: return "EM_SETWORDBREAK"; + case 203: return "EM_SETTABSTOPS"; + case 204: return "EM_SETPASSWORDCHAR"; + case 205: return "EM_EMPTYUNDOBUFFER"; + case 206: return "EM_GETFIRSTVISIBLELINE"; + case 207: return "EM_SETREADONLY"; + case 209: return "EM_SETWORDBREAKPROC / EM_GETWORDBREAKPROC"; + case 210: return "EM_GETPASSWORDCHAR"; + case 211: return "EM_SETMARGINS"; + case 212: return "EM_GETMARGINS"; + case 213: return "EM_GETLIMITTEXT"; + case 214: return "EM_POSFROMCHAR"; + case 215: return "EM_CHARFROMPOS"; + case 216: return "EM_SETIMESTATUS"; + case 217: return "EM_GETIMESTATUS"; + case 224: return "SBM_SETPOS"; + case 225: return "SBM_GETPOS"; + case 226: return "SBM_SETRANGE"; + case 227: return "SBM_GETRANGE"; + case 228: return "SBM_ENABLE_ARROWS"; + case 230: return "SBM_SETRANGEREDRAW"; + case 233: return "SBM_SETSCROLLINFO"; + case 234: return "SBM_GETSCROLLINFO"; + case 235: return "SBM_GETSCROLLBARINFO"; + case 240: return "BM_GETCHECK"; + case 241: return "BM_SETCHECK"; + case 242: return "BM_GETSTATE"; + case 243: return "BM_SETSTATE"; + case 244: return "BM_SETSTYLE"; + case 245: return "BM_CLICK"; + case 246: return "BM_GETIMAGE"; + case 247: return "BM_SETIMAGE"; + case 248: return "BM_SETDONTCLICK"; + case 255: return "WM_INPUT"; + case 256: return "WM_KEYDOWN"; + case 257: return "WM_KEYUP"; + case 258: return "WM_CHAR"; + case 259: return "WM_DEADCHAR"; + case 260: return "WM_SYSKEYDOWN"; + case 261: return "WM_SYSKEYUP"; + case 262: return "WM_SYSCHAR"; + case 263: return "WM_SYSDEADCHAR"; + case 265: return "WM_UNICHAR / WM_WNT_CONVERTREQUESTEX"; + case 266: return "WM_CONVERTREQUEST"; + case 267: return "WM_CONVERTRESULT"; + case 268: return "WM_INTERIM"; + case 269: return "WM_IME_STARTCOMPOSITION"; + case 270: return "WM_IME_ENDCOMPOSITION"; + case 272: return "WM_INITDIALOG"; + case 273: return "WM_COMMAND"; + case 274: return "WM_SYSCOMMAND"; + case 275: return "WM_TIMER"; + case 276: return "WM_HSCROLL"; + case 277: return "WM_VSCROLL"; + case 278: return "WM_INITMENU"; + case 279: return "WM_INITMENUPOPUP"; + case 280: return "WM_SYSTIMER"; + case 287: return "WM_MENUSELECT"; + case 288: return "WM_MENUCHAR"; + case 289: return "WM_ENTERIDLE"; + case 290: return "WM_MENURBUTTONUP"; + case 291: return "WM_MENUDRAG"; + case 292: return "WM_MENUGETOBJECT"; + case 293: return "WM_UNINITMENUPOPUP"; + case 294: return "WM_MENUCOMMAND"; + case 295: return "WM_CHANGEUISTATE"; + case 296: return "WM_UPDATEUISTATE"; + case 297: return "WM_QUERYUISTATE"; + case 306: return "WM_CTLCOLORMSGBOX"; + case 307: return "WM_CTLCOLOREDIT"; + case 308: return "WM_CTLCOLORLISTBOX"; + case 309: return "WM_CTLCOLORBTN"; + case 310: return "WM_CTLCOLORDLG"; + case 311: return "WM_CTLCOLORSCROLLBAR"; + case 312: return "WM_CTLCOLORSTATIC"; + case 512: return "WM_MOUSEMOVE"; + case 513: return "WM_LBUTTONDOWN"; + case 514: return "WM_LBUTTONUP"; + case 515: return "WM_LBUTTONDBLCLK"; + case 516: return "WM_RBUTTONDOWN"; + case 517: return "WM_RBUTTONUP"; + case 518: return "WM_RBUTTONDBLCLK"; + case 519: return "WM_MBUTTONDOWN"; + case 520: return "WM_MBUTTONUP"; + case 521: return "WM_MBUTTONDBLCLK"; + case 522: return "WM_MOUSEWHEEL"; + case 523: return "WM_XBUTTONDOWN"; + case 524: return "WM_XBUTTONUP"; + case 525: return "WM_XBUTTONDBLCLK"; + case 528: return "WM_PARENTNOTIFY"; + case 529: return "WM_ENTERMENULOOP"; + case 530: return "WM_EXITMENULOOP"; + case 531: return "WM_NEXTMENU"; + case 532: return "WM_SIZING"; + case 533: return "WM_CAPTURECHANGED"; + case 534: return "WM_MOVING"; + case 536: return "WM_POWERBROADCAST"; + case 537: return "WM_DEVICECHANGE"; + case 544: return "WM_MDICREATE"; + case 545: return "WM_MDIDESTROY"; + case 546: return "WM_MDIACTIVATE"; + case 547: return "WM_MDIRESTORE"; + case 548: return "WM_MDINEXT"; + case 549: return "WM_MDIMAXIMIZE"; + case 550: return "WM_MDITILE"; + case 551: return "WM_MDICASCADE"; + case 552: return "WM_MDIICONARRANGE"; + case 553: return "WM_MDIGETACTIVE"; + case 560: return "WM_MDISETMENU"; + case 561: return "WM_ENTERSIZEMOVE"; + case 562: return "WM_EXITSIZEMOVE"; + case 563: return "WM_DROPFILES"; + case 564: return "WM_MDIREFRESHMENU"; + case 640: return "WM_IME_REPORT"; + case 641: return "WM_IME_SETCONTEXT"; + case 642: return "WM_IME_NOTIFY"; + case 643: return "WM_IME_CONTROL"; + case 644: return "WM_IME_COMPOSITIONFULL"; + case 645: return "WM_IME_SELECT"; + case 646: return "WM_IME_CHAR"; + case 648: return "WM_IME_REQUEST"; + case 656: return "WM_IME_KEYDOWN"; + case 657: return "WM_IME_KEYUP"; + case 672: return "WM_NCMOUSEHOVER"; + case 673: return "WM_MOUSEHOVER"; + case 674: return "WM_NCMOUSELEAVE"; + case 675: return "WM_MOUSELEAVE"; + case 768: return "WM_CUT"; + case 769: return "WM_COPY"; + case 770: return "WM_PASTE"; + case 771: return "WM_CLEAR"; + case 772: return "WM_UNDO"; + case 773: return "WM_RENDERFORMAT"; + case 774: return "WM_RENDERALLFORMATS"; + case 775: return "WM_DESTROYCLIPBOARD"; + case 776: return "WM_DRAWCLIPBOARD"; + case 777: return "WM_PAINTCLIPBOARD"; + case 778: return "WM_VSCROLLCLIPBOARD"; + case 779: return "WM_SIZECLIPBOARD"; + case 780: return "WM_ASKCBFORMATNAME"; + case 781: return "WM_CHANGECBCHAIN"; + case 782: return "WM_HSCROLLCLIPBOARD"; + case 783: return "WM_QUERYNEWPALETTE"; + case 784: return "WM_PALETTEISCHANGING"; + case 785: return "WM_PALETTECHANGED"; + case 786: return "WM_HOTKEY"; + case 791: return "WM_PRINT"; + case 792: return "WM_PRINTCLIENT"; + case 793: return "WM_APPCOMMAND"; + case 856: return "WM_HANDHELDFIRST"; + case 863: return "WM_HANDHELDLAST"; + case 864: return "WM_AFXFIRST"; + case 895: return "WM_AFXLAST"; + case 896: return "WM_PENWINFIRST"; + case 897: return "WM_RCRESULT"; + case 898: return "WM_HOOKRCRESULT"; + case 899: return "WM_GLOBALRCCHANGE / WM_PENMISCINFO"; + case 900: return "WM_SKB"; + case 901: return "WM_HEDITCTL / WM_PENCTL"; + case 902: return "WM_PENMISC"; + case 903: return "WM_CTLINIT"; + case 904: return "WM_PENEVENT"; + case 911: return "WM_PENWINLAST"; + default: + return "unknown WM_ message"; + } + + return "unknown WM_ message"; +} +#endif +#endif + + +static unsigned int zOrderCounter = 0; +/** + * Private data class of CFloatingDockContainer class (pimpl) + */ +struct FloatingDockContainerPrivate +{ + CFloatingDockContainer *_this; + CDockContainerWidget *DockContainer; + unsigned int zOrderIndex = ++zOrderCounter; + QPointer DockManager; + eDragState DraggingState = DraggingInactive; + QPoint DragStartMousePosition; + CDockContainerWidget *DropContainer = nullptr; + CDockAreaWidget *SingleDockArea = nullptr; + QPoint DragStartPos; + bool Hiding = false; + bool AutoHideChildren = true; +#ifdef Q_OS_LINUX + QWidget* MouseEventHandler = nullptr; + CFloatingWidgetTitleBar* TitleBar = nullptr; + bool IsResizing = false; +#endif + + /** + * Private data constructor + */ + FloatingDockContainerPrivate(CFloatingDockContainer *_public); + + void titleMouseReleaseEvent(); + void updateDropOverlays(const QPoint &GlobalPos); + + /** + * Returns true if the given config flag is set + */ + static bool testConfigFlag(CDockManager::eConfigFlag Flag) + { + return CDockManager::testConfigFlag(Flag); + } + + /** + * Tests is a certain state is active + */ + bool isState(eDragState StateId) const + { + return StateId == DraggingState; + } + + void setState(eDragState StateId) + { + DraggingState = StateId; + } + + void setWindowTitle(const QString &Text) + { +#ifdef Q_OS_LINUX + if (TitleBar) + { + TitleBar->setTitle(Text); + } +#endif + _this->setWindowTitle(Text); + } + + /** + * Reflect the current dock widget title in the floating widget windowTitle() + * depending on the CDockManager::FloatingContainerHasWidgetTitle flag + */ + void reflectCurrentWidget(CDockWidget* CurrentWidget) + { + // reflect CurrentWidget's title if configured to do so, otherwise display application name as window title + if (testConfigFlag(CDockManager::FloatingContainerHasWidgetTitle)) + { + setWindowTitle(CurrentWidget->windowTitle()); + } + else + { + setWindowTitle(qApp->applicationDisplayName()); + } + + // reflect CurrentWidget's icon if configured to do so, otherwise display application icon as window icon + QIcon CurrentWidgetIcon = CurrentWidget->icon(); + if (testConfigFlag(CDockManager::FloatingContainerHasWidgetIcon) + && !CurrentWidgetIcon.isNull()) + { + _this->setWindowIcon(CurrentWidget->icon()); + } + else + { + _this->setWindowIcon(QApplication::windowIcon()); + } + } + + /** + * Handles escape key press when dragging around the floating widget + */ + void handleEscapeKey(); +}; +// struct FloatingDockContainerPrivate + +//============================================================================ +FloatingDockContainerPrivate::FloatingDockContainerPrivate( + CFloatingDockContainer *_public) : + _this(_public) +{ + +} + +//============================================================================ +void FloatingDockContainerPrivate::titleMouseReleaseEvent() +{ + setState(DraggingInactive); + if (!DropContainer) + { + return; + } + + if (DockManager->dockAreaOverlay()->dropAreaUnderCursor() + != InvalidDockWidgetArea + || DockManager->containerOverlay()->dropAreaUnderCursor() + != InvalidDockWidgetArea) + { + CDockOverlay *Overlay = DockManager->containerOverlay(); + if (!Overlay->dropOverlayRect().isValid()) + { + Overlay = DockManager->dockAreaOverlay(); + } + + // Resize the floating widget to the size of the highlighted drop area + // rectangle + QRect Rect = Overlay->dropOverlayRect(); + int FrameWidth = (_this->frameSize().width() - _this->rect().width()) + / 2; + int TitleBarHeight = _this->frameSize().height() + - _this->rect().height() - FrameWidth; + if (Rect.isValid()) + { + QPoint TopLeft = Overlay->mapToGlobal(Rect.topLeft()); + TopLeft.ry() += TitleBarHeight; + _this->setGeometry( + QRect(TopLeft, + QSize(Rect.width(), Rect.height() - TitleBarHeight))); + QApplication::processEvents(); + } + DropContainer->dropFloatingWidget(_this, QCursor::pos()); + } + + DockManager->containerOverlay()->hideOverlay(); + DockManager->dockAreaOverlay()->hideOverlay(); +} + +//============================================================================ +void FloatingDockContainerPrivate::updateDropOverlays(const QPoint &GlobalPos) +{ + if (!_this->isVisible() || !DockManager) + { + return; + } + + auto Containers = DockManager->dockContainers(); + CDockContainerWidget *TopContainer = nullptr; + for (auto ContainerWidget : Containers) + { + if (!ContainerWidget->isVisible()) + { + continue; + } + + if (DockContainer == ContainerWidget) + { + continue; + } + + QPoint MappedPos = ContainerWidget->mapFromGlobal(GlobalPos); + if (ContainerWidget->rect().contains(MappedPos)) + { + if (!TopContainer || ContainerWidget->isInFrontOf(TopContainer)) + { + TopContainer = ContainerWidget; + } + } + } + + DropContainer = TopContainer; + auto ContainerOverlay = DockManager->containerOverlay(); + auto DockAreaOverlay = DockManager->dockAreaOverlay(); + + if (!TopContainer) + { + ContainerOverlay->hideOverlay(); + DockAreaOverlay->hideOverlay(); + return; + } + + int VisibleDockAreas = TopContainer->visibleDockAreaCount(); + ContainerOverlay->setAllowedAreas( + VisibleDockAreas > 1 ? OuterDockAreas : AllDockAreas); + DockWidgetArea ContainerArea = ContainerOverlay->showOverlay(TopContainer); + ContainerOverlay->enableDropPreview(ContainerArea != InvalidDockWidgetArea); + auto DockArea = TopContainer->dockAreaAt(GlobalPos); + if (DockArea && DockArea->isVisible() && VisibleDockAreas > 0) + { + DockAreaOverlay->enableDropPreview(true); + DockAreaOverlay->setAllowedAreas( + (VisibleDockAreas == 1) ? NoDockWidgetArea : DockArea->allowedAreas()); + DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea); + + // A CenterDockWidgetArea for the dockAreaOverlay() indicates that + // the mouse is in the title bar. If the ContainerArea is valid + // then we ignore the dock area of the dockAreaOverlay() and disable + // the drop preview + if ((Area == CenterDockWidgetArea) + && (ContainerArea != InvalidDockWidgetArea)) + { + DockAreaOverlay->enableDropPreview(false); + ContainerOverlay->enableDropPreview(true); + } + else + { + ContainerOverlay->enableDropPreview(InvalidDockWidgetArea == Area); + } + } + else + { + DockAreaOverlay->hideOverlay(); + } +} + + +//============================================================================ +void FloatingDockContainerPrivate::handleEscapeKey() +{ + ADS_PRINT("FloatingDockContainerPrivate::handleEscapeKey()"); + setState(DraggingInactive); + DockManager->containerOverlay()->hideOverlay(); + DockManager->dockAreaOverlay()->hideOverlay(); +} + + +//============================================================================ +CFloatingDockContainer::CFloatingDockContainer(CDockManager *DockManager) : + tFloatingWidgetBase(DockManager), + d(new FloatingDockContainerPrivate(this)) +{ + d->DockManager = DockManager; + d->DockContainer = new CDockContainerWidget(DockManager, this); + connect(d->DockContainer, SIGNAL(dockAreasAdded()), this, + SLOT(onDockAreasAddedOrRemoved())); + connect(d->DockContainer, SIGNAL(dockAreasRemoved()), this, + SLOT(onDockAreasAddedOrRemoved())); + +#ifdef Q_OS_LINUX + QDockWidget::setWidget(d->DockContainer); + QDockWidget::setFloating(true); + QDockWidget::setFeatures(QDockWidget::DockWidgetClosable + | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); + + bool native_window = true; + + // FloatingContainerForce*TitleBar is overwritten by the "ADS_UseNativeTitle" environment variable if set. + auto env = qgetenv("ADS_UseNativeTitle").toUpper(); + if (env == "1") + { + native_window = true; + } + else if (env == "0") + { + native_window = false; + } + else if (DockManager->testConfigFlag(CDockManager::FloatingContainerForceNativeTitleBar)) + { + native_window = true; + } + else if (DockManager->testConfigFlag(CDockManager::FloatingContainerForceQWidgetTitleBar)) + { + native_window = false; + } + else + { + // KDE doesn't seem to fire MoveEvents while moving windows, so for now no native titlebar for everything using KWin. + QString window_manager = internal::windowManager().toUpper().split(" ")[0]; + native_window = window_manager != "KWIN"; + } + + if (native_window) + { + setTitleBarWidget(new QWidget()); + setWindowFlags(Qt::Window | Qt::WindowMaximizeButtonHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); + } + else + { + d->TitleBar = new CFloatingWidgetTitleBar(this); + setTitleBarWidget(d->TitleBar); + setWindowFlags(Qt::Window | Qt::WindowMinMaxButtonsHint | Qt::FramelessWindowHint); + d->TitleBar->enableCloseButton(isClosable()); + connect(d->TitleBar, SIGNAL(closeRequested()), SLOT(close())); + connect(d->TitleBar, &CFloatingWidgetTitleBar::maximizeRequested, + this, &CFloatingDockContainer::onMaximizeRequest); + } +#else + setWindowFlags( + Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint); + QBoxLayout *l = new QBoxLayout(QBoxLayout::TopToBottom); + l->setContentsMargins(0, 0, 0, 0); + l->setSpacing(0); + setLayout(l); + l->addWidget(d->DockContainer); +#endif + + DockManager->registerFloatingWidget(this); +} + +//============================================================================ +CFloatingDockContainer::CFloatingDockContainer(CDockAreaWidget *DockArea) : + CFloatingDockContainer(DockArea->dockManager()) +{ + d->DockContainer->addDockArea(DockArea); + + auto TopLevelDockWidget = topLevelDockWidget(); + if (TopLevelDockWidget) + { + TopLevelDockWidget->emitTopLevelChanged(true); + } + + d->DockManager->notifyWidgetOrAreaRelocation(DockArea); +} + +//============================================================================ +CFloatingDockContainer::CFloatingDockContainer(CDockWidget *DockWidget) : + CFloatingDockContainer(DockWidget->dockManager()) +{ + d->DockContainer->addDockWidget(CenterDockWidgetArea, DockWidget); + auto TopLevelDockWidget = topLevelDockWidget(); + if (TopLevelDockWidget) + { + TopLevelDockWidget->emitTopLevelChanged(true); + } + + d->DockManager->notifyWidgetOrAreaRelocation(DockWidget); +} + +//============================================================================ +CFloatingDockContainer::~CFloatingDockContainer() +{ + ADS_PRINT("~CFloatingDockContainer"); + if (d->DockManager) + { + d->DockManager->removeFloatingWidget(this); + } + delete d; +} + +//============================================================================ +CDockContainerWidget* CFloatingDockContainer::dockContainer() const +{ + return d->DockContainer; +} + +//============================================================================ +void CFloatingDockContainer::changeEvent(QEvent *event) +{ + Super::changeEvent(event); + if ((event->type() == QEvent::ActivationChange) && isActiveWindow()) + { + ADS_PRINT("FloatingWidget::changeEvent QEvent::ActivationChange "); + d->zOrderIndex = ++zOrderCounter; + +#ifdef Q_OS_LINUX + if (d->DraggingState == DraggingFloatingWidget) + { + d->titleMouseReleaseEvent(); + d->DraggingState = DraggingInactive; + } +#endif + } +} + + +#ifdef Q_OS_WIN +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) +bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *message, long *result) +#else +bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) +#endif +{ + QWidget::nativeEvent(eventType, message, result); + MSG *msg = static_cast(message); + switch (msg->message) + { + case WM_MOVING: + { + if (d->isState(DraggingFloatingWidget)) + { + d->updateDropOverlays(QCursor::pos()); + } + } + break; + + case WM_NCLBUTTONDOWN: + if (msg->wParam == HTCAPTION && d->isState(DraggingInactive)) + { + ADS_PRINT("CFloatingDockContainer::nativeEvent WM_NCLBUTTONDOWN"); + d->DragStartPos = pos(); + d->setState(DraggingMousePressed); + } + break; + + case WM_NCLBUTTONDBLCLK: + d->setState(DraggingInactive); + break; + + case WM_ENTERSIZEMOVE: + if (d->isState(DraggingMousePressed)) + { + ADS_PRINT("CFloatingDockContainer::nativeEvent WM_ENTERSIZEMOVE"); + d->setState(DraggingFloatingWidget); + d->updateDropOverlays(QCursor::pos()); + } + break; + + case WM_EXITSIZEMOVE: + if (d->isState(DraggingFloatingWidget)) + { + ADS_PRINT("CFloatingDockContainer::nativeEvent WM_EXITSIZEMOVE"); + if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) + { + d->handleEscapeKey(); + } + else + { + d->titleMouseReleaseEvent(); + } + } + break; + } + return false; +} +#endif + + +//============================================================================ +void CFloatingDockContainer::closeEvent(QCloseEvent *event) +{ + ADS_PRINT("CFloatingDockContainer closeEvent"); + d->setState(DraggingInactive); + event->ignore(); + if (!isClosable()) + { + return; + } + + for (auto DockWidget : d->DockContainer->openedDockWidgets()) + { + if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose)) + { + DockWidget->closeDockWidgetInternal(); + } + else + { + DockWidget->toggleView(false); + } + } + + // In Qt version after 5.9.2 there seems to be a bug that causes the + // QWidget::event() function to not receive any NonClientArea mouse + // events anymore after a close/show cycle. The bug is reported here: + // https://bugreports.qt.io/browse/QTBUG-73295 + // The following code is a workaround for Qt versions > 5.9.2 that seems + // to work + // Starting from Qt version 5.12.2 this seems to work again. But + // now the QEvent::NonClientAreaMouseButtonPress function returns always + // Qt::RightButton even if the left button was pressed + this->hide(); +} + +//============================================================================ +void CFloatingDockContainer::hideEvent(QHideEvent *event) +{ + Super::hideEvent(event); + if (event->spontaneous()) + { + return; + } + + // Prevent toogleView() events during restore state + if (d->DockManager->isRestoringState()) + { + return; + } + + if ( d->AutoHideChildren ) + { + d->Hiding = true; + for ( auto DockArea : d->DockContainer->openedDockAreas() ) + { + for ( auto DockWidget : DockArea->openedDockWidgets() ) + { + DockWidget->toggleView( false ); + } + } + d->Hiding = false; + } +} + + +//============================================================================ +void CFloatingDockContainer::showEvent(QShowEvent *event) +{ + Super::showEvent(event); +#ifdef Q_OS_LINUX + if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting)) + { + this->window()->activateWindow(); + } +#endif +} + + +//============================================================================ +void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos, + const QSize &Size, eDragState DragState, QWidget *MouseEventHandler) +{ +#ifdef Q_OS_LINUX + if (!isMaximized()) + { + resize(Size); + d->DragStartMousePosition = DragStartMousePos; + } + d->setState(DragState); + if (DraggingFloatingWidget == DragState) + { + d->MouseEventHandler = MouseEventHandler; + if (d->MouseEventHandler) + { + d->MouseEventHandler->grabMouse(); + } + } + + if (!isMaximized()) + { + moveFloating(); + } + show(); +#else + Q_UNUSED(MouseEventHandler) + resize(Size); + d->DragStartMousePosition = DragStartMousePos; + d->setState(DragState); + moveFloating(); + show(); +#endif +} + +//============================================================================ +void CFloatingDockContainer::moveFloating() +{ + int BorderSize = (frameSize().width() - size().width()) / 2; + const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition + - QPoint(BorderSize, 0); + move(moveToPos); + switch (d->DraggingState) + { + case DraggingMousePressed: + d->setState(DraggingFloatingWidget); + d->updateDropOverlays(QCursor::pos()); + break; + + case DraggingFloatingWidget: + d->updateDropOverlays(QCursor::pos()); +#ifdef Q_OS_MACOS + // In OSX when hiding the DockAreaOverlay the application would set + // the main window as the active window for some reason. This fixes + // that by resetting the active window to the floating widget after + // updating the overlays. + QApplication::setActiveWindow(this); +#endif + break; + default: + break; + } +} + +//============================================================================ +bool CFloatingDockContainer::isClosable() const +{ + return d->DockContainer->features().testFlag( + CDockWidget::DockWidgetClosable); +} + +//============================================================================ +void CFloatingDockContainer::onDockAreasAddedOrRemoved() +{ + ADS_PRINT("CFloatingDockContainer::onDockAreasAddedOrRemoved()"); + auto TopLevelDockArea = d->DockContainer->topLevelDockArea(); + if (TopLevelDockArea) + { + d->SingleDockArea = TopLevelDockArea; + CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget(); + d->reflectCurrentWidget(CurrentWidget); + connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this, + SLOT(onDockAreaCurrentChanged(int))); + } + else + { + if (d->SingleDockArea) + { + disconnect(d->SingleDockArea, SIGNAL(currentChanged(int)), this, + SLOT(onDockAreaCurrentChanged(int))); + d->SingleDockArea = nullptr; + } + d->setWindowTitle(qApp->applicationDisplayName()); + setWindowIcon(QApplication::windowIcon()); + } +} + +//============================================================================ +void CFloatingDockContainer::updateWindowTitle() +{ + // If this floating container will be hidden, then updating the window + // tile is not required anymore + if (d->Hiding) + { + return; + } + + + auto TopLevelDockArea = d->DockContainer->topLevelDockArea(); + if (TopLevelDockArea) + { + CDockWidget* CurrentWidget = TopLevelDockArea->currentDockWidget(); + if (CurrentWidget) + { + d->reflectCurrentWidget(CurrentWidget); + } + } + else + { + d->setWindowTitle(qApp->applicationDisplayName()); + setWindowIcon(QApplication::windowIcon()); + } +} + +//============================================================================ +void CFloatingDockContainer::onDockAreaCurrentChanged(int Index) +{ + Q_UNUSED(Index); + CDockWidget* CurrentWidget = d->SingleDockArea->currentDockWidget(); + d->reflectCurrentWidget(CurrentWidget); +} + +//============================================================================ +bool CFloatingDockContainer::restoreState(CDockingStateReader &Stream, + bool Testing) +{ + if (!d->DockContainer->restoreState(Stream, Testing)) + { + return false; + } + onDockAreasAddedOrRemoved(); +#ifdef Q_OS_LINUX + if(d->TitleBar) + { + d->TitleBar->setMaximizedIcon(windowState() == Qt::WindowMaximized); + } +#endif + return true; +} + + +//============================================================================ +bool CFloatingDockContainer::hasTopLevelDockWidget() const +{ + return d->DockContainer->hasTopLevelDockWidget(); +} + +//============================================================================ +CDockWidget* CFloatingDockContainer::topLevelDockWidget() const +{ + return d->DockContainer->topLevelDockWidget(); +} + +//============================================================================ +QList CFloatingDockContainer::dockWidgets() const +{ + return d->DockContainer->dockWidgets(); +} + +//============================================================================ +void CFloatingDockContainer::hideAndDeleteLater() +{ + // Widget has been redocked, so it must be hidden right way (see + // https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/issues/351) + // but AutoHideChildren must be set to false because "this" still contains + // dock widgets that shall not be toggled hidden. + d->AutoHideChildren = false; + hide(); + deleteLater(); +} + +//============================================================================ +void CFloatingDockContainer::finishDragging() +{ + ADS_PRINT("CFloatingDockContainer::finishDragging"); +#ifdef Q_OS_LINUX + setWindowOpacity(1); + activateWindow(); + if (d->MouseEventHandler) + { + d->MouseEventHandler->releaseMouse(); + d->MouseEventHandler = nullptr; + } +#endif + d->titleMouseReleaseEvent(); +} + +#ifdef Q_OS_MACOS +//============================================================================ +bool CFloatingDockContainer::event(QEvent *e) +{ + switch (d->DraggingState) + { + case DraggingInactive: + { + // Normally we would check here, if the left mouse button is pressed. + // But from QT version 5.12.2 on the mouse events from + // QEvent::NonClientAreaMouseButtonPress return the wrong mouse button + // The event always returns Qt::RightButton even if the left button + // is clicked. + // It is really great to work around the whole NonClientMouseArea + // bugs +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 2)) + if (e->type() == QEvent::NonClientAreaMouseButtonPress /*&& QGuiApplication::mouseButtons().testFlag(Qt::LeftButton)*/) +#else + if (e->type() == QEvent::NonClientAreaMouseButtonPress && QGuiApplication::mouseButtons().testFlag(Qt::LeftButton)) +#endif + { + ADS_PRINT("FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type()); + d->DragStartPos = pos(); + d->setState(DraggingMousePressed); + } + } + break; + + case DraggingMousePressed: + switch (e->type()) + { + case QEvent::NonClientAreaMouseButtonDblClick: + ADS_PRINT("FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick"); + d->setState(DraggingInactive); + break; + + case QEvent::Resize: + // If the first event after the mouse press is a resize event, then + // the user resizes the window instead of dragging it around. + // But there is one exception. If the window is maximized, + // then dragging the window via title bar will cause the widget to + // leave the maximized state. This in turn will trigger a resize event. + // To know, if the resize event was triggered by user via moving a + // corner of the window frame or if it was caused by a windows state + // change, we check, if we are not in maximized state. + if (!isMaximized()) + { + d->setState(DraggingInactive); + } + break; + + default: + break; + } + break; + + case DraggingFloatingWidget: + if (e->type() == QEvent::NonClientAreaMouseButtonRelease) + { + ADS_PRINT("FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease"); + d->titleMouseReleaseEvent(); + } + break; + + default: + break; + } + +#if (ADS_DEBUG_LEVEL > 0) + qDebug() << QTime::currentTime() << "CFloatingDockContainer::event " << e->type(); +#endif + return QWidget::event(e); +} + + +//============================================================================ +void CFloatingDockContainer::moveEvent(QMoveEvent *event) +{ + QWidget::moveEvent(event); + switch (d->DraggingState) + { + case DraggingMousePressed: + d->setState(DraggingFloatingWidget); + d->updateDropOverlays(QCursor::pos()); + break; + + case DraggingFloatingWidget: + d->updateDropOverlays(QCursor::pos()); + // In OSX when hiding the DockAreaOverlay the application would set + // the main window as the active window for some reason. This fixes + // that by resetting the active window to the floating widget after + // updating the overlays. + QApplication::setActiveWindow(this); + break; + default: + break; + } + + +} +#endif + + +#ifdef Q_OS_LINUX +//============================================================================ +void CFloatingDockContainer::onMaximizeRequest() +{ + if (windowState() == Qt::WindowMaximized) + { + showNormal(); + } + else + { + showMaximized(); + } +} + + +//============================================================================ +void CFloatingDockContainer::showNormal(bool fixGeometry) +{ + if (windowState() == Qt::WindowMaximized) + { + QRect oldNormal = normalGeometry(); + Super::showNormal(); + if(fixGeometry) + { + setGeometry(oldNormal); + } + } + if(d->TitleBar) + { + d->TitleBar->setMaximizedIcon(false); + } +} + + +//============================================================================ +void CFloatingDockContainer::showMaximized() +{ + Super::showMaximized(); + if (d->TitleBar) + { + d->TitleBar->setMaximizedIcon(true); + } +} + + +//============================================================================ +bool CFloatingDockContainer::isMaximized() const +{ + return windowState() == Qt::WindowMaximized; +} + + +//============================================================================ +void CFloatingDockContainer::show() +{ + // Prevent this window from showing in the taskbar and pager (alt+tab) + internal::xcb_add_prop(true, winId(), "_NET_WM_STATE", "_NET_WM_STATE_SKIP_TASKBAR"); + internal::xcb_add_prop(true, winId(), "_NET_WM_STATE", "_NET_WM_STATE_SKIP_PAGER"); + Super::show(); +} + + +//============================================================================ +void CFloatingDockContainer::resizeEvent(QResizeEvent *event) +{ + d->IsResizing = true; + Super::resizeEvent(event); +} + +static bool s_mousePressed = false; +//============================================================================ +void CFloatingDockContainer::moveEvent(QMoveEvent *event) +{ + Super::moveEvent(event); + if (!d->IsResizing && event->spontaneous() && s_mousePressed) + { + d->DraggingState = DraggingFloatingWidget; + d->updateDropOverlays(QCursor::pos()); + } + d->IsResizing = false; +} + +//============================================================================ +bool CFloatingDockContainer::event(QEvent *e) +{ + bool result = Super::event(e); + switch (e->type()) + { + case QEvent::WindowActivate: + s_mousePressed = false; + break; + case QEvent::WindowDeactivate: + s_mousePressed = true; + break; + default: + break; + } + return result; +} + +//============================================================================ +bool CFloatingDockContainer::hasNativeTitleBar() +{ + return d->TitleBar == nullptr; +} +#endif + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF FloatingDockContainer.cpp diff --git a/ads/FloatingDockContainer.h b/ads/FloatingDockContainer.h new file mode 100644 index 0000000..ea27d6a --- /dev/null +++ b/ads/FloatingDockContainer.h @@ -0,0 +1,308 @@ +#ifndef FloatingDockContainerH +#define FloatingDockContainerH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file FloatingDockContainer.h +/// \author Uwe Kindler +/// \date 01.03.2017 +/// \brief Declaration of CFloatingDockContainer class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "ads_globals.h" + +#include + +#ifdef Q_OS_LINUX +#include +#define tFloatingWidgetBase QDockWidget +#else +#include +#define tFloatingWidgetBase QWidget +#endif + +class CDockingStateReader; + +namespace ads +{ +struct FloatingDockContainerPrivate; +class CDockManager; +struct DockManagerPrivate; +class CDockAreaWidget; +class CDockContainerWidget; +class CDockWidget; +class CDockManager; +class CDockAreaTabBar; +class CDockWidgetTab; +struct DockWidgetTabPrivate; +class CDockAreaTitleBar; +struct DockAreaTitleBarPrivate; +class CFloatingWidgetTitleBar; +class CDockingStateReader; + +/** + * Pure virtual interface for floating widgets. + * This interface is used for opaque and non-opaque undocking. If opaque + * undocking is used, the a real CFloatingDockContainer widget will be created + */ +class ADS_EXPORT IFloatingWidget +{ +public: + virtual ~IFloatingWidget() = default; + + /** + * Starts floating. + * This function should get called typically from a mouse press event + * handler + */ + virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size, + eDragState DragState, QWidget* MouseEventHandler) = 0; + + /** + * Moves the widget to a new position relative to the position given when + * startFloating() was called. + * This function should be called from a mouse mouve event handler to + * move the floating widget on mouse move events. + */ + virtual void moveFloating() = 0; + + /** + * Tells the widget that to finish dragging if the mouse is released. + * This function should be called from a mouse release event handler + * to finish the dragging + */ + virtual void finishDragging() = 0; +}; + + +/** + * This implements a floating widget that is a dock container that accepts + * docking of dock widgets like the main window and that can be docked into + * another dock container. + * Every floating window of the docking system is a FloatingDockContainer. + */ +class ADS_EXPORT CFloatingDockContainer : public tFloatingWidgetBase, public IFloatingWidget +{ + Q_OBJECT +private: + FloatingDockContainerPrivate* d; ///< private data (pimpl) + friend struct FloatingDockContainerPrivate; + friend class CDockManager; + friend struct DockManagerPrivate; + friend class CDockAreaTabBar; + friend struct DockWidgetTabPrivate; + friend class CDockWidgetTab; + friend class CDockAreaTitleBar; + friend struct DockAreaTitleBarPrivate; + friend class CDockWidget; + friend class CDockAreaWidget; + friend class CFloatingWidgetTitleBar; + +private Q_SLOTS: + void onDockAreasAddedOrRemoved(); + void onDockAreaCurrentChanged(int Index); + +protected: + /** + * Starts floating at the given global position. + * Use moveToGlobalPos() to move the widget to a new position + * depending on the start position given in Pos parameter + */ + virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size, + eDragState DragState, QWidget* MouseEventHandler) override; + + /** + * Call this function to start dragging the floating widget + */ + void startDragging(const QPoint& DragStartMousePos, const QSize& Size, + QWidget* MouseEventHandler) + { + startFloating(DragStartMousePos, Size, DraggingFloatingWidget, MouseEventHandler); + } + + /** + * Call this function if you explicitly want to signal that dragging has + * finished + */ + virtual void finishDragging() override; + + /** + * Call this function if you just want to initialize the position + * and size of the floating widget + */ + void initFloatingGeometry(const QPoint& DragStartMousePos, const QSize& Size) + { + startFloating(DragStartMousePos, Size, DraggingInactive, nullptr); + } + + /** + * Moves the widget to a new position relative to the position given when + * startFloating() was called + */ + void moveFloating() override; + + /** + * Restores the state from given stream. + * If Testing is true, the function only parses the data from the given + * stream but does not restore anything. You can use this check for + * faulty files before you start restoring the state + */ + bool restoreState(CDockingStateReader& Stream, bool Testing); + + /** + * Call this function to update the window title + */ + void updateWindowTitle(); + +protected: // reimplements QWidget + virtual void changeEvent(QEvent *event) override; + virtual void closeEvent(QCloseEvent *event) override; + virtual void hideEvent(QHideEvent *event) override; + virtual void showEvent(QShowEvent *event) override; + +#ifdef Q_OS_MACOS + virtual bool event(QEvent *e) override; + virtual void moveEvent(QMoveEvent *event) override; +#endif + +#ifdef Q_OS_LINUX + virtual void moveEvent(QMoveEvent *event) override; + virtual void resizeEvent(QResizeEvent *event) override; + virtual bool event(QEvent *e) override; +#endif + +#ifdef Q_OS_WIN + /** + * Native event filter for handling WM_MOVING messages on Windows + */ +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; +#else + virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override; +#endif +#endif + + +public: + using Super = tFloatingWidgetBase; + + /** + * Create empty floating widget - required for restore state + */ + CFloatingDockContainer(CDockManager* DockManager); + + /** + * Create floating widget with the given dock area + */ + CFloatingDockContainer(CDockAreaWidget* DockArea); + + /** + * Create floating widget with the given dock widget + */ + CFloatingDockContainer(CDockWidget* DockWidget); + + /** + * Virtual Destructor + */ + virtual ~CFloatingDockContainer(); + + /** + * Access function for the internal dock container + */ + CDockContainerWidget* dockContainer() const; + + /** + * This function returns true, if it can be closed. + * It can be closed, if all dock widgets in all dock areas can be closed + */ + bool isClosable() const; + + /** + * This function returns true, if this floating widget has only one single + * visible dock widget in a single visible dock area. + * The single dock widget is a real top level floating widget because no + * other widgets are docked. + */ + bool hasTopLevelDockWidget() const; + + /** + * This function returns the first dock widget in the first dock area. + * If the function hasSingleDockWidget() returns true, then this function + * returns this single dock widget. + */ + CDockWidget* topLevelDockWidget() const; + + /** + * This function returns a list of all dock widget in this floating widget. + * This is a simple convenience function that simply calls the dockWidgets() + * function of the internal container widget. + */ + QList dockWidgets() const; + + /** + * This function hides the floating bar instantely and delete it later. + */ + void hideAndDeleteLater(); + +#ifdef Q_OS_LINUX + /** + * This is a function that responds to FloatingWidgetTitleBar::maximizeRequest() + * Maximize or normalize the container size. + */ + void onMaximizeRequest(); + + /** + * Normalize (Unmaximize) the window. + * fixGeometry parameter fixes a "bug" in QT where immediately after calling showNormal + * geometry is not set properly. + * Set this true when moving the window immediately after normalizing. + */ + void showNormal(bool fixGeometry=false); + + /** + * Maximizes the window. + */ + void showMaximized(); + + /** + * Returns if the window is currently maximized or not. + */ + bool isMaximized() const; + + /** + * Patched show to prevent the window from appearing in the taskbar. + */ + void show(); + + /** + * Returns true if the floating widget has a native titlebar or false if + * the floating widget has a QWidget based title bar + */ + bool hasNativeTitleBar(); +#endif + +}; // class FloatingDockContainer +} + // namespace ads +//----------------------------------------------------------------------------- +#endif // FloatingDockContainerH diff --git a/ads/FloatingDragPreview.cpp b/ads/FloatingDragPreview.cpp new file mode 100644 index 0000000..c6ceb1a --- /dev/null +++ b/ads/FloatingDragPreview.cpp @@ -0,0 +1,423 @@ +//============================================================================ +/// \file FloatingDragPreview.cpp +/// \author Uwe Kindler +/// \date 26.11.2019 +/// \brief Implementation of CFloatingDragPreview +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "FloatingDragPreview.h" +#include + +#include +#include +#include +#include + +#include "DockWidget.h" +#include "DockAreaWidget.h" +#include "DockManager.h" +#include "DockContainerWidget.h" +#include "DockOverlay.h" + +namespace ads +{ + +/** + * Private data class (pimpl) + */ +struct FloatingDragPreviewPrivate +{ + CFloatingDragPreview *_this; + QWidget* Content; + CDockAreaWidget* ContentSourceArea = nullptr; + QPoint DragStartMousePosition; + CDockManager* DockManager; + CDockContainerWidget *DropContainer = nullptr; + qreal WindowOpacity; + bool Hidden = false; + QPixmap ContentPreviewPixmap; + bool Canceled = false; + + + /** + * Private data constructor + */ + FloatingDragPreviewPrivate(CFloatingDragPreview *_public); + void updateDropOverlays(const QPoint &GlobalPos); + + void setHidden(bool Value) + { + Hidden = Value; + _this->update(); + } + + /** + * Cancel dragging and emit the draggingCanceled event + */ + void cancelDragging() + { + Canceled = true; + Q_EMIT _this->draggingCanceled(); + DockManager->containerOverlay()->hideOverlay(); + DockManager->dockAreaOverlay()->hideOverlay(); + _this->close(); + } + + /** + * Creates the real floating widget in case the mouse is released outside + * outside of any drop area + */ + void createFloatingWidget(); +}; +// struct LedArrayPanelPrivate + + +//============================================================================ +void FloatingDragPreviewPrivate::updateDropOverlays(const QPoint &GlobalPos) +{ + if (!_this->isVisible() || !DockManager) + { + return; + } + + auto Containers = DockManager->dockContainers(); + CDockContainerWidget *TopContainer = nullptr; + for (auto ContainerWidget : Containers) + { + if (!ContainerWidget->isVisible()) + { + continue; + } + + QPoint MappedPos = ContainerWidget->mapFromGlobal(GlobalPos); + if (ContainerWidget->rect().contains(MappedPos)) + { + if (!TopContainer || ContainerWidget->isInFrontOf(TopContainer)) + { + TopContainer = ContainerWidget; + } + } + } + + DropContainer = TopContainer; + auto ContainerOverlay = DockManager->containerOverlay(); + auto DockAreaOverlay = DockManager->dockAreaOverlay(); + auto DockDropArea = DockAreaOverlay->dropAreaUnderCursor(); + auto ContainerDropArea = ContainerOverlay->dropAreaUnderCursor(); + + if (!TopContainer) + { + ContainerOverlay->hideOverlay(); + DockAreaOverlay->hideOverlay(); + if (CDockManager::testConfigFlag(CDockManager::DragPreviewIsDynamic)) + { + setHidden(false); + } + return; + } + + int VisibleDockAreas = TopContainer->visibleDockAreaCount(); + ContainerOverlay->setAllowedAreas( + VisibleDockAreas > 1 ? OuterDockAreas : AllDockAreas); + auto DockArea = TopContainer->dockAreaAt(GlobalPos); + if (DockArea && DockArea->isVisible() && VisibleDockAreas >= 0 && DockArea != ContentSourceArea) + { + DockAreaOverlay->enableDropPreview(true); + DockAreaOverlay->setAllowedAreas( + (VisibleDockAreas == 1) ? NoDockWidgetArea : DockArea->allowedAreas()); + DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea); + + // A CenterDockWidgetArea for the dockAreaOverlay() indicates that + // the mouse is in the title bar. If the ContainerArea is valid + // then we ignore the dock area of the dockAreaOverlay() and disable + // the drop preview + if ((Area == CenterDockWidgetArea) && (ContainerDropArea != InvalidDockWidgetArea)) + { + DockAreaOverlay->enableDropPreview(false); + ContainerOverlay->enableDropPreview(true); + } + else + { + ContainerOverlay->enableDropPreview(InvalidDockWidgetArea == Area); + } + ContainerOverlay->showOverlay(TopContainer); + } + else + { + DockAreaOverlay->hideOverlay(); + // If there is only one single visible dock area in a container, then + // it does not make sense to show a dock overlay because the dock area + // would be removed and inserted at the same position + if (VisibleDockAreas == 1) + { + ContainerOverlay->hideOverlay(); + } + else + { + ContainerOverlay->showOverlay(TopContainer); + } + + + if (DockArea == ContentSourceArea && InvalidDockWidgetArea == ContainerDropArea) + { + DropContainer = nullptr; + } + } + + if (CDockManager::testConfigFlag(CDockManager::DragPreviewIsDynamic)) + { + setHidden(DockDropArea != InvalidDockWidgetArea || ContainerDropArea != InvalidDockWidgetArea); + } +} + + +//============================================================================ +FloatingDragPreviewPrivate::FloatingDragPreviewPrivate(CFloatingDragPreview *_public) : + _this(_public) +{ + +} + + +//============================================================================ +void FloatingDragPreviewPrivate::createFloatingWidget() +{ + CDockWidget* DockWidget = qobject_cast(Content); + CDockAreaWidget* DockArea = qobject_cast(Content); + + CFloatingDockContainer* FloatingWidget = nullptr; + + if (DockWidget && DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) + { + FloatingWidget = new CFloatingDockContainer(DockWidget); + } + else if (DockArea && DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)) + { + FloatingWidget = new CFloatingDockContainer(DockArea); + } + + if (FloatingWidget) + { + FloatingWidget->setGeometry(_this->geometry()); + FloatingWidget->show(); + if (!CDockManager::testConfigFlag(CDockManager::DragPreviewHasWindowFrame)) + { + QApplication::processEvents(); + int FrameHeight = FloatingWidget->frameGeometry().height() - FloatingWidget->geometry().height(); + QRect FixedGeometry = _this->geometry(); + FixedGeometry.adjust(0, FrameHeight, 0, 0); + FloatingWidget->setGeometry(FixedGeometry); + } + } +} + + +//============================================================================ +CFloatingDragPreview::CFloatingDragPreview(QWidget* Content, QWidget* parent) : + QWidget(parent), + d(new FloatingDragPreviewPrivate(this)) +{ + d->Content = Content; + setAttribute(Qt::WA_DeleteOnClose); + if (CDockManager::testConfigFlag(CDockManager::DragPreviewHasWindowFrame)) + { + setWindowFlags( + Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint); + } + else + { + setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); + setAttribute(Qt::WA_NoSystemBackground); + setAttribute(Qt::WA_TranslucentBackground); + } + +#ifdef Q_OS_LINUX + auto Flags = windowFlags(); + Flags |= Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint; + setWindowFlags(Flags); +#endif + + setWindowOpacity(0.6); + + // Create a static image of the widget that should get undocked + // This is like some kind preview image like it is uses in drag and drop + // operations + if (CDockManager::testConfigFlag(CDockManager::DragPreviewShowsContentPixmap)) + { + d->ContentPreviewPixmap = QPixmap(Content->size()); + Content->render(&d->ContentPreviewPixmap); + } + + connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), + SLOT(onApplicationStateChanged(Qt::ApplicationState))); + + // The only safe way to receive escape key presses is to install an event + // filter for the application object + qApp->installEventFilter(this); +} + + +//============================================================================ +CFloatingDragPreview::CFloatingDragPreview(CDockWidget* Content) + : CFloatingDragPreview((QWidget*)Content, Content->dockManager()) +{ + d->DockManager = Content->dockManager(); + if (Content->dockAreaWidget()->openDockWidgetsCount() == 1) + { + d->ContentSourceArea = Content->dockAreaWidget(); + } + setWindowTitle(Content->windowTitle()); +} + + +//============================================================================ +CFloatingDragPreview::CFloatingDragPreview(CDockAreaWidget* Content) + : CFloatingDragPreview((QWidget*)Content, Content->dockManager()) +{ + d->DockManager = Content->dockManager(); + d->ContentSourceArea = Content; + setWindowTitle(Content->currentDockWidget()->windowTitle()); +} + + +//============================================================================ +CFloatingDragPreview::~CFloatingDragPreview() +{ + delete d; +} + + +//============================================================================ +void CFloatingDragPreview::moveFloating() +{ + int BorderSize = (frameSize().width() - size().width()) / 2; + const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition + - QPoint(BorderSize, 0); + move(moveToPos); + d->updateDropOverlays(QCursor::pos()); +} + + +//============================================================================ +void CFloatingDragPreview::startFloating(const QPoint &DragStartMousePos, + const QSize &Size, eDragState DragState, QWidget *MouseEventHandler) +{ + Q_UNUSED(MouseEventHandler) + Q_UNUSED(DragState) + resize(Size); + d->DragStartMousePosition = DragStartMousePos; + moveFloating(); + show(); + +} + + +//============================================================================ +void CFloatingDragPreview::finishDragging() +{ + ADS_PRINT("CFloatingDragPreview::finishDragging"); + auto DockDropArea = d->DockManager->dockAreaOverlay()->visibleDropAreaUnderCursor(); + auto ContainerDropArea = d->DockManager->containerOverlay()->visibleDropAreaUnderCursor(); + if (!d->DropContainer) + { + d->createFloatingWidget(); + } + else if (DockDropArea != InvalidDockWidgetArea) + { + d->DropContainer->dropWidget(d->Content, DockDropArea, d->DropContainer->dockAreaAt(QCursor::pos())); + } + else if (ContainerDropArea != InvalidDockWidgetArea) + { + // If there is only one single dock area, and we drop into the center + // then we tabify the dropped widget into the only visible dock area + if (d->DropContainer->visibleDockAreaCount() <= 1 && CenterDockWidgetArea == ContainerDropArea) + { + d->DropContainer->dropWidget(d->Content, ContainerDropArea, d->DropContainer->dockAreaAt(QCursor::pos())); + } + else + { + d->DropContainer->dropWidget(d->Content, ContainerDropArea, nullptr); + } + } + else + { + d->createFloatingWidget(); + } + + this->close(); + d->DockManager->containerOverlay()->hideOverlay(); + d->DockManager->dockAreaOverlay()->hideOverlay(); +} + + +//============================================================================ +void CFloatingDragPreview::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + if (d->Hidden) + { + return; + } + + QPainter painter(this); + if (CDockManager::testConfigFlag(CDockManager::DragPreviewShowsContentPixmap)) + { + painter.drawPixmap(QPoint(0, 0), d->ContentPreviewPixmap); + } + + // If we do not have a window frame then we paint a QRubberBand like + // frameless window + if (!CDockManager::testConfigFlag(CDockManager::DragPreviewHasWindowFrame)) + { + QColor Color = palette().color(QPalette::Active, QPalette::Highlight); + QPen Pen = painter.pen(); + Pen.setColor(Color.darker(120)); + Pen.setStyle(Qt::SolidLine); + Pen.setWidth(1); + Pen.setCosmetic(true); + painter.setPen(Pen); + Color = Color.lighter(130); + Color.setAlpha(64); + painter.setBrush(Color); + painter.drawRect(rect().adjusted(0, 0, -1, -1)); + } +} + +//============================================================================ +void CFloatingDragPreview::onApplicationStateChanged(Qt::ApplicationState state) +{ + if (state != Qt::ApplicationActive) + { + disconnect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), + this, SLOT(onApplicationStateChanged(Qt::ApplicationState))); + d->cancelDragging(); + } +} + + +//============================================================================ +bool CFloatingDragPreview::eventFilter(QObject *watched, QEvent *event) +{ + Q_UNUSED(watched); + if (!d->Canceled && event->type() == QEvent::KeyPress) + { + QKeyEvent* e = static_cast(event); + if (e->key() == Qt::Key_Escape) + { + watched->removeEventFilter(this); + d->cancelDragging(); + } + } + + return false; +} + + + +} // namespace ads + +//--------------------------------------------------------------------------- +// EOF FloatingDragPreview.cpp diff --git a/ads/FloatingDragPreview.h b/ads/FloatingDragPreview.h new file mode 100644 index 0000000..3822480 --- /dev/null +++ b/ads/FloatingDragPreview.h @@ -0,0 +1,108 @@ +#ifndef FloatingDragPreviewH +#define FloatingDragPreviewH +//============================================================================ +/// \file FloatingDragPreview.h +/// \author Uwe Kindler +/// \date 26.11.2019 +/// \brief Declaration of CFloatingDragPreview +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include "FloatingDockContainer.h" + +namespace ads +{ +class CDockWidget; +class CDockAreaWidget; +struct FloatingDragPreviewPrivate; + +/** + * A floating overlay is a temporary floating widget that is just used to + * indicate the floating widget movement. + * This widget is used as a placeholder for drag operations for non-opaque + * docking + */ +class CFloatingDragPreview : public QWidget, public IFloatingWidget +{ + Q_OBJECT +private: + FloatingDragPreviewPrivate* d; + friend struct FloatingDragPreviewPrivate; + +private Q_SLOTS: + /** + * Cancel non opaque undocking if application becomes inactive + */ + void onApplicationStateChanged(Qt::ApplicationState state); + +protected: + /** + * Cares about painting the + */ + virtual void paintEvent(QPaintEvent *e) override; + + /** + * The content is a DockArea or a DockWidget + */ + CFloatingDragPreview(QWidget* Content, QWidget* parent); + +public: + using Super = QWidget; + + /** + * Creates an instance for undocking the DockWidget in Content parameter + */ + CFloatingDragPreview(CDockWidget* Content); + + /** + * Creates an instance for undocking the DockArea given in Content + * parameters + */ + CFloatingDragPreview(CDockAreaWidget* Content); + + /** + * Delete private data + */ + ~CFloatingDragPreview(); + + /** + * We filter the events of the assigned content widget to receive + * escape key presses for canceling the drag operation + */ + virtual bool eventFilter(QObject *watched, QEvent *event) override; + + +public: // implements IFloatingWidget ----------------------------------------- + virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size, + eDragState DragState, QWidget* MouseEventHandler) override; + + /** + * Moves the widget to a new position relative to the position given when + * startFloating() was called + */ + virtual void moveFloating() override; + + /** + * Finishes dragging. + * Hides the dock overlays and executes the real undocking and docking + * of the assigned Content widget + */ + virtual void finishDragging() override; + +Q_SIGNALS: + /** + * This signal is emitted, if dragging has been canceled by escape key + * or by active application switching via task manager + */ + void draggingCanceled(); +}; + + +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // FloatingDragPreviewH + diff --git a/ads/IconProvider.cpp b/ads/IconProvider.cpp new file mode 100644 index 0000000..25e7be1 --- /dev/null +++ b/ads/IconProvider.cpp @@ -0,0 +1,73 @@ +//============================================================================ +/// \file IconProvider.cpp +/// \author Uwe Kindler +/// \date 18.10.2019 +/// \brief Implementation of CIconProvider +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "IconProvider.h" +#include + +namespace ads +{ +/** + * Private data class (pimpl) + */ +struct IconProviderPrivate +{ + CIconProvider *_this; + QVector UserIcons{IconCount, QIcon()}; + + /** + * Private data constructor + */ + IconProviderPrivate(CIconProvider *_public); +}; +// struct LedArrayPanelPrivate + +//============================================================================ +IconProviderPrivate::IconProviderPrivate(CIconProvider *_public) : + _this(_public) +{ + +} + +//============================================================================ +CIconProvider::CIconProvider() : + d(new IconProviderPrivate(this)) +{ + +} + +//============================================================================ +CIconProvider::~CIconProvider() +{ + delete d; +} + + +//============================================================================ +QIcon CIconProvider::customIcon(eIcon IconId) const +{ + Q_ASSERT(IconId < d->UserIcons.size()); + return d->UserIcons[IconId]; +} + + +//============================================================================ +void CIconProvider::registerCustomIcon(eIcon IconId, const QIcon &icon) +{ + Q_ASSERT(IconId < d->UserIcons.size()); + d->UserIcons[IconId] = icon; +} + +} // namespace ads + + + + +//--------------------------------------------------------------------------- +// EOF IconProvider.cpp diff --git a/ads/IconProvider.h b/ads/IconProvider.h new file mode 100644 index 0000000..fa7d150 --- /dev/null +++ b/ads/IconProvider.h @@ -0,0 +1,61 @@ +#ifndef IconProviderH +#define IconProviderH +//============================================================================ +/// \file IconProvider.h +/// \author Uwe Kindler +/// \date 18.10.2019 +/// \brief Declaration of CIconProvider +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include + +#include "ads_globals.h" + +namespace ads +{ + +struct IconProviderPrivate; + +/** + * This object provides all icons that are required by the advanced docking + * system. + * The IconProvider enables the user to register custom icons in case using + * stylesheets is not an option. + */ +class ADS_EXPORT CIconProvider +{ +private: + IconProviderPrivate* d; ///< private data (pimpl) + friend struct IconProviderPrivate; + +public: + /** + * Default Constructor + */ + CIconProvider(); + + /** + * Virtual Destructor + */ + virtual ~CIconProvider(); + + /** + * The function returns a custom icon if one is registered and a null Icon + * if no custom icon is registered + */ + QIcon customIcon(eIcon IconId) const; + + /** + * Registers a custom icon for the given IconId + */ + void registerCustomIcon(eIcon IconId, const QIcon &icon); +}; // class IconProvider + +} // namespace ads + + +//--------------------------------------------------------------------------- +#endif // IconProviderH diff --git a/ads/ads.qrc b/ads/ads.qrc new file mode 100644 index 0000000..a29a542 --- /dev/null +++ b/ads/ads.qrc @@ -0,0 +1,18 @@ + + + stylesheets/default.css + images/close-button.svg + images/close-button-disabled.svg + stylesheets/default_linux.css + images/close-button-focused.svg + stylesheets/focus_highlighting.css + stylesheets/focus_highlighting_linux.css + images/tabs-menu-button.svg + images/detach-button.svg + images/detach-button-disabled.svg + images/maximize-button.svg + images/maximize-button-focused.svg + images/restore-button.svg + images/restore-button-focused.svg + + diff --git a/ads/ads_globals.cpp b/ads/ads_globals.cpp new file mode 100644 index 0000000..8eca159 --- /dev/null +++ b/ads/ads_globals.cpp @@ -0,0 +1,415 @@ +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file ads_globals.cpp +/// \author Uwe Kindler +/// \date 24.02.2017 +/// \brief Implementation of +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include +#include +#include + +#include "DockSplitter.h" +#include "DockManager.h" +#include "IconProvider.h" +#include "ads_globals.h" + +#ifdef Q_OS_LINUX +#include +#include +#include +#include +#endif + +namespace ads +{ + +namespace internal +{ +#ifdef Q_OS_LINUX +static QString _window_manager; +static QHash _xcb_atom_cache; + + +//============================================================================ + bool is_platform_x11() +{ + return QGuiApplication::platformName() == QLatin1String("xcb"); +} + + +//============================================================================ +xcb_connection_t* x11_connection() +{ + if (!qApp) + return nullptr; + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return nullptr; + + void *connection = native->nativeResourceForIntegration(QByteArray("connection")); + return reinterpret_cast(connection); +} + + +//============================================================================ +xcb_atom_t xcb_get_atom(const char *name) +{ + if (!is_platform_x11()) + { + return XCB_ATOM_NONE; + } + auto key = QString(name); + if(_xcb_atom_cache.contains(key)) + { + return _xcb_atom_cache[key]; + } + xcb_connection_t *connection = x11_connection(); + xcb_intern_atom_cookie_t request = xcb_intern_atom(connection, 1, strlen(name), name); + xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, request, NULL); + if (!reply) + { + return XCB_ATOM_NONE; + } + xcb_atom_t atom = reply->atom; + if(atom == XCB_ATOM_NONE) + { + ADS_PRINT("Unknown Atom response from XServer: " << name); + } + else + { + _xcb_atom_cache.insert(key, atom); + } + free(reply); + return atom; +} + + +//============================================================================ +void xcb_update_prop(bool set, WId window, const char *type, const char *prop, const char *prop2) +{ + auto connection = x11_connection(); + xcb_atom_t type_atom = xcb_get_atom(type); + xcb_atom_t prop_atom = xcb_get_atom(prop); + xcb_client_message_event_t event; + event.response_type = XCB_CLIENT_MESSAGE; + event.format = 32; + event.sequence = 0; + event.window = window; + event.type = type_atom; + event.data.data32[0] = set ? 1 : 0; + event.data.data32[1] = prop_atom; + event.data.data32[2] = prop2 ? xcb_get_atom(prop2) : 0; + event.data.data32[3] = 0; + event.data.data32[4] = 0; + + xcb_send_event(connection, 0, window, + XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_PROPERTY_CHANGE, + (const char *)&event); + xcb_flush(connection); +} + + +//============================================================================ +xcb_get_property_reply_t* _xcb_get_props(WId window, const char *type, unsigned int atom_type) +{ + if (!is_platform_x11()) + { + return nullptr; + } + xcb_connection_t *connection = x11_connection(); + xcb_atom_t type_atom = xcb_get_atom(type); + if (type_atom == XCB_ATOM_NONE) + { + return nullptr; + } + xcb_get_property_cookie_t request = xcb_get_property_unchecked(connection, 0, window, type_atom, atom_type, 0, 1024); + xcb_get_property_reply_t *reply = xcb_get_property_reply(connection, request, nullptr); + if(reply && reply->type != atom_type) + { + ADS_PRINT("ATOM TYPE MISMATCH (" << type <<"). Expected: " << atom_type << " but got " << reply->type); + free(reply); + return nullptr; + } + return reply; +} + + +//============================================================================ +template +void xcb_get_prop_list(WId window, const char *type, QVector &ret, unsigned int atom_type) +{ + xcb_get_property_reply_t *reply = _xcb_get_props(window, type, atom_type); + if (reply && reply->format == 32 && reply->type == atom_type && reply->value_len > 0) + { + const xcb_atom_t *data = static_cast(xcb_get_property_value(reply)); + ret.resize(reply->value_len); + memcpy((void *)&ret.first(), (void *)data, reply->value_len * sizeof(T)); + } + free(reply); +} + + +//============================================================================ +QString xcb_get_prop_string(WId window, const char *type) +{ + QString ret; + // try utf8 first + xcb_atom_t utf_atom = xcb_get_atom("UTF8_STRING"); + if(utf_atom != XCB_ATOM_NONE) + { + xcb_get_property_reply_t *reply = _xcb_get_props(window, type, utf_atom); + if (reply && reply->format == 8 && reply->type == utf_atom) + { + const char *value = reinterpret_cast(xcb_get_property_value(reply)); + ret = QString::fromUtf8(value, xcb_get_property_value_length(reply)); + free(reply); + return ret; + } + free(reply); + } + // Fall back to XCB_ATOM_STRING + xcb_get_property_reply_t *reply = _xcb_get_props(window, type, XCB_ATOM_STRING); + if (reply && reply->format == 8 && reply->type == XCB_ATOM_STRING) + { + const char *value = reinterpret_cast(xcb_get_property_value(reply)); + ret = QString::fromLatin1(value, xcb_get_property_value_length(reply)); + } + free(reply); + return ret; +} + + +//============================================================================ +bool xcb_dump_props(WId window, const char *type) +{ + QVector atoms; + xcb_get_prop_list(window, type, atoms, XCB_ATOM_ATOM); + qDebug() << "\n\n!!!" << type << " - " << atoms.length(); + xcb_connection_t *connection = x11_connection(); + for (auto atom : atoms) + { + auto foo = xcb_get_atom_name(connection, atom); + auto bar = xcb_get_atom_name_reply(connection, foo, nullptr); + qDebug() << "\t" << xcb_get_atom_name_name(bar); + free(bar); + } + return true; +} + + +//============================================================================ +void xcb_add_prop(bool state, WId window, const char *type, const char *prop) +{ + if (!is_platform_x11()) + { + return; + } + xcb_atom_t prop_atom = xcb_get_atom(prop); + xcb_atom_t type_atom = xcb_get_atom(type); + if (prop_atom == XCB_ATOM_NONE || type_atom == XCB_ATOM_NONE) + { + return; + } + QVector atoms; + xcb_get_prop_list(window, type, atoms, XCB_ATOM_ATOM); + int index = atoms.indexOf(prop_atom); + if (state && index == -1) + { + atoms.push_back(prop_atom); + } + else if (!state && index >= 0) + { + atoms.remove(index); + } + xcb_connection_t *connection = x11_connection(); + xcb_change_property(connection, XCB_PROP_MODE_REPLACE, window, type_atom, XCB_ATOM_ATOM, 32, atoms.count(), atoms.constData()); + xcb_flush(connection); +} + + +//============================================================================ +QString detectWindowManagerX11() +{ + // Tries to detect the windowmanager via X11. + // See: https://specifications.freedesktop.org/wm-spec/1.3/ar01s03.html#idm46018259946000 + if (!is_platform_x11()) + { + return "UNKNOWN"; + } + xcb_connection_t *connection = x11_connection(); + xcb_screen_t *first_screen = xcb_setup_roots_iterator (xcb_get_setup (connection)).data; + if(!first_screen) + { + ADS_PRINT("No screen found via XCB."); + return "UNKNOWN"; + } + // Get supporting window () + xcb_window_t root = first_screen->root; + xcb_window_t support_win = 0; + QVector sup_windows; + xcb_get_prop_list(root, "_NET_SUPPORTING_WM_CHECK", sup_windows, XCB_ATOM_WINDOW); + if(sup_windows.length() == 0) + { + // This doesn't seem to be in use anymore, but wmctrl does the same so lets play safe. + // Both XCB_ATOM_CARDINAL and XCB_ATOM_WINDOW break down to a uint32_t, so reusing sup_windows should be fine. + xcb_get_prop_list(root, "_WIN_SUPPORTING_WM_CHECK", sup_windows, XCB_ATOM_CARDINAL); + } + if(sup_windows.length() == 0) + { + ADS_PRINT("Failed to get the supporting window on non EWMH comform WM."); + return "UNKNOWN"; + } + support_win = sup_windows[0]; + QString ret = xcb_get_prop_string(support_win, "_NET_WM_NAME"); + if(ret.length() == 0) + { + ADS_PRINT("Empty WM name occured."); + return "UNKNOWN"; + } + return ret; +} + +//============================================================================ +QString windowManager() +{ + if(_window_manager.length() == 0) + { + _window_manager = detectWindowManagerX11(); + } + return _window_manager; +} +#endif + + +//============================================================================ +void replaceSplitterWidget(QSplitter* Splitter, QWidget* From, QWidget* To) +{ + int index = Splitter->indexOf(From); + From->setParent(nullptr); + Splitter->insertWidget(index, To); +} + +//============================================================================ +CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area) +{ + switch (Area) + { + case TopDockWidgetArea: return CDockInsertParam(Qt::Vertical, false); + case RightDockWidgetArea: return CDockInsertParam(Qt::Horizontal, true); + case CenterDockWidgetArea: + case BottomDockWidgetArea: return CDockInsertParam(Qt::Vertical, true); + case LeftDockWidgetArea: return CDockInsertParam(Qt::Horizontal, false); + default: CDockInsertParam(Qt::Vertical, false); + } // switch (Area) + + return CDockInsertParam(Qt::Vertical, false); +} + + +//============================================================================ +QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity) +{ + QPixmap TransparentPixmap(Source.size()); + TransparentPixmap.fill(Qt::transparent); + QPainter p(&TransparentPixmap); + p.setOpacity(Opacity); + p.drawPixmap(0, 0, Source); + return TransparentPixmap; +} + + +//============================================================================ +void hideEmptyParentSplitters(CDockSplitter* Splitter) +{ + while (Splitter && Splitter->isVisible()) + { + if (!Splitter->hasVisibleContent()) + { + Splitter->hide(); + } + Splitter = internal::findParent(Splitter); + } +} + + +//============================================================================ +void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap, + ads::eIcon CustomIconId) +{ + // First we try to use custom icons if available + QIcon Icon = CDockManager::iconProvider().customIcon(CustomIconId); + if (!Icon.isNull()) + { + Button->setIcon(Icon); + return; + } + +#ifdef Q_OS_LINUX + Button->setIcon(Button->style()->standardIcon(StandarPixmap)); +#else + // The standard icons does not look good on high DPI screens so we create + // our own "standard" icon here. + QPixmap normalPixmap = Button->style()->standardPixmap(StandarPixmap, 0, Button); + Icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled); + Icon.addPixmap(normalPixmap, QIcon::Normal); + Button->setIcon(Icon); +#endif +} + + +//============================================================================ +void repolishStyle(QWidget* w, eRepolishChildOptions Options) +{ + if (!w) + { + return; + } + w->style()->unpolish(w); + w->style()->polish(w); + + if (RepolishIgnoreChildren == Options) + { + return; + } + + QList Children = w->findChildren(QString(), + (RepolishDirectChildren == Options) ? Qt::FindDirectChildrenOnly: Qt::FindChildrenRecursively); + for (auto Widget : Children) + { + Widget->style()->unpolish(Widget); + Widget->style()->polish(Widget); + } +} + +} // namespace internal +} // namespace ads + + + +//--------------------------------------------------------------------------- +// EOF ads_globals.cpp diff --git a/ads/ads_globals.h b/ads/ads_globals.h new file mode 100644 index 0000000..777bd82 --- /dev/null +++ b/ads/ads_globals.h @@ -0,0 +1,313 @@ +#ifndef ads_globalsH +#define ads_globalsH +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file ads_globals.h +/// \author Uwe Kindler +/// \date 24.02.2017 +/// \brief Declaration of +//============================================================================ + + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_OS_LINUX +#include +#endif + +QT_FORWARD_DECLARE_CLASS(QAbstractButton) + +#ifndef ADS_STATIC +#ifdef ADS_SHARED_EXPORT +#define ADS_EXPORT Q_DECL_EXPORT +#else +#define ADS_EXPORT Q_DECL_IMPORT +#endif +#else +#define ADS_EXPORT +#endif + +// Define ADS_DEBUG_PRINT to enable a lot of debug output +#ifdef ADS_DEBUG_PRINT +#define ADS_PRINT(s) qDebug() << s +#else +#define ADS_PRINT(s) +#endif + +// Set ADS_DEBUG_LEVEL to enable additional debug output and to enable layout +// dumps to qDebug and std::cout after layout changes +#define ADS_DEBUG_LEVEL 0 + +QT_FORWARD_DECLARE_CLASS(QSplitter) + +namespace ads +{ +class CDockSplitter; + +enum DockWidgetArea +{ + NoDockWidgetArea = 0x00, + LeftDockWidgetArea = 0x01, + RightDockWidgetArea = 0x02, + TopDockWidgetArea = 0x04, + BottomDockWidgetArea = 0x08, + CenterDockWidgetArea = 0x10, + + InvalidDockWidgetArea = NoDockWidgetArea, + OuterDockAreas = TopDockWidgetArea | LeftDockWidgetArea | RightDockWidgetArea | BottomDockWidgetArea, + AllDockAreas = OuterDockAreas | CenterDockWidgetArea +}; +Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea) + + +enum TitleBarButton +{ + TitleBarButtonTabsMenu, + TitleBarButtonUndock, + TitleBarButtonClose +}; + +/** + * The different dragging states + */ +enum eDragState +{ + DraggingInactive, //!< DraggingInactive + DraggingMousePressed, //!< DraggingMousePressed + DraggingTab, //!< DraggingTab + DraggingFloatingWidget//!< DraggingFloatingWidget +}; + +/** + * The different icons used in the UI + */ +enum eIcon +{ + TabCloseIcon, //!< TabCloseIcon + DockAreaMenuIcon, //!< DockAreaMenuIcon + DockAreaUndockIcon,//!< DockAreaUndockIcon + DockAreaCloseIcon, //!< DockAreaCloseIcon + + IconCount, //!< just a delimiter for range checks +}; + +/** + * For bitwise combination of dock wdget features + */ +enum eBitwiseOperator +{ + BitwiseAnd, + BitwiseOr +}; + + +namespace internal +{ +static const bool RestoreTesting = true; +static const bool Restore = false; +static const char* const ClosedProperty = "close"; +static const char* const DirtyProperty = "dirty"; + +#ifdef Q_OS_LINUX +// Utils to directly communicate with the X server +/** + * Get atom from cache or request it from the XServer. + */ +xcb_atom_t xcb_get_atom(const char *name); + +/** + * Add a property to a window. Only works on "hidden" windows. + */ +void xcb_add_prop(bool state, WId window, const char *type, const char *prop); +/** + * Updates up to two window properties. Can be set on a visible window. + */ +void xcb_update_prop(bool set, WId window, const char *type, const char *prop, const char *prop2 = nullptr); +/** + * Only for debugging purposes. + */ +bool xcb_dump_props(WId window, const char *type); +/** + * Gets the active window manager from the X11 Server. + * Requires a EWMH conform window manager (Allmost all common used ones are). + * Returns "UNKNOWN" otherwise. + */ +QString windowManager(); +#endif + +/** + * Replace the from widget in the given splitter with the To widget + */ +void replaceSplitterWidget(QSplitter* Splitter, QWidget* From, QWidget* To); + +/** + * This function walks the splitter tree upwards to hides all splitters + * that do not have visible content + */ +void hideEmptyParentSplitters(CDockSplitter* FirstParentSplitter); + +/** + * Convenience class for QPair to provide better naming than first and + * second + */ +class CDockInsertParam : public QPair +{ +public: + using QPair::QPair; + Qt::Orientation orientation() const {return this->first;} + bool append() const {return this->second;} + int insertOffset() const {return append() ? 1 : 0;} +}; + +/** + * Returns the insertion parameters for the given dock area + */ +CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area); + +/** + * Searches for the parent widget of the given type. + * Returns the parent widget of the given widget or 0 if the widget is not + * child of any widget of type T + * + * It is not safe to use this function in in CDockWidget because only + * the current dock widget has a parent. All dock widgets that are not the + * current dock widget in a dock area have no parent. + */ +template +T findParent(const QWidget* w) +{ + QWidget* parentWidget = w->parentWidget(); + while (parentWidget) + { + T ParentImpl = qobject_cast(parentWidget); + if (ParentImpl) + { + return ParentImpl; + } + parentWidget = parentWidget->parentWidget(); + } + return 0; +} + +/** + * Creates a semi transparent pixmap from the given pixmap Source. + * The Opacity parameter defines the opacity from completely transparent (0.0) + * to completely opaque (1.0) + */ +QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity); + + +/** + * Helper function for settings flags in a QFlags instance. + */ +template +void setFlag(T& Flags, typename T::enum_type flag, bool on = true) +{ +#if QT_VERSION >= 0x050700 + Flags.setFlag(flag, on); +#else + if(on) + { + Flags |= flag; + } + else + { + Flags &= ~flag; + } +#endif +} + + +/** + * Helper function for settings tooltips without cluttering the code with + * tests for preprocessor macros + */ +template +void setToolTip(QObjectPtr obj, const QString &tip) +{ +#ifndef QT_NO_TOOLTIP + obj->setToolTip(tip); +#else + Q_UNUSED(obj); + Q_UNUSED(tip); +#endif +} + + +/** + * Helper function for access to mouse event global position in Qt5 and + */ +inline QPoint globalPositionOf(QMouseEvent* ev) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return ev->globalPosition().toPoint(); +#else + return ev->globalPos(); +#endif +} + + +/** + * Helper function to set the icon of a certain button. + * Use this function to set the icons for the dock area and dock widget buttons. + * The function first uses the CustomIconId to get an icon from the + * CIconProvider. You can register your custom icons with the icon provider, if + * you do not want to use the default buttons and if you do not want to use + * stylesheets. + * If the IconProvider does not return a valid icon (icon is null), the function + * fetches the given standard pixmap from the QStyle. + * param[in] Button The button whose icons are to be set + * param[in] StandardPixmap The standard pixmap to be used for the button + * param[in] CustomIconId The identifier for the custom icon. + */ +void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap, + ads::eIcon CustomIconId); + + +enum eRepolishChildOptions +{ + RepolishIgnoreChildren, + RepolishDirectChildren, + RepolishChildrenRecursively +}; + +/** + * Calls unpolish() / polish for the style of the given widget to update + * stylesheet if a property changes + */ +void repolishStyle(QWidget* w, eRepolishChildOptions Options = RepolishIgnoreChildren); + + +} // namespace internal +} // namespace ads + +Q_DECLARE_OPERATORS_FOR_FLAGS(ads::DockWidgetAreas) +//--------------------------------------------------------------------------- +#endif // ads_globalsH diff --git a/ads/images/close-button-disabled.svg b/ads/images/close-button-disabled.svg new file mode 100644 index 0000000..cbcf1e5 --- /dev/null +++ b/ads/images/close-button-disabled.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/images/close-button-focused.svg b/ads/images/close-button-focused.svg new file mode 100644 index 0000000..b9a6fad --- /dev/null +++ b/ads/images/close-button-focused.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/images/close-button.svg b/ads/images/close-button.svg new file mode 100644 index 0000000..c772029 --- /dev/null +++ b/ads/images/close-button.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/images/detach-button-disabled.svg b/ads/images/detach-button-disabled.svg new file mode 100644 index 0000000..3a7c082 --- /dev/null +++ b/ads/images/detach-button-disabled.svg @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + + + diff --git a/ads/images/detach-button.svg b/ads/images/detach-button.svg new file mode 100644 index 0000000..88d9bf2 --- /dev/null +++ b/ads/images/detach-button.svg @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + + diff --git a/ads/images/maximize-button-focused.svg b/ads/images/maximize-button-focused.svg new file mode 100644 index 0000000..cdbb56d --- /dev/null +++ b/ads/images/maximize-button-focused.svg @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/images/maximize-button.svg b/ads/images/maximize-button.svg new file mode 100644 index 0000000..4084eb8 --- /dev/null +++ b/ads/images/maximize-button.svg @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/images/restore-button-focused.svg b/ads/images/restore-button-focused.svg new file mode 100644 index 0000000..45b32e9 --- /dev/null +++ b/ads/images/restore-button-focused.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/images/restore-button.svg b/ads/images/restore-button.svg new file mode 100644 index 0000000..46175d4 --- /dev/null +++ b/ads/images/restore-button.svg @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/images/tabs-menu-button.svg b/ads/images/tabs-menu-button.svg new file mode 100644 index 0000000..dcd5eb2 --- /dev/null +++ b/ads/images/tabs-menu-button.svg @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Jemis Mali + + + + + image/svg+xml + + + + + + diff --git a/ads/linux/FloatingWidgetTitleBar.cpp b/ads/linux/FloatingWidgetTitleBar.cpp new file mode 100644 index 0000000..88eddc2 --- /dev/null +++ b/ads/linux/FloatingWidgetTitleBar.cpp @@ -0,0 +1,293 @@ +/******************************************************************************* + ** Qt Advanced Docking System + ** Copyright (C) 2017 Uwe Kindler + ** + ** This library is free software; you can redistribute it and/or + ** modify it under the terms of the GNU Lesser General Public + ** License as published by the Free Software Foundation; either + ** version 2.1 of the License, or (at your option) any later version. + ** + ** This library is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. + ** + ** You should have received a copy of the GNU Lesser General Public + ** License along with this library; If not, see . + ******************************************************************************/ + +//============================================================================ +/// \file FloatingWidgetTitleBar.cpp +/// \author Uwe Kindler +/// \date 13.05.2019 +/// \brief Implementation of CFloatingWidgetTitleBar class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include "FloatingWidgetTitleBar.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include "ads_globals.h" +#include "ElidingLabel.h" +#include "FloatingDockContainer.h" + +namespace ads +{ + +using tTabLabel = CElidingLabel; +using tCloseButton = QToolButton; +using tMaximizeButton = QToolButton; + +/** + * @brief Private data class of public interface CFloatingWidgetTitleBar + */ +struct FloatingWidgetTitleBarPrivate +{ + CFloatingWidgetTitleBar *_this; ///< public interface class + QLabel *IconLabel = nullptr; + tTabLabel *TitleLabel; + tCloseButton *CloseButton = nullptr; + tMaximizeButton* MaximizeButton = nullptr; + CFloatingDockContainer *FloatingWidget = nullptr; + eDragState DragState = DraggingInactive; + QIcon MaximizeIcon; + QIcon NormalIcon; + bool Maximized = false; + + FloatingWidgetTitleBarPrivate(CFloatingWidgetTitleBar *_public) : + _this(_public) + { + } + + /** + * Creates the complete layout including all controls + */ + void createLayout(); +}; + +//============================================================================ +void FloatingWidgetTitleBarPrivate::createLayout() +{ + TitleLabel = new tTabLabel(); + TitleLabel->setElideMode(Qt::ElideRight); + TitleLabel->setText("DockWidget->windowTitle()"); + TitleLabel->setObjectName("floatingTitleLabel"); + TitleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); + + CloseButton = new tCloseButton(); + CloseButton->setObjectName("floatingTitleCloseButton"); + CloseButton->setAutoRaise(true); + + MaximizeButton = new tMaximizeButton(); + MaximizeButton->setObjectName("floatingTitleMaximizeButton"); + MaximizeButton->setAutoRaise(true); + + // The standard icons do does not look good on high DPI screens + QIcon CloseIcon; + QPixmap normalPixmap = _this->style()->standardPixmap( + QStyle::SP_TitleBarCloseButton, 0, CloseButton); + CloseIcon.addPixmap(normalPixmap, QIcon::Normal); + CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), + QIcon::Disabled); + CloseButton->setIcon( + _this->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); + CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + CloseButton->setVisible(true); + CloseButton->setFocusPolicy(Qt::NoFocus); + _this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested())); + + _this->setMaximizedIcon(false); + MaximizeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + MaximizeButton->setVisible(true); + MaximizeButton->setFocusPolicy(Qt::NoFocus); + _this->connect(MaximizeButton, &QPushButton::clicked, _this, &CFloatingWidgetTitleBar::maximizeRequested); + + QFontMetrics fm(TitleLabel->font()); + int Spacing = qRound(fm.height() / 4.0); + + // Fill the layout + QBoxLayout *Layout = new QBoxLayout(QBoxLayout::LeftToRight); + Layout->setContentsMargins(6, 0, 0, 0); + Layout->setSpacing(0); + _this->setLayout(Layout); + Layout->addWidget(TitleLabel, 1); + Layout->addSpacing(Spacing); + Layout->addWidget(MaximizeButton); + Layout->addWidget(CloseButton); + Layout->setAlignment(Qt::AlignCenter); + + TitleLabel->setVisible(true); +} + +//============================================================================ +CFloatingWidgetTitleBar::CFloatingWidgetTitleBar(CFloatingDockContainer *parent) : + QFrame(parent), + d(new FloatingWidgetTitleBarPrivate(this)) +{ + d->FloatingWidget = parent; + d->createLayout(); + + auto normalPixmap = this->style()->standardPixmap(QStyle::SP_TitleBarNormalButton, 0, d->MaximizeButton); + d->NormalIcon.addPixmap(normalPixmap, QIcon::Normal); + d->NormalIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled); + + auto maxPixmap = this->style()->standardPixmap(QStyle::SP_TitleBarMaxButton, 0, d->MaximizeButton); + d->MaximizeIcon.addPixmap(maxPixmap, QIcon::Normal); + d->MaximizeIcon.addPixmap(internal::createTransparentPixmap(maxPixmap, 0.25), QIcon::Disabled); + setMaximizedIcon(d->Maximized); +} + +//============================================================================ +CFloatingWidgetTitleBar::~CFloatingWidgetTitleBar() +{ + delete d; +} + +//============================================================================ +void CFloatingWidgetTitleBar::mousePressEvent(QMouseEvent *ev) +{ + if (ev->button() == Qt::LeftButton) + { + d->DragState = DraggingFloatingWidget; + d->FloatingWidget->startDragging(ev->pos(), d->FloatingWidget->size(), + this); + return; + } + Super::mousePressEvent(ev); +} + + +//============================================================================ +void CFloatingWidgetTitleBar::mouseReleaseEvent(QMouseEvent *ev) +{ + d->DragState = DraggingInactive; + if (d->FloatingWidget) + { + d->FloatingWidget->finishDragging(); + } + Super::mouseReleaseEvent(ev); +} + + +//============================================================================ +void CFloatingWidgetTitleBar::mouseMoveEvent(QMouseEvent *ev) +{ + if (!(ev->buttons() & Qt::LeftButton) || DraggingInactive == d->DragState) + { + d->DragState = DraggingInactive; + Super::mouseMoveEvent(ev); + return; + } + + // move floating window + if (DraggingFloatingWidget == d->DragState) + { + if(d->FloatingWidget->isMaximized()) + { + d->FloatingWidget->showNormal(); + } + d->FloatingWidget->moveFloating(); + Super::mouseMoveEvent(ev); + return; + } + Super::mouseMoveEvent(ev); +} + + +//============================================================================ +void CFloatingWidgetTitleBar::enableCloseButton(bool Enable) +{ + d->CloseButton->setEnabled(Enable); +} + + +//============================================================================ +void CFloatingWidgetTitleBar::setTitle(const QString &Text) +{ + d->TitleLabel->setText(Text); +} + +//============================================================================ +void CFloatingWidgetTitleBar::updateStyle() +{ + internal::repolishStyle(this, internal::RepolishDirectChildren); +} + + +//============================================================================ +void CFloatingWidgetTitleBar::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton) + { + emit maximizeRequested(); + event->accept(); + } + else + { + QWidget::mouseDoubleClickEvent(event); + } +} + + +//============================================================================ +void CFloatingWidgetTitleBar::setMaximizedIcon(bool maximized) +{ + d->Maximized = maximized; + if (maximized) + { + d->MaximizeButton->setIcon(d->NormalIcon); + } + else + { + d->MaximizeButton->setIcon(d->MaximizeIcon); + } +} + + +//============================================================================ +void CFloatingWidgetTitleBar::setMaximizeIcon(const QIcon& Icon) +{ + d->MaximizeIcon = Icon; + if (d->Maximized) + { + setMaximizedIcon(d->Maximized); + } +} + + +//============================================================================ +void CFloatingWidgetTitleBar::setNormalIcon(const QIcon& Icon) +{ + d->NormalIcon = Icon; + if (!d->Maximized) + { + setMaximizedIcon(d->Maximized); + } +} + + +//============================================================================ +QIcon CFloatingWidgetTitleBar::maximizeIcon() const +{ + return d->MaximizeIcon; +} + + +//============================================================================ +QIcon CFloatingWidgetTitleBar::normalIcon() const +{ + return d->NormalIcon; +} + + +} // namespace ads diff --git a/ads/linux/FloatingWidgetTitleBar.h b/ads/linux/FloatingWidgetTitleBar.h new file mode 100644 index 0000000..ad6904f --- /dev/null +++ b/ads/linux/FloatingWidgetTitleBar.h @@ -0,0 +1,109 @@ +#ifndef FLOATINGWIDGETTITLEBAR_H +#define FLOATINGWIDGETTITLEBAR_H +/******************************************************************************* +** Qt Advanced Docking System +** Copyright (C) 2017 Uwe Kindler +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** version 2.1 of the License, or (at your option) any later version. +** +** This library is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; If not, see . +******************************************************************************/ + + +//============================================================================ +/// \file FloatingWidgetTitleBar.h +/// \author Uwe Kindler +/// \date 13.05.2019 +/// \brief Declaration of CFloatingWidgetTitleBar class +//============================================================================ + +//============================================================================ +// INCLUDES +//============================================================================ +#include +#include + +namespace ads +{ +class CFloatingDockContainer; + +struct FloatingWidgetTitleBarPrivate; + + +/** + * Titlebar for floating widgets to capture non client are mouse events. + * Linux does not support NonClieantArea mouse events like + * QEvent::NonClientAreaMouseButtonPress. Because these events are required + * for the docking system to work properly, we use our own titlebar here to + * capture the required mouse events. + */ +class CFloatingWidgetTitleBar : public QFrame +{ + Q_OBJECT + Q_PROPERTY(QIcon maximizeIcon READ maximizeIcon WRITE setMaximizeIcon) + Q_PROPERTY(QIcon normalIcon READ normalIcon WRITE setNormalIcon) +private: + FloatingWidgetTitleBarPrivate *d; ///< private data (pimpl) + +protected: + virtual void mousePressEvent(QMouseEvent *ev) override; + virtual void mouseReleaseEvent(QMouseEvent *ev) override; + virtual void mouseMoveEvent(QMouseEvent *ev) override; + virtual void mouseDoubleClickEvent(QMouseEvent *event) override; + + void setMaximizeIcon(const QIcon& Icon); + QIcon maximizeIcon() const; + void setNormalIcon(const QIcon& Icon); + QIcon normalIcon() const; + +public: + using Super = QWidget; + explicit CFloatingWidgetTitleBar(CFloatingDockContainer *parent = nullptr); + + /** + * Virtual Destructor + */ + virtual ~CFloatingWidgetTitleBar(); + + /** + * Enables / disables the window close button. + */ + void enableCloseButton(bool Enable); + + /** + * Sets the window title, that means, the text of the internal tile label. + */ + void setTitle(const QString &Text); + + /** + * Update stylesheet style if a property changes + */ + void updateStyle(); + + /** + * Change the maximize button icon according to current windows state + */ + void setMaximizedIcon(bool maximized); + +signals: + /** + * This signal is emitted, if the close button is clicked. + */ + void closeRequested(); + + /** + * This signal is emitted, if the maximize button is clicked. + */ + void maximizeRequested(); +}; +} // namespace ads +#endif // FLOATINGWIDGETTITLEBAR_H diff --git a/ads/qtadvanceddockingConfig.cmake b/ads/qtadvanceddockingConfig.cmake new file mode 100644 index 0000000..65173fa --- /dev/null +++ b/ads/qtadvanceddockingConfig.cmake @@ -0,0 +1,2 @@ +include(CMakeFindDependencyMacro) +include("${CMAKE_CURRENT_LIST_DIR}/adsTargets.cmake") \ No newline at end of file diff --git a/ads/src.pro b/ads/src.pro new file mode 100644 index 0000000..9f6d265 --- /dev/null +++ b/ads/src.pro @@ -0,0 +1,89 @@ +ADS_OUT_ROOT = $${OUT_PWD}/.. +CONFIG += c++14 +CONFIG += debug_and_release +TARGET = $$qtLibraryTarget(qtadvanceddocking) +DEFINES += QT_DEPRECATED_WARNINGS +TEMPLATE = lib +DESTDIR = $${ADS_OUT_ROOT}/lib +QT += core gui widgets + +!adsBuildStatic { + CONFIG += shared + DEFINES += ADS_SHARED_EXPORT +} +adsBuildStatic { + CONFIG += staticlib + DEFINES += ADS_STATIC +} + +windows { + # MinGW + *-g++* { + QMAKE_CXXFLAGS += -Wall -Wextra -pedantic + } + # MSVC + *-msvc* { + QMAKE_CXXFLAGS += /utf-8 + } +} + +RESOURCES += ads.qrc + +HEADERS += \ + ads_globals.h \ + DockAreaWidget.h \ + DockAreaTabBar.h \ + DockContainerWidget.h \ + DockManager.h \ + DockWidget.h \ + DockWidgetTab.h \ + DockingStateReader.h \ + FloatingDockContainer.h \ + FloatingDragPreview.h \ + DockOverlay.h \ + DockSplitter.h \ + DockAreaTitleBar_p.h \ + DockAreaTitleBar.h \ + ElidingLabel.h \ + IconProvider.h \ + DockComponentsFactory.h \ + DockFocusController.h + + +SOURCES += \ + ads_globals.cpp \ + DockAreaWidget.cpp \ + DockAreaTabBar.cpp \ + DockContainerWidget.cpp \ + DockManager.cpp \ + DockWidget.cpp \ + DockingStateReader.cpp \ + DockWidgetTab.cpp \ + FloatingDockContainer.cpp \ + FloatingDragPreview.cpp \ + DockOverlay.cpp \ + DockSplitter.cpp \ + DockAreaTitleBar.cpp \ + ElidingLabel.cpp \ + IconProvider.cpp \ + DockComponentsFactory.cpp \ + DockFocusController.cpp + + +unix:!macx { +HEADERS += linux/FloatingWidgetTitleBar.h +SOURCES += linux/FloatingWidgetTitleBar.cpp +LIBS += -lxcb +QT += gui-private +} + +isEmpty(PREFIX){ + PREFIX=../installed + warning("Install Prefix not set") +} +headers.path=$$PREFIX/include +headers.files=$$HEADERS +target.path=$$PREFIX/lib +INSTALLS += headers target + +DISTFILES += diff --git a/ads/stylesheets/default.css b/ads/stylesheets/default.css new file mode 100644 index 0000000..7952bd1 --- /dev/null +++ b/ads/stylesheets/default.css @@ -0,0 +1,96 @@ +/* + * Default style sheet on Windows Platforms + */ +ads--CDockContainerWidget { + background: palette(dark); +} +ads--CDockContainerWidget > QSplitter{ + padding: 1 0 1 0; +} + +ads--CDockContainerWidget ads--CDockSplitter::handle { + background: palette(dark); +} + +ads--CDockAreaWidget { + background: palette(window); + border: 1px solid white; +} + +ads--CDockWidgetTab { + background: palette(window); + border-color: palette(light); + border-style: solid; + border-width: 0 1px 0 0; + padding: 0 0px; +} + +ads--CDockWidgetTab[activeTab="true"] { + background: qlineargradient(spread : pad, x1 : 0, y1 : 0, x2 : 0, y2 : 0.5, stop : 0 + palette(window), stop:1 palette(light)); + /*background: palette(highlight);*/ +} + +ads--CDockWidgetTab QLabel { + color: palette(dark); +} + +ads--CDockWidgetTab[activeTab="true"] QLabel { + color: palette(foreground); +} + +ads--CDockWidget { + background: palette(light); + border-color: palette(light); + border-style: solid; + border-width: 1px 0 0 0; +} + +ads--CTitleBarButton { + padding: 0px 0px; +} + +QScrollArea#dockWidgetScrollArea { + padding: 0px; + border: none; +} + +#tabCloseButton { + margin-top: 2px; + background: none; + border: none; + padding: 0px -2px; + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#tabCloseButton:hover { + border: 1px solid rgba(0, 0, 0, 32); + background: rgba(0, 0, 0, 16); +} + +#tabCloseButton:pressed { + background: rgba(0, 0, 0, 32); +} + +#tabsMenuButton::menu-indicator { + image: none; +} + +#tabsMenuButton { + qproperty-icon: url(:/ads/images/tabs-menu-button.svg); + qproperty-iconSize: 16px; +} + +#dockAreaCloseButton { + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#detachGroupButton { + qproperty-icon: url(:/ads/images/detach-button.svg), + url(:/ads/images/detach-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} diff --git a/ads/stylesheets/default_linux.css b/ads/stylesheets/default_linux.css new file mode 100644 index 0000000..ac41491 --- /dev/null +++ b/ads/stylesheets/default_linux.css @@ -0,0 +1,124 @@ +/* + * Default style sheet on Linux Platforms + */ +ads--CDockContainerWidget { + background: palette(dark); +} +ads--CDockContainerWidget > QSplitter{ + padding: 1 0 1 0; +} + +ads--CDockContainerWidget ads--CDockSplitter::handle { + background: palette(dark); +} + +ads--CDockAreaWidget { + background: palette(window); + border: 1px solid white; +} + +ads--CDockAreaWidget #tabsMenuButton::menu-indicator { + image: none; +} + +ads--CDockWidgetTab { + background: palette(window); + border-color: palette(light); + border-style: solid; + border-width: 0 1px 0 0; + padding: 0 0px; +} + +ads--CDockWidgetTab[activeTab="true"] { + background: qlineargradient(spread : pad, x1 : 0, y1 : 0, x2 : 0, y2 : 0.5, stop : 0 + palette(window), stop:1 palette(light)); + /*background: palette(highlight);*/ +} + +ads--CDockWidgetTab QLabel { + color: palette(dark); +} + +ads--CDockWidgetTab[activeTab="true"] QLabel { + color: palette(foreground); +} + +ads--CDockWidget { + background: palette(light); + border-color: palette(light); + border-style: solid; + border-width: 1px 0 0 0; +} + +ads--CTitleBarButton { + padding: 0px 0px; +} + +QScrollArea#dockWidgetScrollArea { + padding: 0px; + border: none; +} + +#tabCloseButton { + margin-top: 2px; + background: none; + border: none; + padding: 0px -2px; + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#tabCloseButton:hover { + border: 1px solid rgba(0, 0, 0, 32); + background: rgba(0, 0, 0, 16); +} + +#tabCloseButton:pressed { + background: rgba(0, 0, 0, 32); +} + +#tabsMenuButton { + qproperty-icon: url(:/ads/images/tabs-menu-button.svg); + qproperty-iconSize: 16px; +} + +#dockAreaCloseButton { + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#detachGroupButton { + qproperty-icon: url(:/ads/images/detach-button.svg), + url(:/ads/images/detach-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + + +ads--CFloatingWidgetTitleBar { + background: palette(midlight); + qproperty-maximizeIcon: url(:/ads/images/maximize-button.svg); + qproperty-normalIcon: url(:/ads/images/restore-button.svg); +} + + +#floatingTitleCloseButton, #floatingTitleMaximizeButton { + qproperty-iconSize: 16px; + border: none; + margin: 3px; +} + + +#floatingTitleCloseButton { + qproperty-icon: url(:/ads/images/close-button.svg); +} + +#floatingTitleCloseButton:hover { + background: rgba(0, 0, 0, 24); + border: none; +} + +#floatingTitleCloseButton:pressed { + background: rgba(0, 0, 0, 48); +} diff --git a/ads/stylesheets/focus_highlighting.css b/ads/stylesheets/focus_highlighting.css new file mode 100644 index 0000000..5551721 --- /dev/null +++ b/ads/stylesheets/focus_highlighting.css @@ -0,0 +1,129 @@ +/* + * Default style sheet on Windows Platforms with focus highlighting flag enabled + */ +ads--CDockContainerWidget { + background: palette(dark); +} +ads--CDockContainerWidget > QSplitter{ + padding: 1 0 1 0; +} + +ads--CDockAreaWidget { + background: palette(window); + border: 1px solid white; +} + +ads--CDockWidgetTab { + background: palette(window); + border-color: palette(light); + border-style: solid; + border-width: 0 1px 0 0; + padding: 0 0px; + qproperty-iconSize: 16px 16px;/* this is optional in case you would like to change icon size*/ +} + +ads--CDockWidgetTab[activeTab="true"] { + background: qlineargradient(spread : pad, x1 : 0, y1 : 0, x2 : 0, y2 : 0.5, stop : 0 + palette(window), stop:1 palette(light)); + /*background: palette(highlight);*/ +} + +ads--CDockWidgetTab QLabel { + color: palette(dark); +} + +ads--CDockWidgetTab[activeTab="true"] QLabel { + color: palette(foreground); +} + +ads--CDockWidget { + background: palette(light); + border-color: palette(light); + border-style: solid; + border-width: 1px 0 0 0; +} + +ads--CTitleBarButton { + padding: 0px 0px; +} + +QScrollArea#dockWidgetScrollArea { + padding: 0px; + border: none; +} + +#tabsMenuButton::menu-indicator { + image: none; +} + +#tabCloseButton { + margin-top: 2px; + background: none; + border: none; + padding: 0px -2px; + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#tabCloseButton:hover { + /*border: 1px solid rgba(0, 0, 0, 32);*/ + background: rgba(0, 0, 0, 24); +} + +#tabCloseButton:pressed { + background: rgba(0, 0, 0, 48); +} + +#dockAreaCloseButton { + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#detachGroupButton { + qproperty-icon: url(:/ads/images/detach-button.svg), + url(:/ads/images/detach-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +ads--CDockSplitter::handle { + background-color: palette(dark); + /* uncomment the following line if you would like to change the size of + the splitter handles */ + /* height: 1px; */ +} + +/* Focus related styling */ +ads--CDockWidgetTab[focused="true"] { + background: palette(highlight); + border-color: palette(highlight); +} + +ads--CDockWidgetTab[focused="true"]>#tabCloseButton { + qproperty-icon: url(:/ads/images/close-button-focused.svg) +} + +ads--CDockWidgetTab[focused="true"]>#tabCloseButton:hover { + background: rgba(255, 255, 255, 48); +} + +ads--CDockWidgetTab[focused="true"]>#tabCloseButton:pressed { + background: rgba(255, 255, 255, 92); +} + +ads--CDockWidgetTab[focused="true"] QLabel { + color: palette(light); +} + +ads--CDockAreaTitleBar { + background: transparent; + border-bottom: 2px solid palette(light); + padding-bottom: 0px; +} + +ads--CDockAreaWidget[focused="true"] ads--CDockAreaTitleBar { + background: transparent; + border-bottom: 2px solid palette(highlight); + padding-bottom: 0px; +} diff --git a/ads/stylesheets/focus_highlighting_linux.css b/ads/stylesheets/focus_highlighting_linux.css new file mode 100644 index 0000000..f16ab5e --- /dev/null +++ b/ads/stylesheets/focus_highlighting_linux.css @@ -0,0 +1,199 @@ +/* + * Default style sheet on Linux Platforms with focus highlighting flag enabled + */ +ads--CDockContainerWidget { + background: palette(dark); +} +ads--CDockContainerWidget > QSplitter{ + padding: 1 0 1 0; +} + + +ads--CDockContainerWidget ads--CDockSplitter::handle { + background: palette(dark); +} + +ads--CDockAreaWidget { + background: palette(window); + border: 1px solid white; +} + +ads--CDockAreaWidget #tabsMenuButton::menu-indicator { + image: none; +} + +ads--CDockWidgetTab { + background: palette(window); + border-color: palette(light); + border-style: solid; + border-width: 0 1px 0 0; + padding: 0 0px; +} + +ads--CDockWidgetTab[activeTab="true"] { + background: qlineargradient(spread : pad, x1 : 0, y1 : 0, x2 : 0, y2 : 0.5, stop : 0 + palette(window), stop:1 palette(light)); + /*background: palette(highlight);*/ +} + +ads--CDockWidgetTab QLabel { + color: palette(dark); +} + +ads--CDockWidgetTab[activeTab="true"] QLabel { + color: palette(foreground); +} + +ads--CDockWidget { + background: palette(light); + border-color: palette(light); + border-style: solid; + border-width: 1px 0 0 0; +} + +ads--CTitleBarButton { + padding: 0px 0px; +} + +QScrollArea#dockWidgetScrollArea { + padding: 0px; + border: none; +} + +#dockAreaCloseButton { + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#detachGroupButton { + qproperty-icon: url(:/ads/images/detach-button.svg), + url(:/ads/images/detach-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#tabCloseButton { + margin-top: 2px; + background: none; + border: none; + padding: 0px -2px; + qproperty-icon: url(:/ads/images/close-button.svg), + url(:/ads/images/close-button-disabled.svg) disabled; + qproperty-iconSize: 16px; +} + +#tabCloseButton:hover { + /*border: 1px solid rgba(0, 0, 0, 32);*/ + background: rgba(0, 0, 0, 24); +} + +#tabCloseButton:pressed { + background: rgba(0, 0, 0, 48); +} + + +#tabsMenuButton { + qproperty-icon: url(:/ads/images/tabs-menu-button.svg); + qproperty-iconSize: 16px; +} + + +/* Focus related styling */ +ads--CDockWidgetTab[focused="true"] { + background: palette(highlight); + border-color: palette(highlight); +} + +ads--CDockWidgetTab[focused="true"]>#tabCloseButton { + qproperty-icon: url(:/ads/images/close-button-focused.svg) +} + +ads--CDockWidgetTab[focused="true"]>#tabCloseButton:hover { + background: rgba(255, 255, 255, 48); +} + +ads--CDockWidgetTab[focused="true"]>#tabCloseButton:pressed { + background: rgba(255, 255, 255, 92); +} + +ads--CDockWidgetTab[focused="true"] QLabel { + color: palette(light); +} + +ads--CDockAreaTitleBar { + background: transparent; + border-bottom: 2px solid palette(light); + padding-bottom: 0px; +} + +ads--CDockAreaWidget[focused="true"] ads--CDockAreaTitleBar { + background: transparent; + border-bottom: 2px solid palette(highlight); + padding-bottom: 0px; +} + + +ads--CFloatingWidgetTitleBar { + qproperty-maximizeIcon: url(:/ads/images/maximize-button.svg); + qproperty-normalIcon: url(:/ads/images/restore-button.svg); +} + + +/* does not properly work on KDE +ads--CFloatingDockContainer[isActiveWindow="true"] ads--CFloatingWidgetTitleBar { + background: palette(highlight); + qproperty-maximizeIcon: url(:/ads/images/maximize-button-focused.svg); + qproperty-normalIcon: url(:/ads/images/restore-button-focused.svg); +} + +ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleLabel { + color: palette(light); +} +*/ + +#floatingTitleCloseButton, #floatingTitleMaximizeButton { + qproperty-iconSize: 16px; + border: none; + margin: 6px 3px 6px 3px; +} + + +#floatingTitleCloseButton { + qproperty-icon: url(:/ads/images/close-button.svg); +} + + +#floatingTitleCloseButton:hover, #floatingTitleMaximizeButton:hover { + background: rgba(0, 0, 0, 24); + border: none; +} + + +#floatingTitleCloseButton:pressed, #floatingTitleMaximizeButton:pressed { + background: rgba(0, 0, 0, 48); +} + + +ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleMaximizeButton { + qproperty-iconSize: 16px; +} + + +/* does not properly work on KDE +ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton { + qproperty-icon: url(:/ads/images/close-button-focused.svg); + qproperty-iconSize: 16px; +} + +ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton:hover, +ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleMaximizeButton:hover { + background: rgba(255, 255, 255, 48); +} + + +ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleCloseButton:pressed, +ads--CFloatingDockContainer[isActiveWindow="true"] #floatingTitleMaximizeButton:pressed { + background: rgba(255, 255, 255, 92); +} +*/ + diff --git a/icons/about.png b/icons/about.png new file mode 100644 index 0000000..7ebf461 Binary files /dev/null and b/icons/about.png differ diff --git a/icons/add.svg b/icons/add.svg new file mode 100644 index 0000000..a5fe024 --- /dev/null +++ b/icons/add.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/addWorkspace.png b/icons/addWorkspace.png new file mode 100644 index 0000000..766e328 Binary files /dev/null and b/icons/addWorkspace.png differ diff --git a/icons/back.svg b/icons/back.svg new file mode 100644 index 0000000..1ef770c --- /dev/null +++ b/icons/back.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/bottom.png b/icons/bottom.png new file mode 100644 index 0000000..380a2b6 Binary files /dev/null and b/icons/bottom.png differ diff --git a/icons/center.png b/icons/center.png new file mode 100644 index 0000000..3f17fa2 Binary files /dev/null and b/icons/center.png differ diff --git a/icons/close.svg b/icons/close.svg new file mode 100644 index 0000000..7440a67 --- /dev/null +++ b/icons/close.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/forward.svg b/icons/forward.svg new file mode 100644 index 0000000..ad8b9d2 --- /dev/null +++ b/icons/forward.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/homepage.png b/icons/homepage.png new file mode 100644 index 0000000..b1e9be5 Binary files /dev/null and b/icons/homepage.png differ diff --git a/icons/left.png b/icons/left.png new file mode 100644 index 0000000..81bcdb5 Binary files /dev/null and b/icons/left.png differ diff --git a/icons/load.png b/icons/load.png new file mode 100644 index 0000000..eb71df8 Binary files /dev/null and b/icons/load.png differ diff --git a/icons/menu.png b/icons/menu.png new file mode 100644 index 0000000..ee13894 Binary files /dev/null and b/icons/menu.png differ diff --git a/icons/quit.png b/icons/quit.png new file mode 100644 index 0000000..190f1d9 Binary files /dev/null and b/icons/quit.png differ diff --git a/icons/refresh.svg b/icons/refresh.svg new file mode 100644 index 0000000..2cf2901 --- /dev/null +++ b/icons/refresh.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/remove.png b/icons/remove.png new file mode 100644 index 0000000..80ca194 Binary files /dev/null and b/icons/remove.png differ diff --git a/icons/removeWorkspace.png b/icons/removeWorkspace.png new file mode 100644 index 0000000..48fb81a Binary files /dev/null and b/icons/removeWorkspace.png differ diff --git a/icons/right.png b/icons/right.png new file mode 100644 index 0000000..8ece147 Binary files /dev/null and b/icons/right.png differ diff --git a/icons/save.png b/icons/save.png new file mode 100644 index 0000000..fbbc100 Binary files /dev/null and b/icons/save.png differ diff --git a/icons/search.png b/icons/search.png new file mode 100644 index 0000000..b8c7874 Binary files /dev/null and b/icons/search.png differ diff --git a/icons/settings.png b/icons/settings.png new file mode 100644 index 0000000..1a7c3dc Binary files /dev/null and b/icons/settings.png differ diff --git a/icons/splitbrowser.ico b/icons/splitbrowser.ico new file mode 100644 index 0000000..8d6a59d Binary files /dev/null and b/icons/splitbrowser.ico differ diff --git a/icons/splitbrowser.png b/icons/splitbrowser.png new file mode 100644 index 0000000..eb7d285 Binary files /dev/null and b/icons/splitbrowser.png differ diff --git a/icons/tab.png b/icons/tab.png new file mode 100644 index 0000000..ef03b8f Binary files /dev/null and b/icons/tab.png differ diff --git a/icons/top.png b/icons/top.png new file mode 100644 index 0000000..2aca3f1 Binary files /dev/null and b/icons/top.png differ diff --git a/iqwebview.h b/iqwebview.h new file mode 100644 index 0000000..e25f2a2 --- /dev/null +++ b/iqwebview.h @@ -0,0 +1,16 @@ +#ifndef IQWEBVIEW_H +#define IQWEBVIEW_H + +#include + +class IQWebView +{ +public: + virtual QUrl url() const = 0; + virtual QString title() const = 0; +signals: + void titleChanged(const QString &title); + void urlChanged(const QUrl &url); +}; + +#endif // IQWEBVIEW_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..18cca1e --- /dev/null +++ b/main.cpp @@ -0,0 +1,14 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + a.setOrganizationName(DEVELOPER_NAME); + a.setApplicationName(QString(APP_NAME) + (USE_WEBKIT ? " WebKit" : USE_ULTRALIGHT ? " Ultralight" : " Native")); + a.setApplicationVersion(QString::number(APP_VERSION)); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..73c4a08 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,351 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#if USE_WEBKIT +#include "qwebkitwebview.h" +#elif USE_ULTRALIGHT +#include "qultralightwebview.h" +#else +#include "qnativewebview.h" +#endif +#include "DockAreaWidget.h" +#include "DockAreaTitleBar.h" +#include "DockAreaTabBar.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef ULTRALIGHT_VERSION +#define ULTRALIGHT_VERSION "" +#endif + +using namespace std; + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) +{ + ui->setupUi(this); + +#if USE_ULTRALIGHT + ultralight::Settings settings; + settings.developer_name = DEVELOPER_NAME; + settings.app_name = APP_NAME " Ultralight"; + ultralight::Config config; +// config.memory_cache_size = 128 * 1024 * 1024; +// config.page_cache_size = 2; + ulApp = ultralight::App::Create(settings, config); +#endif + + // Dock + ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton); + ads::CDockManager::setConfigFlag(ads::CDockManager::EqualSplitOnInsertion); + //ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting); + dm = new ads::CDockManager(this); + connect(dm, &ads::CDockManager::dockAreaCreated, [=](ads::CDockAreaWidget *da) { + ads::CDockAreaTitleBar *titleBar = da->titleBar(); + QToolButton *addPaneButton = new QToolButton; + addPaneButton->setDefaultAction(ui->actionAdd); + addPaneButton->setAutoRaise(true); + titleBar->insertWidget(titleBar->indexOf(titleBar->tabBar()) + 1, addPaneButton); + }); + + restoreSettings(); + restoreWorkspaces(); + + if (!dm->openedDockWidgets().size()) + addPane(homePage); + + dm->setContextMenuPolicy(Qt::CustomContextMenu); + connect(dm, &ads::CDockManager::customContextMenuRequested, [=](const QPoint &pos) { + QMenu *menu = new QMenu(this); + menu->addAction(ui->actionMenubar); + menu->addAction(ui->actionAdd); + menu->exec(mapToGlobal(pos)); + }); +} + +MainWindow::~MainWindow() +{ + delete dm; + delete ui; + if (clearDataOnClose) + clearData(); +} + +QUrl MainWindow::sanitizeUrl(const QUrl &url) +{ + if (!url.isValid()) + return QUrl("about:blank"); + if (url.isRelative()) { + if (url.toString().endsWith(".com") || + url.toString().endsWith(".net") || + url.toString().endsWith(".org") || + url.toString().endsWith(".info") || + url.toString().endsWith(".co") || + url.toString().endsWith(".uk") || + url.toString().endsWith(".de") || + url.toString().endsWith(".fr") || + url.toString().endsWith(".pl") || + url.toString().endsWith(".io")) { + return QUrl("http://" + url.toEncoded()); + } + return QUrl(searchPage.toString().replace("[query]", url.toEncoded())); + } + return url; +} + +QSize MainWindow::sizeHint() const +{ + return QDesktopWidget().availableGeometry(this).size() * 0.9; +} + +void MainWindow::closeEvent(QCloseEvent* event) +{ + saveSettings(); +#if USE_ULTRALIGHT + ulApp->Quit(); +#endif + QMainWindow::closeEvent(event); +} + +void MainWindow::addPane(QUrl url) +{ + ads::CDockWidget* dw = new ads::CDockWidget("Loading..."); + WEBVIEW_IMPL *wv = new WEBVIEW_IMPL(dw, url); + dw->setWidget(wv); + dw->setObjectName(QString::number(dm->dockWidgetsMap().size())); + dw->setFeature(ads::CDockWidget::DockWidgetDeleteOnClose, true); + dm->addDockWidget(area, dw, dm->dockAreaAt(QCursor::pos())); + + connect(wv, &WEBVIEW_IMPL::titleChanged, [=](const QString &title) { + QString shortTitle(title); + if (shortTitle.size() > 80) { + shortTitle.truncate(80); + shortTitle.append("…"); + } + dw->setWindowTitle(shortTitle); + }); +} + +void MainWindow::addWorkspace() +{ + QString workspaceName = QInputDialog::getText(this, "Add new workspace", "Type unique name:"); + if (workspaceName.isEmpty()) + return; + + dm->addPerspective(workspaceName); + QAction *a = new QAction(workspaceName); + a->setActionGroup(ui->workspaces); + a->setCheckable(true); + a->setChecked(true); + ui->menuWorkspaces->addAction(a); + ui->actionRemoveWorkspace->setVisible(true); + saveWorkspaces(); +} + +void MainWindow::removeWorkspace() +{ + if (ui->workspaces->actions().size() <= 1) + return; + + QAction *a = ui->workspaces->checkedAction(); + + QMessageBox *confirmBox = new QMessageBox(this); + confirmBox->setText("Do you want to remove the current workspace " + a->text() + "?"); + confirmBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No); + confirmBox->setDefaultButton(QMessageBox::No); + if(confirmBox->exec() != QMessageBox::Yes) + return; + + dm->removePerspective(a->text()); + ui->workspaces->removeAction(a); + ui->menuWorkspaces->removeAction(a); + ui->menuWorkspaces->actions().first()->setChecked(true); + saveWorkspaces(); +} + +void MainWindow::saveWorkspaces() +{ + QSettings settings("settings.ini", QSettings::IniFormat); + dm->savePerspectives(settings); +} + +void MainWindow::restoreWorkspaces() +{ + QSettings settings("Settings.ini", QSettings::IniFormat); + dm->loadPerspectives(settings); + ui->menuWorkspaces->clear(); + foreach (const QString &name, dm->perspectiveNames()) { + QAction *a = new QAction(name); + a->setCheckable(true); + a->setActionGroup(ui->workspaces); + ui->menuWorkspaces->addAction(a); + } + ui->actionRemoveWorkspace->setVisible(ui->workspaces->actions().size() > 1); + if (ui->workspaces->actions().size() > 0) + ui->menuWorkspaces->actions().first()->setChecked(true); +} + +void MainWindow::saveSettings() +{ + QSettings settings("settings.ini", QSettings::IniFormat); + settings.setValue("browser/area", area); + settings.setValue("browser/homePage", homePage); + settings.setValue("browser/searchPage", searchPage); + settings.setValue("browser/saveLayout", saveLayoutOnClose); + settings.setValue("browser/geometry", saveGeometry()); + settings.setValue("browser/state", saveState()); + settings.setValue("browser/dockingState", dm->saveState()); + + if (saveLayoutOnClose) { + settings.beginGroup("tabs"); + settings.remove(""); + settings.endGroup(); + settings.beginWriteArray("tabs"); + QList tabs = dm->openedDockWidgets(); + for(int i = 0; i < tabs.size(); i++) { + settings.setArrayIndex(i); + settings.setValue("URL", ((WEBVIEW_IMPL*) tabs[i]->widget())->url()); + } + settings.endArray(); + } + + settings.sync(); +} + +void MainWindow::restoreSettings() +{ + QSettings settings("settings.ini", QSettings::IniFormat); + restoreGeometry(settings.value("browser/geometry").toByteArray()); + restoreState(settings.value("browser/state").toByteArray()); + area = (ads::DockWidgetArea) settings.value("browser/area", area).toInt(); + homePage = settings.value("browser/homePage", homePage).toString(); + searchPage = settings.value("browser/searchPage", searchPage).toString(); + saveLayoutOnClose = settings.value("browser/saveLayout", saveLayoutOnClose).toBool(); + + ui->actionSave->setChecked(saveLayoutOnClose); + if (area == ads::RightDockWidgetArea) + ui->actionRight->setChecked(true); + else if (area == ads::LeftDockWidgetArea) + ui->actionLeft->setChecked(true); + else if (area == ads::TopDockWidgetArea) + ui->actionTop->setChecked(true); + else if (area == ads::BottomDockWidgetArea) + ui->actionBottom->setChecked(true); + else + ui->actionCenter->setChecked(true); + + if (saveLayoutOnClose) { + int tabs = settings.beginReadArray("tabs"); + for(int i = 0; i < tabs; i++) { + settings.setArrayIndex(i); + addPane(settings.value("URL").toUrl()); + } + settings.endArray(); + dm->restoreState(settings.value("browser/dockingState").toByteArray()); + } +} + +bool MainWindow::clearData() +{ +#if USE_WEBKIT + QString path(QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA") + "\\Apple Computer\\WebKit"); +#elif USE_ULTRALIGHT + QString path(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); +#elif defined(_WIN32) + QString path(QProcessEnvironment::systemEnvironment().value("APPDATA") + "\\" + QFileInfo(QApplication::applicationFilePath()).fileName() + "\\EBWebView"); +#elif defined(__unix__) + QString path(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.cache/" + QFileInfo(QApplication::applicationFilePath()).fileName() + "/WebKitCache"); +#endif + qDebug() << "Removing" << path; + QThread::msleep(500); + return QDir(path).removeRecursively(); +} + +void MainWindow::on_actionQuit_triggered() +{ + close(); +} + +void MainWindow::on_actionSave_toggled(bool checked) +{ + saveLayoutOnClose = checked; +} + +void MainWindow::on_actionAdd_triggered() +{ + addPane(homePage); +} + +void MainWindow::on_actionAddWorkspace_triggered() +{ + addWorkspace(); +} + +void MainWindow::on_actionRemoveWorkspace_triggered() +{ + removeWorkspace(); +} + +void MainWindow::on_tabAreas_triggered() +{ + QString name = ui->tabAreas->checkedAction()->objectName(); + if (name == "actionRight") + area = ads::RightDockWidgetArea; + else if (name == "actionLeft") + area = ads::LeftDockWidgetArea; + else if (name == "actionTop") + area = ads::TopDockWidgetArea; + else if (name == "actionBottom") + area = ads::BottomDockWidgetArea; + else + area = ads::CenterDockWidgetArea; +} + +void MainWindow::on_actionAbout_triggered() +{ + QMessageBox::about(this, "About " + QApplication::applicationName(), + QApplication::applicationName() + " version " + QApplication::applicationVersion() + +#if USE_WEBKIT + "\nPlaywright WebKit revision " + QString::number(WEBKIT_VERSION) + +#elif USE_ULTRALIGHT + "\nUltralight version " + QString::fromStdString(ULTRALIGHT_VERSION) + +#endif + "\n© 2022 Jerzy GÅ‚owacki\nMIT License"); +} + +void MainWindow::on_actionHomepage_triggered() +{ + bool ok; + QUrl url = QUrl(QInputDialog::getText(this, "Set home page", "URL:", QLineEdit::Normal, homePage.toString(), &ok)); + if (ok && url.isValid() && !url.isRelative()) + homePage = url; + else if (ok) + QMessageBox::warning(this, "Set home page", "Invalid URL"); +} + +void MainWindow::on_actionSearchpage_triggered() +{ + bool ok; + QUrl url = QUrl(QInputDialog::getText(this, "Set search page", "URL with [query]:", QLineEdit::Normal, searchPage.toString(), &ok)); + if (ok && url.isValid() && !url.isRelative() && url.toString().contains("[query]")) + searchPage = url; + else if (ok) + QMessageBox::warning(this, "Set search page", "Invalid URL or does not contain [query]"); +} + +void MainWindow::on_actionClear_toggled(bool checked) +{ + clearDataOnClose = checked; +} + +void MainWindow::on_actionMenubar_toggled(bool checked) +{ + ui->menubar->setVisible(checked); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..9a25f80 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,59 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include "DockManager.h" + +#if USE_ULTRALIGHT +#include +#endif + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + static QUrl sanitizeUrl(const QUrl &url); + QSize sizeHint() const override; +protected: + virtual void closeEvent(QCloseEvent*) override; +private: + Ui::MainWindow *ui; + ads::CDockManager *dm; +#if USE_ULTRALIGHT + ultralight::RefPtr ulApp; +#endif + ads::DockWidgetArea area = ads::RightDockWidgetArea; + inline static QUrl homePage = QUrl("https://start.duckduckgo.com/"); + inline static QUrl searchPage = QUrl("https://duckduckgo.com/?q=[query]"); + bool saveLayoutOnClose = true; + bool clearDataOnClose = false; + void addPane(QUrl url); + void addWorkspace(); + void removeWorkspace(); + void saveWorkspaces(); + void restoreWorkspaces(); + void saveSettings(); + void restoreSettings(); + bool clearData(); +private slots: + void on_actionQuit_triggered(); + void on_actionSave_toggled(bool checked); + void on_actionAdd_triggered(); + void on_actionAddWorkspace_triggered(); + void on_actionRemoveWorkspace_triggered(); + void on_tabAreas_triggered(); + void on_actionAbout_triggered(); + void on_actionHomepage_triggered(); + void on_actionSearchpage_triggered(); + void on_actionClear_toggled(bool checked); + void on_actionMenubar_toggled(bool checked); +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..872e7a7 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,299 @@ + + + MainWindow + + + + 0 + 0 + 1280 + 750 + + + + + :/icons/splitbrowser.png:/icons/splitbrowser.png + + + + 24 + 24 + + + + + + + 0 + 0 + 1280 + 26 + + + + + &File + + + + Tab &area + + + + :/icons/tab.png:/icons/tab.png + + + + + + + + + + Workspaces + + + + + + + + + + + + + + &View + + + + + + &Help + + + + + + &Settings + + + + + + + + + + + + + + + :/icons/quit.png:/icons/quit.png + + + &Quit + + + Ctrl+Q + + + + + + :/icons/add.svg:/icons/add.svg + + + Add new &tab + + + Add new tab + + + Ctrl+T + + + + + + :/icons/addWorkspace.png:/icons/addWorkspace.png + + + Add new workspace + + + + + + :/icons/removeWorkspace.png:/icons/removeWorkspace.png + + + Remove workspace + + + + + + :/icons/about.png:/icons/about.png + + + &About... + + + About browser + + + + + + :/icons/homepage.png:/icons/homepage.png + + + Set &home page... + + + Set home page + + + + + + :/icons/search.png:/icons/search.png + + + Set &search page... + + + + + true + + + + :/icons/save.png:/icons/save.png + + + Save &layout on close + + + Save layout on close + + + + + true + + + true + + + &Menu bar + + + Ctrl+M + + + + + true + + + + :/icons/remove.png:/icons/remove.png + + + &Clear browsing data on close + + + Clear browsing data + + + + + + true + + + true + + + + :/icons/right.png:/icons/right.png + + + &Right + + + Right area + + + + + true + + + + :/icons/left.png:/icons/left.png + + + &Left + + + Left area + + + + + true + + + + :/icons/top.png:/icons/top.png + + + &Top + + + Top area + + + + + true + + + + :/icons/bottom.png:/icons/bottom.png + + + &Bottom + + + Bottom area + + + + + true + + + + :/icons/center.png:/icons/center.png + + + &Center + + + Center area + + + + + + + + + + diff --git a/qnativewebview.cpp b/qnativewebview.cpp new file mode 100644 index 0000000..22ff48f --- /dev/null +++ b/qnativewebview.cpp @@ -0,0 +1,170 @@ +#include "qnativewebview.h" +#include "mainwindow.h" +#include "webview.h" + +#include +#include +#include +#include +#include +#include +#include + +#define WEBVIEW ((webview::webview *) _wv) + +using namespace std; + +QNativeWebView::QNativeWebView(QWidget *parent, QUrl url) : QWidget(parent) +{ + _wv = new webview::webview(false, nullptr); + if (!WEBVIEW->window()) { + QMessageBox::critical(this, QApplication::applicationName(), "Cannot initialize native webview!" +#ifdef _WIN32 + "\nInstall Edge WebView2 from https://developer.microsoft.com/en-us/microsoft-edge/webview2/consumer/" +#endif + ); + exit(1); + } + + WEBVIEW->bind("qtInit", [=](string log) -> string { + _url = WEBVIEW->get_url(); + _title = WEBVIEW->get_title(); + emit urlChanged(_url); + emit titleChanged(_title); + emit loadProgress(100); + emit loadFinished(true); + return log; + }); + WEBVIEW->init("addEventListener('DOMContentLoaded', qtInit)"); + QWidget *wvWidget = createWindowContainer(QWindow::fromWinId((unsigned long long) WEBVIEW->window())); + + //Toolbar + QToolBar *toolbar = new QToolBar; + toolbar->setIconSize(QSize(24, 24)); + + QAction *backAction = new QAction(QIcon(":/icons/back.svg"), "&Back", this); + backAction->setShortcut(QKeySequence("Alt+Left")); + backAction->setToolTip("Go back"); + connect(backAction, &QAction::triggered, this, &QNativeWebView::back); + toolbar->addAction(backAction); + + QAction *forwardAction = new QAction(QIcon(":/icons/forward.svg"), "&Forward", this); + forwardAction->setShortcut(QKeySequence("Alt+Right")); + forwardAction->setToolTip("Go forward"); + connect(forwardAction, &QAction::triggered, this, &QNativeWebView::forward); + toolbar->addAction(forwardAction); + + QAction *refreshAction = new QAction(QIcon(":/icons/refresh.svg"), "&Refresh", this); + refreshAction->setShortcuts(QKeySequence::Refresh); + refreshAction->setToolTip("Refresh"); + connect(refreshAction, &QAction::triggered, this, &QNativeWebView::reload); + toolbar->addAction(refreshAction); + + QAction *stopAction = new QAction(QIcon(":/icons/close.svg"), "&Stop", this); + stopAction->setShortcuts(QKeySequence::Cancel); + stopAction->setToolTip("Stop"); + refreshAction->setVisible(false); + connect(stopAction, &QAction::triggered, this, &QNativeWebView::stop); + toolbar->addAction(stopAction); + + _addressBar = new QLineEdit; + _addressBar->setDragEnabled(true); + _addressBar->installEventFilter(this); + connect(_addressBar, &QLineEdit::returnPressed, this, [=]() { + load(MainWindow::sanitizeUrl(_addressBar->text())); + }); + connect(this, &QNativeWebView::urlChanged, [=](QUrl url) { + _addressBar->setText(url.toString()); + }); + connect(this, &QNativeWebView::loadStarted, [=]() { + refreshAction->setVisible(false); + stopAction->setVisible(true); + }); + connect(this, &QNativeWebView::loadFinished, [=]() { + refreshAction->setVisible(true); + stopAction->setVisible(false); + }); + QWidgetAction *addressBarAction = new QWidgetAction(this); + addressBarAction->setDefaultWidget(_addressBar); + toolbar->addAction(addressBarAction); + + QFrame *hLine = new QFrame(); + hLine->setFrameShape(QFrame::HLine); + hLine->setFrameShadow(QFrame::Sunken); + + QVBoxLayout *layout = new QVBoxLayout; + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + layout->addWidget(toolbar); + layout->addWidget(hLine); + layout->addWidget(wvWidget); + setLayout(layout); + + load(url); +} + +QNativeWebView::~QNativeWebView() +{ + delete WEBVIEW; +} + +void QNativeWebView::load(const QUrl &url) +{ + if (!url.isValid()) + return; + _url = url; + emit loadStarted(); + emit loadProgress(0); + WEBVIEW->navigate(_url.toString().toStdString()); + WEBVIEW->step(0); +} + +void QNativeWebView::setUrl(const QUrl &url) +{ + load(url); +} + +QUrl QNativeWebView::url() const +{ + return _url; +} + +QString QNativeWebView::title() const +{ + return _title; +} + +bool QNativeWebView::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == _addressBar && event->type() == QEvent::FocusIn) + QTimer::singleShot(0, _addressBar, &QLineEdit::selectAll); + return QWidget::eventFilter(obj, event); +} + +void QNativeWebView::back() +{ + emit loadStarted(); + emit loadProgress(0); + WEBVIEW->go_back(); +} + +void QNativeWebView::forward() +{ + emit loadStarted(); + emit loadProgress(0); + WEBVIEW->go_forward(); +} + +void QNativeWebView::reload() +{ + emit loadStarted(); + emit loadProgress(0); + WEBVIEW->reload(); +} + +void QNativeWebView::stop() +{ + WEBVIEW->stop(); + emit loadProgress(100); + emit loadFinished(true); +} diff --git a/qnativewebview.h b/qnativewebview.h new file mode 100644 index 0000000..a398d95 --- /dev/null +++ b/qnativewebview.h @@ -0,0 +1,41 @@ +#ifndef QNATIVEWEBVIEW_H +#define QNATIVEWEBVIEW_H +#define WEBVIEW_IMPL QNativeWebView + +#include "iqwebview.h" + +#include +#include +#include + +class QNativeWebView : public QWidget, public IQWebView +{ + Q_OBJECT +public: + explicit QNativeWebView(QWidget *parent = nullptr, QUrl url = QUrl()); + ~QNativeWebView(); + void load(const QUrl &url); + void setUrl(const QUrl &url); + QUrl url() const override; + QString title() const override; +protected: + bool eventFilter(QObject *obj, QEvent *ev) override; +private: + void *_wv; + QUrl _url; + QString _title; + QLineEdit *_addressBar; +public slots: + void back(); + void forward(); + void reload(); + void stop(); +signals: + void loadFinished(bool ok); + void loadProgress(int progress); + void loadStarted(); + void titleChanged(const QString &title); + void urlChanged(const QUrl &url); +}; + +#endif // QNATIVEWEBVIEW_H diff --git a/qtadvanceddocking.dll b/qtadvanceddocking.dll new file mode 100644 index 0000000..42f24cb Binary files /dev/null and b/qtadvanceddocking.dll differ diff --git a/qtadvanceddocking.exp b/qtadvanceddocking.exp new file mode 100644 index 0000000..6cceaf7 Binary files /dev/null and b/qtadvanceddocking.exp differ diff --git a/qtadvanceddocking.lib b/qtadvanceddocking.lib new file mode 100644 index 0000000..4666377 Binary files /dev/null and b/qtadvanceddocking.lib differ diff --git a/qtadvanceddockingd.dll b/qtadvanceddockingd.dll new file mode 100644 index 0000000..f7c2806 Binary files /dev/null and b/qtadvanceddockingd.dll differ diff --git a/qtadvanceddockingd.exp b/qtadvanceddockingd.exp new file mode 100644 index 0000000..b4dc481 Binary files /dev/null and b/qtadvanceddockingd.exp differ diff --git a/qtadvanceddockingd.lib b/qtadvanceddockingd.lib new file mode 100644 index 0000000..ccbd77b Binary files /dev/null and b/qtadvanceddockingd.lib differ diff --git a/qultralightwebview.cpp b/qultralightwebview.cpp new file mode 100644 index 0000000..b89cfdf --- /dev/null +++ b/qultralightwebview.cpp @@ -0,0 +1,300 @@ +#include "qultralightwebview.h" +#include "mainwindow.h" + +#include +#include +#include +#include +#include +#include +#include + +QUltralightWebView::QUltralightWebView(QWidget *parent, QUrl url) : QWidget(parent) +{ + ultralight::App *app = ultralight::App::instance(); + _window = ultralight::Window::Create(app->main_monitor(), 0, 0, false, 0); + _overlay = ultralight::Overlay::Create(_window, _window->width(), _window->height(), 0, 0); + _view = _overlay->view(); + _view->set_load_listener(this); + _view->set_view_listener(this); + _window->set_listener(this); + + QWidget *wvWidget = createWindowContainer(QWindow::fromWinId((unsigned long long) _window->native_handle())); + + //Toolbar + QToolBar *toolbar = new QToolBar; + toolbar->setIconSize(QSize(24, 24)); + + QAction *backAction = new QAction(QIcon(":/icons/back.svg"), "&Back", this); + backAction->setShortcut(QKeySequence("Alt+Left")); + backAction->setToolTip("Go back"); + connect(backAction, &QAction::triggered, this, &QUltralightWebView::back); + toolbar->addAction(backAction); + + QAction *forwardAction = new QAction(QIcon(":/icons/forward.svg"), "&Forward", this); + forwardAction->setShortcut(QKeySequence("Alt+Right")); + forwardAction->setToolTip("Go forward"); + connect(forwardAction, &QAction::triggered, this, &QUltralightWebView::forward); + toolbar->addAction(forwardAction); + + QAction *refreshAction = new QAction(QIcon(":/icons/refresh.svg"), "&Refresh", this); + refreshAction->setShortcuts(QKeySequence::Refresh); + refreshAction->setToolTip("Refresh"); + connect(refreshAction, &QAction::triggered, this, &QUltralightWebView::reload); + toolbar->addAction(refreshAction); + + QAction *stopAction = new QAction(QIcon(":/icons/close.svg"), "&Stop", this); + stopAction->setShortcuts(QKeySequence::Cancel); + stopAction->setToolTip("Stop"); + refreshAction->setVisible(false); + connect(stopAction, &QAction::triggered, this, &QUltralightWebView::stop); + toolbar->addAction(stopAction); + + _addressBar = new QLineEdit; + _addressBar->setDragEnabled(true); + _addressBar->installEventFilter(this); + connect(_addressBar, &QLineEdit::returnPressed, this, [=]() { + QTimer::singleShot(10, [=]() { + load(MainWindow::sanitizeUrl(_addressBar->text())); + }); + }); + connect(this, &QUltralightWebView::urlChanged, [=](QUrl url) { + _addressBar->setText(url.toString()); + }); + connect(this, &QUltralightWebView::loadStarted, [=]() { + refreshAction->setVisible(false); + stopAction->setVisible(true); + }); + connect(this, &QUltralightWebView::loadFinished, [=]() { + refreshAction->setVisible(true); + stopAction->setVisible(false); + }); + QWidgetAction *addressBarAction = new QWidgetAction(this); + addressBarAction->setDefaultWidget(_addressBar); + toolbar->addAction(addressBarAction); + + QFrame *hLine = new QFrame(); + hLine->setFrameShape(QFrame::HLine); + hLine->setFrameShadow(QFrame::Sunken); + + QVBoxLayout *layout = new QVBoxLayout; + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + layout->addWidget(toolbar); + layout->addWidget(hLine); + layout->addWidget(wvWidget); + setLayout(layout); + + setFocusPolicy(Qt::WheelFocus); + + load(url); + + QTimer::singleShot(0, [=]() { + if(!app->is_running()) + app->Run(); + setFocus(); + }); +} + +QUltralightWebView::~QUltralightWebView() +{ + _view->set_load_listener(nullptr); + _view->set_view_listener(nullptr); + _window->set_listener(nullptr); + _window->Close(); +} + +void QUltralightWebView::load(const QUrl &url) +{ + if (!url.isValid()) + return; + qDebug() << "Loading" << url; + _view->LoadURL(QUrlToUlString(url)); +} + + +void QUltralightWebView::setUrl(const QUrl &url) +{ + load(url); +} + +QUrl QUltralightWebView::url() const +{ + return _url; +} + +QString QUltralightWebView::title() const +{ + return _title; +} + +bool QUltralightWebView::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == _addressBar && event->type() == QEvent::FocusIn) + QTimer::singleShot(0, _addressBar, &QLineEdit::selectAll); + return QWidget::eventFilter(obj, event); +} + +void QUltralightWebView::keyPressEvent(QKeyEvent* ev) +{ + sendKey(ev); + QWidget::keyPressEvent(ev); +} + +void QUltralightWebView::back() +{ + _view->GoBack(); +} + +void QUltralightWebView::forward() +{ + _view->GoForward(); +} + +void QUltralightWebView::reload() +{ + _view->Reload(); +} + +void QUltralightWebView::stop() +{ + _view->Stop(); +} + +int QUltralightWebView::QtModsToUlMods(int mods) +{ + int result = 0; + if (mods & Qt::AltModifier) + result |= ultralight::KeyEvent::kMod_AltKey; + if (mods & Qt::ControlModifier) + result |= ultralight::KeyEvent::kMod_CtrlKey; + if (mods & Qt::MetaModifier) + result |= ultralight::KeyEvent::kMod_MetaKey; + if (mods & Qt::ShiftModifier) + result |= ultralight::KeyEvent::kMod_ShiftKey; + return result; +} + +QString QUltralightWebView::ulStringToQString(const ultralight::String string) +{ + return QString::fromUtf8(string.utf8().data()); +} + +QUrl QUltralightWebView::ulStringToQUrl(const ultralight::String string) +{ + return QUrl(ulStringToQString(string)); +} + +ultralight::String QUltralightWebView::QStringToUlString(const QString string) +{ + return (ultralight::String8) string.toUtf8().constData(); +} + +ultralight::String QUltralightWebView::QUrlToUlString(const QUrl url) +{ + return QStringToUlString(url.toString()); +} + +void QUltralightWebView::OnResize(ultralight::Window *window, uint32_t width_px, uint32_t height_px) +{ + _overlay->Resize(width_px, height_px); +} + +//void QUltralightWebView::OnClose(ultralight::Window *window) +//{ +// qDebug() << "Not implemented: OnClose" << window; +//} + +void QUltralightWebView::OnChangeCursor(ultralight::View* caller, ultralight::Cursor cursor) { + _window->SetCursor(cursor); +} + +void QUltralightWebView::OnChangeTitle(ultralight::View *caller, const ultralight::String &title) +{ + _title = ulStringToQString(title); + emit titleChanged(_title); +} + +void QUltralightWebView::OnChangeURL(ultralight::View *caller, const ultralight::String &url) +{ + _url = ulStringToQUrl(url); + emit urlChanged(_url); +} + +//void QUltralightWebView::OnChangeTooltip(ultralight::View *caller, const ultralight::String &tooltip) +//{ +// qDebug() << "Not implemented: OnChangeTooltip" << tooltip.utf8().data(); +//} + +//void QUltralightWebView::OnAddConsoleMessage(ultralight::View *caller, ultralight::MessageSource source, ultralight::MessageLevel level, const ultralight::String &message, uint32_t line_number, uint32_t column_number, const ultralight::String &source_id) +//{ +// if (level == ultralight::MessageLevel::kMessageLevel_Log || level == ultralight::MessageLevel::kMessageLevel_Info) +// qInfo() << ">>" << ulStringToQString(message); +// else if (level == ultralight::MessageLevel::kMessageLevel_Debug) +// qDebug() << ">>" << ulStringToQString(message); +// else if (level == ultralight::MessageLevel::kMessageLevel_Warning) +// qWarning() << ">>" << ulStringToQString(message); +// else if (level == ultralight::MessageLevel::kMessageLevel_Error) +// qCritical() << ">>" << ulStringToQString(message); +//} + +//ultralight::RefPtr QUltralightWebView::OnCreateChildView(ultralight::View *caller, const ultralight::String &opener_url, const ultralight::String &target_url, bool is_popup, const ultralight::IntRect &popup_rect) +//{ +// qDebug() << "Not implemented: OnCreateChildView"; +// return nullptr; +//} + +void QUltralightWebView::OnBeginLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url) +{ + if (is_main_frame) { + emit loadStarted(); + emit loadProgress(0); + } +} + +void QUltralightWebView::OnFinishLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url) +{ + if (is_main_frame) { + emit loadProgress(100); + emit loadFinished(true); + } +} + +void QUltralightWebView::OnFailLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url, const ultralight::String &description, const ultralight::String &error_domain, int error_code) +{ + qCritical() << "ERROR" << error_code << "(" << ulStringToQString(error_domain) << ")" << ulStringToQString(description) << "while loading" << ulStringToQUrl(url).toString(); + if (is_main_frame) { + emit loadProgress(100); + emit loadFinished(false); + } +} + +//void QUltralightWebView::OnWindowObjectReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url) +//{ +// qDebug() << "Not implemented: OnWindowObjectReady"; +//} + +//void QUltralightWebView::OnDOMReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url) +//{ +// qDebug() << "Not implemented: OnDOMReady"; +//} + +//void QUltralightWebView::OnUpdateHistory(ultralight::View *caller) +//{ +// qDebug() << "Not implemented: OnUpdateHistory"; +//} + +void QUltralightWebView::sendKey(QKeyEvent *event) +{ + ultralight::KeyEvent evt; + evt.type = ultralight::KeyEvent::kType_RawKeyDown; + evt.virtual_key_code = event->nativeVirtualKey(); + GetKeyIdentifierFromVirtualKeyCode(event->nativeVirtualKey(), evt.key_identifier); + evt.modifiers = QtModsToUlMods(event->modifiers()); + _overlay->view()->FireKeyEvent(evt); + // Support typing chars + evt.type = ultralight::KeyEvent::kType_Char; + evt.text = QStringToUlString(event->text()); + evt.unmodified_text = evt.text; + _overlay->view()->FireKeyEvent(evt); +} diff --git a/qultralightwebview.h b/qultralightwebview.h new file mode 100644 index 0000000..8bb3bfc --- /dev/null +++ b/qultralightwebview.h @@ -0,0 +1,69 @@ +#ifndef QULTRALIGHTWEBVIEW_H +#define QULTRALIGHTWEBVIEW_H +#define WEBVIEW_IMPL QUltralightWebView + +#include "iqwebview.h" + +#include +#include + +#include + +class QUltralightWebView : public QWidget, + public IQWebView, + public ultralight::WindowListener, + public ultralight::LoadListener, + public ultralight::ViewListener +{ + Q_OBJECT +public: + explicit QUltralightWebView(QWidget *parent = nullptr, QUrl url = QUrl()); + ~QUltralightWebView(); + void load(const QUrl &url); + void setUrl(const QUrl &url); + QUrl url() const override; + QString title() const override; +protected: + bool eventFilter(QObject *obj, QEvent *ev) override; + void keyPressEvent(QKeyEvent*) override; +private: + ultralight::RefPtr _window; + ultralight::RefPtr _overlay; + ultralight::RefPtr _view; + QUrl _url; + QString _title; + QLineEdit *_addressBar; + static int QtModsToUlMods(int mods); + static QString ulStringToQString(const ultralight::String string); + static QUrl ulStringToQUrl(const ultralight::String string); + static ultralight::String QStringToUlString(const QString string); + static ultralight::String QUrlToUlString(const QUrl url); + void OnResize(ultralight::Window* window, uint32_t width_px, uint32_t height_px) override; +// void OnClose(ultralight::Window* window) override; + void OnChangeCursor(ultralight::View* caller, ultralight::Cursor cursor) override; + void OnChangeTitle(ultralight::View* caller, const ultralight::String& title) override; + void OnChangeURL(ultralight::View* caller, const ultralight::String& url) override; +// void OnChangeTooltip(ultralight::View* caller, const ultralight::String& tooltip) override; +// void OnAddConsoleMessage(ultralight::View* caller, ultralight::MessageSource source, ultralight::MessageLevel level, const ultralight::String& message, uint32_t line_number, uint32_t column_number, const ultralight::String& source_id) override; +// ultralight::RefPtr OnCreateChildView(ultralight::View* caller, const ultralight::String& opener_url, const ultralight::String& target_url, bool is_popup, const ultralight::IntRect& popup_rect) override; + void OnBeginLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, const ultralight::String& url) override; + void OnFinishLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, const ultralight::String& url) override; + void OnFailLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, const ultralight::String& url, const ultralight::String& description, const ultralight::String& error_domain, int error_code) override; +// void OnWindowObjectReady(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, const ultralight::String& url) override; +// void OnDOMReady(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, const ultralight::String& url) override; +// void OnUpdateHistory(ultralight::View* caller) override; +public slots: + void back(); + void forward(); + void reload(); + void stop(); + void sendKey(QKeyEvent *event); +signals: + void loadFinished(bool ok); + void loadProgress(int progress); + void loadStarted(); + void titleChanged(const QString &title); + void urlChanged(const QUrl &url); +}; + +#endif // QULTRALIGHTWEBVIEW_H diff --git a/qwebkitwebview.cpp b/qwebkitwebview.cpp new file mode 100644 index 0000000..fc15300 --- /dev/null +++ b/qwebkitwebview.cpp @@ -0,0 +1,68 @@ +#include "qwebkitwebview.h" + +#include +#include +#include +#include +#include + +using namespace std; + +QWebKitWebView::QWebKitWebView(QWidget *parent, QUrl url) : QWidget(parent) +{ + _process = new QProcess(this); + _process->start("webkit\\Playwright.exe", QStringList(url.toString())); + _process->waitForStarted(); + HWND winId = NULL; + while (!winId) { + QThread::msleep(100); + winId = FindWindow(L"Playwright", NULL); + } + HWND toolbarId = FindWindowEx(winId, NULL, L"ToolbarWindow32", NULL); + HWND addressBarId = FindWindowEx(toolbarId, NULL, L"Edit", NULL); + QWindow *window = QWindow::fromWinId((unsigned long long) winId); + QWidget *wvWidget = createWindowContainer(window, this, Qt::FramelessWindowHint); + QGridLayout *layout = new QGridLayout; + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(wvWidget); + setLayout(layout); + + QTimer *timer = new QTimer(this); + timer->setTimerType(Qt::VeryCoarseTimer); + connect(timer, &QTimer::timeout, this, [=]() { + wstring wtitle(GetWindowTextLength(winId), L'\0'); + GetWindowText(winId, &wtitle[0], (int) wtitle.capacity()); + QString title = QString::fromStdWString(wtitle).replace(" [WebKit]", ""); + if (title == "Playwright") + title = ""; + if (_title != title) { + _title = title; + emit titleChanged(_title); + } + wstring wurl((int) SendMessage(addressBarId, WM_GETTEXTLENGTH, NULL, NULL), L'\0'); + SendMessage(addressBarId, WM_GETTEXT, wurl.capacity(), (LPARAM) &wurl[0]); + QUrl url = QUrl(QString::fromStdWString(wurl)); + if (_url != url) { + _url = url; + emit urlChanged(_url); + } + }); + timer->start(1000); +} + +QWebKitWebView::~QWebKitWebView() +{ + _process->terminate(); + _process->kill(); + _process->deleteLater(); +} + +QUrl QWebKitWebView::url() const +{ + return _url; +} + +QString QWebKitWebView::title() const +{ + return _title; +} diff --git a/qwebkitwebview.h b/qwebkitwebview.h new file mode 100644 index 0000000..f527ddf --- /dev/null +++ b/qwebkitwebview.h @@ -0,0 +1,28 @@ +#ifndef QWEBKITWEBVIEW_H +#define QWEBKITWEBVIEW_H +#define WEBVIEW_IMPL QWebKitWebView + +#include "iqwebview.h" + +#include +#include +#include + +class QWebKitWebView : public QWidget, public IQWebView +{ + Q_OBJECT +public: + explicit QWebKitWebView(QWidget *parent = nullptr, QUrl url = QUrl()); + ~QWebKitWebView(); + QUrl url() const override; + QString title() const override; +private: + QProcess *_process; + QUrl _url; + QString _title; +signals: + void titleChanged(const QString &title); + void urlChanged(const QUrl &url); +}; + +#endif // QWEBKITWEBVIEW_H diff --git a/res.qrc b/res.qrc new file mode 100644 index 0000000..9bc4212 --- /dev/null +++ b/res.qrc @@ -0,0 +1,27 @@ + + + icons/load.png + icons/menu.png + icons/save.png + icons/quit.png + icons/addWorkspace.png + icons/removeWorkspace.png + icons/refresh.svg + icons/forward.svg + icons/back.svg + icons/add.svg + icons/close.svg + icons/tab.png + icons/center.png + icons/top.png + icons/right.png + icons/left.png + icons/bottom.png + icons/about.png + icons/splitbrowser.png + icons/homepage.png + icons/search.png + icons/settings.png + icons/remove.png + + diff --git a/splitbrowser.pro b/splitbrowser.pro new file mode 100644 index 0000000..80e9f91 --- /dev/null +++ b/splitbrowser.pro @@ -0,0 +1,87 @@ +DEVELOPER_NAME='Jerzy Glowacki' +APP_NAME='Split Browser' +APP_VERSION=0.1 +WEBKIT_VERSION = 1668 +WEB_ENGINE = native # webkit/native/ultralight + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS \ + DEVELOPER_NAME="\"\\\"$$DEVELOPER_NAME\\\"\"" APP_NAME="\"\\\"$$APP_NAME\\\"\"" \ + APP_VERSION=$$APP_VERSION WEBKIT_VERSION=$$WEBKIT_VERSION + +equals(WEB_ENGINE, 'webkit'): DEFINES += USE_WEBKIT=1 USE_ULTRALIGHT=0 +else: equals(WEB_ENGINE, 'ultralight'): DEFINES += USE_WEBKIT=0 USE_ULTRALIGHT=1 +else: DEFINES += USE_WEBKIT=0 USE_ULTRALIGHT=0 + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +equals(WEB_ENGINE, 'webkit'): SOURCES += qwebkitwebview.cpp +else: equals(WEB_ENGINE, 'ultralight'): SOURCES += qultralightwebview.cpp +else: SOURCES += qnativewebview.cpp + +HEADERS += \ + iqwebview.h \ + mainwindow.h + +equals(WEB_ENGINE, 'webkit'): HEADERS += qwebkitwebview.h +else: equals(WEB_ENGINE, 'ultralight'): HEADERS += qultralightwebview.h +else: HEADERS += qnativewebview.h webview.h webview2.h + +FORMS += \ + mainwindow.ui + +CONFIG(debug, debug|release):win32: LIBS += -L$$PWD/./ -lqtadvanceddockingd +else: LIBS += -L$$PWD/./ -lqtadvanceddocking + +win32:equals(WEB_ENGINE, 'native'): LIBS += -lWebView2Loader +win32:equals(WEB_ENGINE, 'webkit'): LIBS += -luser32 +equals(WEB_ENGINE, 'ultralight'): LIBS += -L$$PWD/ultralight/ -lUltralight -lUltralightCore -lAppCore -lWebCore + +INCLUDEPATH += $$PWD/ads +equals(WEB_ENGINE, 'ultralight'): INCLUDEPATH += $$PWD/ultralight/include + +DEPENDPATH += $$PWD/ads +equals(WEB_ENGINE, 'ultralight'): DEPENDPATH += $$PWD/ultralight/include + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + res.qrc + +DISTFILES += \ + +RC_ICONS = $$PWD/icons/splitbrowser.ico + +DESTDIR = $$OUT_PWD/$$WEB_ENGINE +OBJECTS_DIR = $$DESTDIR/.obj +MOC_DIR = $$DESTDIR/.moc +RCC_DIR = $$DESTDIR/.qrc +UI_DIR = $$DESTDIR/.ui + + +ultralightBin.files = $$files($$PWD/../ultralight/bin/*.dll) +ultralightBin.path = $$DESTDIR + +ultralightRes.files = $$files($$PWD/../ultralight/bin/resources/*) +ultralightRes.path = $$DESTDIR/assets/resources + +equals(WEB_ENGINE, 'ultralight'): COPIES += ultralightBin ultralightRes diff --git a/splitbrowser.pro.user b/splitbrowser.pro.user new file mode 100644 index 0000000..8c613c2 --- /dev/null +++ b/splitbrowser.pro.user @@ -0,0 +1,340 @@ + + + + + + EnvironmentId + {a0074964-3edf-47ce-982a-8747de1e7b39} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.14.2 MSVC2017 64bit + Desktop Qt 5.14.2 MSVC2017 64bit + qt.qt5.5142.win64_msvc2017_64_kit + 1 + 0 + 0 + + true + 0 + C:\Users\Jerzy\Workspace\build-splitbrowser-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug + C:/Users/Jerzy/Workspace/build-splitbrowser-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + C:\Users\Jerzy\Workspace\build-splitbrowser-Desktop_Qt_5_14_2_MSVC2017_64bit-Release + C:/Users/Jerzy/Workspace/build-splitbrowser-Desktop_Qt_5_14_2_MSVC2017_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 2 + 2 + + + true + 0 + C:\Users\Jerzy\Workspace\build-splitbrowser-Desktop_Qt_5_14_2_MSVC2017_64bit-Profile + C:/Users/Jerzy/Workspace/build-splitbrowser-Desktop_Qt_5_14_2_MSVC2017_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + true + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Jerzy/Workspace/splitbrowser/splitbrowser.pro + C:/Users/Jerzy/Workspace/splitbrowser/splitbrowser.pro + + false + + false + true + true + false + false + false + + C:/Users/Jerzy/Workspace/build-splitbrowser-Desktop_Qt_5_14_2_MSVC2017_64bit-Release/native + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/webview.h b/webview.h new file mode 100644 index 0000000..d27ad25 --- /dev/null +++ b/webview.h @@ -0,0 +1,1523 @@ +/* + * MIT License + * + * Copyright (c) 2017 Serge Zaitsev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef WEBVIEW_H +#define WEBVIEW_H + +#ifndef WEBVIEW_API +#define WEBVIEW_API extern +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *webview_t; + +// Creates a new webview instance. If debug is non-zero - developer tools will +// be enabled (if the platform supports them). Window parameter can be a +// pointer to the native window handle. If it's non-null - then child WebView +// is embedded into the given parent window. Otherwise a new window is created. +// Depending on the platform, a GtkWindow, NSWindow or HWND pointer can be +// passed here. +WEBVIEW_API webview_t webview_create(int debug, void *window); + +// Destroys a webview +WEBVIEW_API void webview_destroy(webview_t w); + +// Steps one step in the main loop +WEBVIEW_API int webview_step(webview_t w, int blocking); + +// Runs the main loop until it's terminated. After this function exits - you +// must destroy the webview. +WEBVIEW_API void webview_run(webview_t w); + +// Stops the main loop. It is safe to call this function from another other +// background thread. +WEBVIEW_API void webview_terminate(webview_t w); + +// Posts a function to be executed on the main thread. You normally do not need +// to call this function, unless you want to tweak the native window. +WEBVIEW_API void +webview_dispatch(webview_t w, void (*fn)(webview_t w, void *arg), void *arg); + +// Returns a native window handle pointer. When using GTK backend the pointer +// is GtkWindow pointer, when using Cocoa backend the pointer is NSWindow +// pointer, when using Win32 backend the pointer is HWND pointer. +WEBVIEW_API void *webview_get_window(webview_t w); + +// Updates the title of the native window. Must be called from the UI thread. +WEBVIEW_API void webview_set_title(webview_t w, const char *title); + +// Window size hints +#define WEBVIEW_HINT_NONE 0 // Width and height are default size +#define WEBVIEW_HINT_MIN 1 // Width and height are minimum bounds +#define WEBVIEW_HINT_MAX 2 // Width and height are maximum bounds +#define WEBVIEW_HINT_FIXED 3 // Window size can not be changed by a user + +// Updates native window size. See WEBVIEW_HINT constants. +WEBVIEW_API void webview_set_size(webview_t w, int width, int height, + int hints); + +// Navigates webview to the given URL. URL may be a properly encoded data URI. +// Examples: +// webview_navigate(w, "https://github.com/webview/webview"); +// webview_navigate(w, "data:text/html,%3Ch1%3EHello%3C%2Fh1%3E"); +// webview_navigate(w, "data:text/html;base64,PGgxPkhlbGxvPC9oMT4="); +WEBVIEW_API void webview_navigate(webview_t w, const char *url); + +// Set webview HTML directly. +// Example: webview_set_html(w, "

Hello

"); +WEBVIEW_API void webview_set_html(webview_t w, const char *html); + +WEBVIEW_API void webview_go_back(webview_t w); + +WEBVIEW_API void webview_go_forward(webview_t w); + +WEBVIEW_API void webview_reload(webview_t w); + +WEBVIEW_API void webview_stop(webview_t w); + +WEBVIEW_API char *webview_get_title(webview_t w); + +WEBVIEW_API char *webview_get_url(webview_t w); + +// Injects JavaScript code at the initialization of the new page. Every time +// the webview will open a the new page - this initialization code will be +// executed. It is guaranteed that code is executed before window.onload. +WEBVIEW_API void webview_init(webview_t w, const char *js); + +// Evaluates arbitrary JavaScript code. Evaluation happens asynchronously, also +// the result of the expression is ignored. Use RPC bindings if you want to +// receive notifications about the results of the evaluation. +WEBVIEW_API void webview_eval(webview_t w, const char *js); + +// Binds a native C callback so that it will appear under the given name as a +// global JavaScript function. Internally it uses webview_init(). Callback +// receives a request string and a user-provided argument pointer. Request +// string is a JSON array of all the arguments passed to the JavaScript +// function. +WEBVIEW_API void webview_bind(webview_t w, const char *name, + void (*fn)(const char *seq, const char *req, + void *arg), + void *arg); + +// Removes a native C callback that was previously set by webview_bind. +WEBVIEW_API void webview_unbind(webview_t w, const char *name); + +// Allows to return a value from the native binding. Original request pointer +// must be provided to help internal RPC engine match requests with responses. +// If status is zero - result is expected to be a valid JSON result value. +// If status is not zero - result is an error JSON object. +WEBVIEW_API void webview_return(webview_t w, const char *seq, int status, + const char *result); + +#ifdef __cplusplus +} +#endif + +#ifndef WEBVIEW_HEADER + +#if !defined(WEBVIEW_GTK) && !defined(WEBVIEW_COCOA) && !defined(WEBVIEW_EDGE) +#if defined(__APPLE__) +#define WEBVIEW_COCOA +#elif defined(__unix__) +#define WEBVIEW_GTK +#elif defined(_WIN32) +#define WEBVIEW_EDGE +#else +#error "please, specify webview backend" +#endif +#endif + +#ifndef WEBVIEW_DEPRECATED +#if __cplusplus >= 201402L +#define WEBVIEW_DEPRECATED(reason) [[deprecated(reason)]] +#elif defined(_MSC_VER) +#define WEBVIEW_DEPRECATED(reason) __declspec(deprecated(reason)) +#else +#define WEBVIEW_DEPRECATED(reason) __attribute__((deprecated(reason))) +#endif +#endif + +#ifndef WEBVIEW_DEPRECATED_PRIVATE +#define WEBVIEW_DEPRECATED_PRIVATE \ + WEBVIEW_DEPRECATED("Private API should not be used") +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace webview { + +using dispatch_fn_t = std::function; + +namespace detail { + +// Percent-encodes (%xx) each character of a string. +inline std::string percent_encode(const std::string &s) { + static const std::array alphabet{'0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F'}; + static const int output_chars_per_input_char = 3; + std::string encoded; + encoded.reserve(s.size() * output_chars_per_input_char); + for (char c : s) { + auto uc = static_cast(c); + encoded += '%'; + encoded += alphabet[uc >> 4]; + encoded += alphabet[uc & 15]; + } + return encoded; +} + +inline int json_parse_c(const char *s, size_t sz, const char *key, size_t keysz, + const char **value, size_t *valuesz) { + enum { + JSON_STATE_VALUE, + JSON_STATE_LITERAL, + JSON_STATE_STRING, + JSON_STATE_ESCAPE, + JSON_STATE_UTF8 + } state = JSON_STATE_VALUE; + const char *k = NULL; + int index = 1; + int depth = 0; + int utf8_bytes = 0; + + if (key == NULL) { + index = (int) keysz; + keysz = 0; + } + + *value = NULL; + *valuesz = 0; + + for (; sz > 0; s++, sz--) { + enum { + JSON_ACTION_NONE, + JSON_ACTION_START, + JSON_ACTION_END, + JSON_ACTION_START_STRUCT, + JSON_ACTION_END_STRUCT + } action = JSON_ACTION_NONE; + unsigned char c = *s; + switch (state) { + case JSON_STATE_VALUE: + if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == ',' || + c == ':') { + continue; + } else if (c == '"') { + action = JSON_ACTION_START; + state = JSON_STATE_STRING; + } else if (c == '{' || c == '[') { + action = JSON_ACTION_START_STRUCT; + } else if (c == '}' || c == ']') { + action = JSON_ACTION_END_STRUCT; + } else if (c == 't' || c == 'f' || c == 'n' || c == '-' || + (c >= '0' && c <= '9')) { + action = JSON_ACTION_START; + state = JSON_STATE_LITERAL; + } else { + return -1; + } + break; + case JSON_STATE_LITERAL: + if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == ',' || + c == ']' || c == '}' || c == ':') { + state = JSON_STATE_VALUE; + s--; + sz++; + action = JSON_ACTION_END; + } else if (c < 32 || c > 126) { + return -1; + } // fallthrough + case JSON_STATE_STRING: + if (c < 32 || (c > 126 && c < 192)) { + return -1; + } else if (c == '"') { + action = JSON_ACTION_END; + state = JSON_STATE_VALUE; + } else if (c == '\\') { + state = JSON_STATE_ESCAPE; + } else if (c >= 192 && c < 224) { + utf8_bytes = 1; + state = JSON_STATE_UTF8; + } else if (c >= 224 && c < 240) { + utf8_bytes = 2; + state = JSON_STATE_UTF8; + } else if (c >= 240 && c < 247) { + utf8_bytes = 3; + state = JSON_STATE_UTF8; + } else if (c >= 128 && c < 192) { + return -1; + } + break; + case JSON_STATE_ESCAPE: + if (c == '"' || c == '\\' || c == '/' || c == 'b' || c == 'f' || + c == 'n' || c == 'r' || c == 't' || c == 'u') { + state = JSON_STATE_STRING; + } else { + return -1; + } + break; + case JSON_STATE_UTF8: + if (c < 128 || c > 191) { + return -1; + } + utf8_bytes--; + if (utf8_bytes == 0) { + state = JSON_STATE_STRING; + } + break; + default: + return -1; + } + + if (action == JSON_ACTION_END_STRUCT) { + depth--; + } + + if (depth == 1) { + if (action == JSON_ACTION_START || action == JSON_ACTION_START_STRUCT) { + if (index == 0) { + *value = s; + } else if (keysz > 0 && index == 1) { + k = s; + } else { + index--; + } + } else if (action == JSON_ACTION_END || + action == JSON_ACTION_END_STRUCT) { + if (*value != NULL && index == 0) { + *valuesz = (size_t)(s + 1 - *value); + return 0; + } else if (keysz > 0 && k != NULL) { + if (keysz == (size_t)(s - k - 1) && memcmp(key, k + 1, keysz) == 0) { + index = 0; + } else { + index = 2; + } + k = NULL; + } + } + } + + if (action == JSON_ACTION_START_STRUCT) { + depth++; + } + } + return -1; +} + +inline std::string json_escape(const std::string &s) { + // TODO: implement + return '"' + s + '"'; +} + +inline int json_unescape(const char *s, size_t n, char *out) { + int r = 0; + if (*s++ != '"') { + return -1; + } + while (n > 2) { + char c = *s; + if (c == '\\') { + s++; + n--; + switch (*s) { + case 'b': + c = '\b'; + break; + case 'f': + c = '\f'; + break; + case 'n': + c = '\n'; + break; + case 'r': + c = '\r'; + break; + case 't': + c = '\t'; + break; + case '\\': + c = '\\'; + break; + case '/': + c = '/'; + break; + case '\"': + c = '\"'; + break; + default: // TODO: support unicode decoding + return -1; + } + } + if (out != NULL) { + *out++ = c; + } + s++; + n--; + r++; + } + if (*s != '"') { + return -1; + } + if (out != NULL) { + *out = '\0'; + } + return r; +} + +inline std::string json_parse(const std::string &s, const std::string &key, + const int index) { + const char *value; + size_t value_sz; + if (key == "") { + json_parse_c(s.c_str(), s.length(), nullptr, index, &value, &value_sz); + } else { + json_parse_c(s.c_str(), s.length(), key.c_str(), key.length(), &value, + &value_sz); + } + if (value != nullptr) { + if (value[0] != '"') { + return std::string(value, value_sz); + } + int n = json_unescape(value, value_sz, nullptr); + if (n > 0) { + char *decoded = new char[n + 1]; + json_unescape(value, value_sz, decoded); + std::string result(decoded, n); + delete[] decoded; + return result; + } + } + return ""; +} + +} // namespace detail + +WEBVIEW_DEPRECATED_PRIVATE +inline int json_parse_c(const char *s, size_t sz, const char *key, size_t keysz, + const char **value, size_t *valuesz) { + return detail::json_parse_c(s, sz, key, keysz, value, valuesz); +} + +WEBVIEW_DEPRECATED_PRIVATE +inline std::string json_escape(const std::string &s) { + return detail::json_escape(s); +} + +WEBVIEW_DEPRECATED_PRIVATE +inline int json_unescape(const char *s, size_t n, char *out) { + return detail::json_unescape(s, n, out); +} + +WEBVIEW_DEPRECATED_PRIVATE +inline std::string json_parse(const std::string &s, const std::string &key, + const int index) { + return detail::json_parse(s, key, index); +} + +} // namespace webview + +#if defined(WEBVIEW_GTK) +// +// ==================================================================== +// +// This implementation uses webkit2gtk backend. It requires gtk+3.0 and +// webkit2gtk-4.0 libraries. Proper compiler flags can be retrieved via: +// +// pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0 +// +// ==================================================================== +// +#include +#include +#include + +namespace webview { +namespace detail { + +class gtk_webkit_engine { +public: + gtk_webkit_engine(bool debug, void *window) + : m_window(static_cast(window)) { + if (gtk_init_check(0, NULL) == FALSE) { + return; + } + m_window = static_cast(window); + if (m_window == nullptr) { + m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + } + g_signal_connect(G_OBJECT(m_window), "destroy", + G_CALLBACK(+[](GtkWidget *, gpointer arg) { + static_cast(arg)->terminate(); + }), + this); + // Initialize webview widget + m_webview = webkit_web_view_new(); + WebKitUserContentManager *manager = + webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(m_webview)); + g_signal_connect(manager, "script-message-received::external", + G_CALLBACK(+[](WebKitUserContentManager *, + WebKitJavascriptResult *r, gpointer arg) { + auto *w = static_cast(arg); + char *s = get_string_from_js_result(r); + w->on_message(s); + g_free(s); + }), + this); + webkit_user_content_manager_register_script_message_handler(manager, + "external"); + init("window.external={invoke:function(s){window.webkit.messageHandlers." + "external.postMessage(s);}}"); + + gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_webview)); + gtk_widget_grab_focus(GTK_WIDGET(m_webview)); + + WebKitSettings *settings = + webkit_web_view_get_settings(WEBKIT_WEB_VIEW(m_webview)); + webkit_settings_set_javascript_can_access_clipboard(settings, true); + if (debug) { + webkit_settings_set_enable_write_console_messages_to_stdout(settings, + true); + webkit_settings_set_enable_developer_extras(settings, true); + } + + gtk_window_minimize(m_window); + gtk_widget_show_all(m_window); + } + virtual ~gtk_webkit_engine() = default; + void *window() { return (void *)m_window; } + int step(int blocking) { return gtk_main_iteration_do(blocking); } + void run() { gtk_main(); } + void terminate() { /*gtk_main_quit();*/ } + void dispatch(std::function f) { + g_idle_add_full(G_PRIORITY_HIGH_IDLE, (GSourceFunc)([](void *f) -> int { + (*static_cast(f))(); + return G_SOURCE_REMOVE; + }), + new std::function(f), + [](void *f) { delete static_cast(f); }); + } + + void set_title(const std::string &title) { + gtk_window_set_title(GTK_WINDOW(m_window), title.c_str()); + } + + void set_size(int width, int height, int hints) { + gtk_window_set_resizable(GTK_WINDOW(m_window), hints != WEBVIEW_HINT_FIXED); + if (hints == WEBVIEW_HINT_NONE) { + gtk_window_resize(GTK_WINDOW(m_window), width, height); + } else if (hints == WEBVIEW_HINT_FIXED) { + gtk_widget_set_size_request(m_window, width, height); + } else { + GdkGeometry g; + g.min_width = g.max_width = width; + g.min_height = g.max_height = height; + GdkWindowHints h = + (hints == WEBVIEW_HINT_MIN ? GDK_HINT_MIN_SIZE : GDK_HINT_MAX_SIZE); + // This defines either MIN_SIZE, or MAX_SIZE, but not both: + gtk_window_set_geometry_hints(GTK_WINDOW(m_window), nullptr, &g, h); + } + } + + void navigate(const std::string &url) { + webkit_web_view_load_uri(WEBKIT_WEB_VIEW(m_webview), url.c_str()); + } + + void set_html(const std::string &html) { + webkit_web_view_load_html(WEBKIT_WEB_VIEW(m_webview), html.c_str(), NULL); + } + + void go_back() { + if(webkit_web_view_can_go_back(WEBKIT_WEB_VIEW(m_webview))) + webkit_web_view_go_back(WEBKIT_WEB_VIEW(m_webview)); + } + + void go_forward() { + if(webkit_web_view_can_go_forward(WEBKIT_WEB_VIEW(m_webview))) + webkit_web_view_go_forward(WEBKIT_WEB_VIEW(m_webview)); + } + + void reload() { + webkit_web_view_reload(WEBKIT_WEB_VIEW(m_webview)); + } + + void stop() { + webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(m_webview)); + } + + char *get_title() { + return webkit_web_view_get_title(WEBKIT_WEB_VIEW(m_webview)); + } + + char *get_url() { + return webkit_web_view_get_uri(WEBKIT_WEB_VIEW(m_webview)); + } + + void init(const std::string &js) { + WebKitUserContentManager *manager = + webkit_web_view_get_user_content_manager(WEBKIT_WEB_VIEW(m_webview)); + webkit_user_content_manager_add_script( + manager, webkit_user_script_new( + js.c_str(), WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, + WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, NULL, NULL)); + } + + void eval(const std::string &js) { + webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(m_webview), js.c_str(), NULL, + NULL, NULL); + } + +private: + virtual void on_message(const std::string &msg) = 0; + + static char *get_string_from_js_result(WebKitJavascriptResult *r) { + char *s; +#if WEBKIT_MAJOR_VERSION >= 2 && WEBKIT_MINOR_VERSION >= 22 + JSCValue *value = webkit_javascript_result_get_js_value(r); + s = jsc_value_to_string(value); +#else + JSGlobalContextRef ctx = webkit_javascript_result_get_global_context(r); + JSValueRef value = webkit_javascript_result_get_value(r); + JSStringRef js = JSValueToStringCopy(ctx, value, NULL); + size_t n = JSStringGetMaximumUTF8CStringSize(js); + s = g_new(char, n); + JSStringGetUTF8CString(js, s, n); + JSStringRelease(js); +#endif + return s; + } + + GtkWidget *m_window; + GtkWidget *m_webview; +}; + +} // namespace detail + +using browser_engine = detail::gtk_webkit_engine; + +} // namespace webview + +#elif defined(WEBVIEW_COCOA) + +// +// ==================================================================== +// +// This implementation uses Cocoa WKWebView backend on macOS. It is +// written using ObjC runtime and uses WKWebView class as a browser runtime. +// You should pass "-framework Webkit" flag to the compiler. +// +// ==================================================================== +// + +#include +#include + +#define NSApplicationDefinedEvent 15 +#define NSBackingStoreBuffered 2 +#define NSEventMaskAny ULONG_MAX + +#define NSWindowStyleMaskResizable 8 +#define NSWindowStyleMaskMiniaturizable 4 +#define NSWindowStyleMaskTitled 1 +#define NSWindowStyleMaskClosable 2 + +#define NSApplicationActivationPolicyRegular 0 + +#define WKUserScriptInjectionTimeAtDocumentStart 0 + +namespace webview { +namespace detail { + +// Helpers to avoid too much typing +id operator"" _cls(const char *s, std::size_t) { return (id)objc_getClass(s); } +SEL operator"" _sel(const char *s, std::size_t) { return sel_registerName(s); } +id operator"" _str(const char *s, std::size_t) { + return ((id(*)(id, SEL, const char *))objc_msgSend)( + "NSString"_cls, "stringWithUTF8String:"_sel, s); +} + +class cocoa_wkwebview_engine { +public: + cocoa_wkwebview_engine(bool debug, void *window) { + // Application + id app = ((id(*)(id, SEL))objc_msgSend)("NSApplication"_cls, + "sharedApplication"_sel); + ((void (*)(id, SEL, long))objc_msgSend)( + app, "setActivationPolicy:"_sel, NSApplicationActivationPolicyRegular); + + // Delegate + auto cls = + objc_allocateClassPair((Class) "NSResponder"_cls, "AppDelegate", 0); + class_addProtocol(cls, objc_getProtocol("NSTouchBarProvider")); + class_addMethod(cls, "applicationShouldTerminateAfterLastWindowClosed:"_sel, + (IMP)(+[](id, SEL, id) -> BOOL { return 1; }), "c@:@"); + class_addMethod(cls, "userContentController:didReceiveScriptMessage:"_sel, + (IMP)(+[](id self, SEL, id, id msg) { + auto w = + (cocoa_wkwebview_engine *)objc_getAssociatedObject( + self, "webview"); + assert(w); + w->on_message(((const char *(*)(id, SEL))objc_msgSend)( + ((id(*)(id, SEL))objc_msgSend)(msg, "body"_sel), + "UTF8String"_sel)); + }), + "v@:@@"); + objc_registerClassPair(cls); + + auto delegate = ((id(*)(id, SEL))objc_msgSend)((id)cls, "new"_sel); + objc_setAssociatedObject(delegate, "webview", (id)this, + OBJC_ASSOCIATION_ASSIGN); + ((void (*)(id, SEL, id))objc_msgSend)(app, "setDelegate:"_sel, delegate); + + // Main window + if (window == nullptr) { + m_window = ((id(*)(id, SEL))objc_msgSend)("NSWindow"_cls, "alloc"_sel); + m_window = + ((id(*)(id, SEL, CGRect, int, unsigned long, int))objc_msgSend)( + m_window, "initWithContentRect:styleMask:backing:defer:"_sel, + CGRectMake(0, 0, 0, 0), 0, NSBackingStoreBuffered, 0); + } else { + m_window = (id)window; + } + + // Step + auto window_cls = + objc_allocateClassPair((Class) "NSObject"_cls, "WindowDelegate", 0); + class_addProtocol(window_cls, objc_getProtocol("NSWindowDelegate")); + class_replaceMethod( + window_cls, "windowWillClose:"_sel, (IMP)(+[](id self, SEL, id) { + auto w = (cocoa_wkwebview_engine *)objc_getAssociatedObject( + self, "webview"); + assert(w); + w->should_exit = 1; + }), "v@:@"); + class_replaceMethod(window_cls, "windowShouldClose:"_sel, + (IMP)(+[](id, SEL, id) -> BOOL { return 1; }), "B@:@"); + objc_registerClassPair(window_cls); + auto window_delegate = + ((id(*)(id, SEL))objc_msgSend)((id)window_cls, "new"_sel); + objc_setAssociatedObject(window_delegate, "webview", (id)this, + OBJC_ASSOCIATION_ASSIGN); + ((void (*)(id, SEL, id))objc_msgSend)(m_window, "setDelegate:"_sel, + window_delegate); + + // Webview + auto config = + ((id(*)(id, SEL))objc_msgSend)("WKWebViewConfiguration"_cls, "new"_sel); + m_manager = + ((id(*)(id, SEL))objc_msgSend)(config, "userContentController"_sel); + m_webview = ((id(*)(id, SEL))objc_msgSend)("WKWebView"_cls, "alloc"_sel); + + if (debug) { + // Equivalent Obj-C: + // [[config preferences] setValue:@YES forKey:@"developerExtrasEnabled"]; + ((id(*)(id, SEL, id, id))objc_msgSend)( + ((id(*)(id, SEL))objc_msgSend)(config, "preferences"_sel), + "setValue:forKey:"_sel, + ((id(*)(id, SEL, BOOL))objc_msgSend)("NSNumber"_cls, + "numberWithBool:"_sel, 1), + "developerExtrasEnabled"_str); + } + + // Equivalent Obj-C: + // [[config preferences] setValue:@YES forKey:@"fullScreenEnabled"]; + ((id(*)(id, SEL, id, id))objc_msgSend)( + ((id(*)(id, SEL))objc_msgSend)(config, "preferences"_sel), + "setValue:forKey:"_sel, + ((id(*)(id, SEL, BOOL))objc_msgSend)("NSNumber"_cls, + "numberWithBool:"_sel, 1), + "fullScreenEnabled"_str); + + // Equivalent Obj-C: + // [[config preferences] setValue:@YES forKey:@"javaScriptCanAccessClipboard"]; + ((id(*)(id, SEL, id, id))objc_msgSend)( + ((id(*)(id, SEL))objc_msgSend)(config, "preferences"_sel), + "setValue:forKey:"_sel, + ((id(*)(id, SEL, BOOL))objc_msgSend)("NSNumber"_cls, + "numberWithBool:"_sel, 1), + "javaScriptCanAccessClipboard"_str); + + // Equivalent Obj-C: + // [[config preferences] setValue:@YES forKey:@"DOMPasteAllowed"]; + ((id(*)(id, SEL, id, id))objc_msgSend)( + ((id(*)(id, SEL))objc_msgSend)(config, "preferences"_sel), + "setValue:forKey:"_sel, + ((id(*)(id, SEL, BOOL))objc_msgSend)("NSNumber"_cls, + "numberWithBool:"_sel, 1), + "DOMPasteAllowed"_str); + + ((void (*)(id, SEL, CGRect, id))objc_msgSend)( + m_webview, "initWithFrame:configuration:"_sel, CGRectMake(0, 0, 0, 0), + config); + ((void (*)(id, SEL, id, id))objc_msgSend)( + m_manager, "addScriptMessageHandler:name:"_sel, delegate, + "external"_str); + + init(R"script( + window.external = { + invoke: function(s) { + window.webkit.messageHandlers.external.postMessage(s); + }, + }; + )script"); + ((void (*)(id, SEL, id))objc_msgSend)(m_window, "setContentView:"_sel, + m_webview); + ((void (*)(id, SEL, id))objc_msgSend)(m_window, "miniaturize:"_sel, nullptr); + //((void (*)(id, SEL, id))objc_msgSend)(m_window, "makeKeyAndOrderFront:"_sel, + // nullptr); + } + virtual ~cocoa_wkwebview_engine() { close(); } + void *window() { return (void *)m_window; } + void terminate() { + close(); +// ((void (*)(id, SEL, id))objc_msgSend)("NSApp"_cls, "terminate:"_sel, +// nullptr); + } + int step(int blocking) { + id until = + (blocking + ? ((id(*)(id, SEL))objc_msgSend)("NSDate"_cls, "distantFuture"_sel) + : ((id(*)(id, SEL))objc_msgSend)("NSDate"_cls, "distantPast"_sel)); + id app = ((id(*)(id, SEL))objc_msgSend)("NSApplication"_cls, + "sharedApplication"_sel); + id event = ((id(*)(id, SEL, unsigned long long, id, id, bool))objc_msgSend)( + app, "nextEventMatchingMask:untilDate:inMode:dequeue:"_sel, ULONG_MAX, + until, "kCFRunLoopDefaultMode"_str, true); + if (event) { + ((id(*)(id, SEL, id))objc_msgSend)(app, "sendEvent:"_sel, event); + } + return should_exit; + } + void run() { + id app = ((id(*)(id, SEL))objc_msgSend)("NSApplication"_cls, + "sharedApplication"_sel); + dispatch([&]() { + ((void (*)(id, SEL, BOOL))objc_msgSend)( + app, "activateIgnoringOtherApps:"_sel, 1); + }); + ((void (*)(id, SEL))objc_msgSend)(app, "run"_sel); + } + void dispatch(std::function f) { + dispatch_async_f(dispatch_get_main_queue(), new dispatch_fn_t(f), + (dispatch_function_t)([](void *arg) { + auto f = static_cast(arg); + (*f)(); + delete f; + })); + } + void set_title(const std::string &title) { + ((void (*)(id, SEL, id))objc_msgSend)( + m_window, "setTitle:"_sel, + ((id(*)(id, SEL, const char *))objc_msgSend)( + "NSString"_cls, "stringWithUTF8String:"_sel, title.c_str())); + } + void set_size(int width, int height, int hints) { + auto style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | + NSWindowStyleMaskMiniaturizable; + if (hints != WEBVIEW_HINT_FIXED) { + style = style | NSWindowStyleMaskResizable; + } + ((void (*)(id, SEL, unsigned long))objc_msgSend)( + m_window, "setStyleMask:"_sel, style); + + if (hints == WEBVIEW_HINT_MIN) { + ((void (*)(id, SEL, CGSize))objc_msgSend)( + m_window, "setContentMinSize:"_sel, CGSizeMake(width, height)); + } else if (hints == WEBVIEW_HINT_MAX) { + ((void (*)(id, SEL, CGSize))objc_msgSend)( + m_window, "setContentMaxSize:"_sel, CGSizeMake(width, height)); + } else { + ((void (*)(id, SEL, CGRect, BOOL, BOOL))objc_msgSend)( + m_window, "setFrame:display:animate:"_sel, + CGRectMake(0, 0, width, height), 1, 0); + } + ((void (*)(id, SEL))objc_msgSend)(m_window, "center"_sel); + } + void navigate(const std::string &url) { + auto nsurl = ((id(*)(id, SEL, id))objc_msgSend)( + "NSURL"_cls, "URLWithString:"_sel, + ((id(*)(id, SEL, const char *))objc_msgSend)( + "NSString"_cls, "stringWithUTF8String:"_sel, url.c_str())); + + ((void (*)(id, SEL, id))objc_msgSend)( + m_webview, "loadRequest:"_sel, + ((id(*)(id, SEL, id))objc_msgSend)("NSURLRequest"_cls, + "requestWithURL:"_sel, nsurl)); + } + void set_html(const std::string &html) { + ((void (*)(id, SEL, id, id))objc_msgSend)( + m_webview, "loadHTMLString:baseURL:"_sel, + ((id(*)(id, SEL, const char *))objc_msgSend)( + "NSString"_cls, "stringWithUTF8String:"_sel, html.c_str()), + nullptr); + } + void go_back() { + if(((bool (*)(id, SEL))objc_msgSend)( + m_webview, "canGoBack:"_sel)) + ((void (*)(id, SEL))objc_msgSend)( + m_webview, "goBack:"_sel); + } + void go_forward() { + if(((bool (*)(id, SEL))objc_msgSend)( + m_webview, "canGoForward:"_sel)) + ((void (*)(id, SEL))objc_msgSend)( + m_webview, "goForward:"_sel); + } + void reload() { + ((void (*)(id, SEL))objc_msgSend)( + m_webview, "reload:"_sel); + } + void stop() { + ((void (*)(id, SEL))objc_msgSend)( + m_webview, "stopLoading:"_sel); + } + char *get_title() { + return ((char *(*)(id, SEL))objc_msgSend)( + m_webview, "title:"_sel); + } + char *get_url() { + return ((char *(*)(id, SEL))objc_msgSend)( + m_webview, "url:"_sel); + } + void init(const std::string &js) { + // Equivalent Obj-C: + // [m_manager addUserScript:[[WKUserScript alloc] initWithSource:[NSString stringWithUTF8String:js.c_str()] injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]] + ((void (*)(id, SEL, id))objc_msgSend)( + m_manager, "addUserScript:"_sel, + ((id(*)(id, SEL, id, long, BOOL))objc_msgSend)( + ((id(*)(id, SEL))objc_msgSend)("WKUserScript"_cls, "alloc"_sel), + "initWithSource:injectionTime:forMainFrameOnly:"_sel, + ((id(*)(id, SEL, const char *))objc_msgSend)( + "NSString"_cls, "stringWithUTF8String:"_sel, js.c_str()), + WKUserScriptInjectionTimeAtDocumentStart, 1)); + } + void eval(const std::string &js) { + ((void (*)(id, SEL, id, id))objc_msgSend)( + m_webview, "evaluateJavaScript:completionHandler:"_sel, + ((id(*)(id, SEL, const char *))objc_msgSend)( + "NSString"_cls, "stringWithUTF8String:"_sel, js.c_str()), + nullptr); + } + +private: + virtual void on_message(const std::string &msg) = 0; + void close() { ((void (*)(id, SEL))objc_msgSend)(m_window, "close"_sel); } + int should_exit = 0; + id m_window; + id m_webview; + id m_manager; +}; + +} // namespace detail + +using browser_engine = detail::cocoa_wkwebview_engine; + +} // namespace webview + +#elif defined(WEBVIEW_EDGE) + +// +// ==================================================================== +// +// This implementation uses Win32 API to create a native window. It +// uses Edge/Chromium webview2 backend as a browser engine. +// +// ==================================================================== +// + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include + +#include "webview2.h" + +#pragma comment(lib, "user32.lib") +#pragma comment(lib, "Shlwapi.lib") +#pragma comment(lib, "windowsapp") +#pragma comment(lib, "shell32.lib") + +namespace webview { +namespace detail { + +using msg_cb_t = std::function; +using namespace winrt; + +class win32_edge_engine { +public: + win32_edge_engine(bool debug, void *window) { + if (window == nullptr) { + HINSTANCE hInstance = GetModuleHandle(nullptr); + HICON icon = (HICON)LoadImage( + hInstance, IDI_APPLICATION, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); + + WNDCLASSEXW wc; + ZeroMemory(&wc, sizeof(WNDCLASSEX)); + wc.cbSize = sizeof(WNDCLASSEX); + wc.hInstance = hInstance; + wc.lpszClassName = L"webview"; + wc.hIcon = icon; + wc.hIconSm = icon; + wc.lpfnWndProc = + (WNDPROC)(+[](HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) -> LRESULT { + auto w = (win32_edge_engine *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + switch (msg) { + case WM_SIZE: + w->resize(hwnd); + break; + case WM_CLOSE: + DestroyWindow(hwnd); + break; + case WM_DESTROY: + w->terminate(); + break; + case WM_GETMINMAXINFO: { + auto lpmmi = (LPMINMAXINFO)lp; + if (w == nullptr) { + return 0; + } + if (w->m_maxsz.x > 0 && w->m_maxsz.y > 0) { + lpmmi->ptMaxSize = w->m_maxsz; + lpmmi->ptMaxTrackSize = w->m_maxsz; + } + if (w->m_minsz.x > 0 && w->m_minsz.y > 0) { + lpmmi->ptMinTrackSize = w->m_minsz; + } + } break; + default: + return DefWindowProcW(hwnd, msg, wp, lp); + } + return 0; + }); + RegisterClassExW(&wc); + m_window = CreateWindowW(L"webview", L"", WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, nullptr, + nullptr, hInstance, nullptr); + if (m_window == nullptr) { + return; + } + SetWindowLongPtr(m_window, GWLP_USERDATA, (LONG_PTR)this); + } else { + m_window = *(static_cast(window)); + } + + SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); + ShowWindow(m_window, SW_SHOWMINNOACTIVE); + UpdateWindow(m_window); + SetFocus(m_window); + + auto cb = + std::bind(&win32_edge_engine::on_message, this, std::placeholders::_1); + + embed(m_window, debug, cb); + resize(m_window); + m_controller->MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC); + } + + int step(int blocking) { + MSG msg; + if (blocking) { + if (GetMessage(&msg, nullptr, 0, 0) < 0) + return 0; + } else { + if (!PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) + return 0; + } + if (msg.hwnd) { + TranslateMessage(&msg); + DispatchMessage(&msg); + return 0; + } + + if (msg.message == WM_APP) { + auto f = (dispatch_fn_t *)(msg.lParam); + (*f)(); + delete f; + } else if (msg.message == WM_QUIT) { + return -1; + } + return 0; + } + + virtual ~win32_edge_engine() = default; + + void run() { + MSG msg; + BOOL res; + while ((res = GetMessage(&msg, nullptr, 0, 0)) != -1) { + if (msg.hwnd) { + TranslateMessage(&msg); + DispatchMessage(&msg); + continue; + } + if (msg.message == WM_APP) { + auto f = (dispatch_fn_t *)(msg.lParam); + (*f)(); + delete f; + } else if (msg.message == WM_QUIT) { + return; + } + } + } + void *window() { return (void *)m_window; } + void terminate() { /*PostQuitMessage(0);*/ } + void dispatch(dispatch_fn_t f) { + PostThreadMessage(m_main_thread, WM_APP, 0, (LPARAM) new dispatch_fn_t(f)); + } + + void set_title(const std::string &title) { + SetWindowTextW(m_window, winrt::to_hstring(title).c_str()); + } + + void set_size(int width, int height, int hints) { + auto style = GetWindowLong(m_window, GWL_STYLE); + if (hints == WEBVIEW_HINT_FIXED) { + style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); + } else { + style |= (WS_THICKFRAME | WS_MAXIMIZEBOX); + } + SetWindowLong(m_window, GWL_STYLE, style); + + if (hints == WEBVIEW_HINT_MAX) { + m_maxsz.x = width; + m_maxsz.y = height; + } else if (hints == WEBVIEW_HINT_MIN) { + m_minsz.x = width; + m_minsz.y = height; + } else { + RECT r; + r.left = r.top = 0; + r.right = width; + r.bottom = height; + AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, 0); + SetWindowPos( + m_window, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, + SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE | SWP_FRAMECHANGED); + resize(m_window); + } + } + + void navigate(const std::string &url) { + auto wurl = winrt::to_hstring(url); + m_webview->Navigate(wurl.c_str()); + } + + void go_back() { + BOOL canGoBack = FALSE; + m_webview->get_CanGoBack(&canGoBack); + if(canGoBack) + m_webview->GoBack(); + } + + void go_forward() { + BOOL canGoForward = FALSE; + m_webview->get_CanGoForward(&canGoForward); + if(canGoForward) + m_webview->GoForward(); + } + + void reload() { + m_webview->Reload(); + } + + void stop() { + m_webview->Stop(); + } + + char *get_title() { + LPWSTR wtitle; + m_webview->get_DocumentTitle(&wtitle); + int length = WideCharToMultiByte(CP_UTF8, 0, wtitle, -1, 0, 0, NULL, NULL); + char *title = new char[length]; + WideCharToMultiByte(CP_UTF8, 0, wtitle, -1, title, length, NULL, NULL); + return title; + } + + char *get_url() { + LPWSTR wurl; + m_webview->get_Source(&wurl); + int length = WideCharToMultiByte(CP_UTF8, 0, wurl, -1, 0, 0, NULL, NULL); + char *url = new char[length]; + WideCharToMultiByte(CP_UTF8, 0, wurl, -1, url, length, NULL, NULL); + return url; + } + + void init(const std::string &js) { + auto wjs = winrt::to_hstring(js); + m_webview->AddScriptToExecuteOnDocumentCreated(wjs.c_str(), nullptr); + } + + void eval(const std::string &js) { + auto wjs = winrt::to_hstring(js); + m_webview->ExecuteScript(wjs.c_str(), nullptr); + } + + void set_html(const std::string &html) { + auto html2 = + winrt::to_hstring("data:text/html," + detail::percent_encode(html)); + m_webview->Navigate(html2.c_str()); + } + +private: + bool embed(HWND wnd, bool debug, msg_cb_t cb) { + std::atomic_flag flag = ATOMIC_FLAG_INIT; + flag.test_and_set(); + + wchar_t currentExePath[MAX_PATH]; + GetModuleFileNameW(NULL, currentExePath, MAX_PATH); + wchar_t *currentExeName = PathFindFileNameW(currentExePath); + + wchar_t dataPath[MAX_PATH]; + if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, dataPath))) { + return false; + } + wchar_t userDataFolder[MAX_PATH]; + PathCombineW(userDataFolder, dataPath, currentExeName); + + HRESULT res = CreateCoreWebView2EnvironmentWithOptions( + nullptr, userDataFolder, nullptr, + new webview2_com_handler(wnd, cb, + [&](ICoreWebView2Controller *controller) { + m_controller = controller; + m_controller->get_CoreWebView2(&m_webview); + m_webview->AddRef(); + flag.clear(); + })); + if (res != S_OK) { + return false; + } + MSG msg = {}; + while (flag.test_and_set() && GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + init("window.external={invoke:s=>window.chrome.webview.postMessage(s)}"); + return true; + } + + void resize(HWND wnd) { + if (m_controller == nullptr) { + return; + } + RECT bounds; + GetClientRect(wnd, &bounds); + m_controller->put_Bounds(bounds); + } + + virtual void on_message(const std::string &msg) = 0; + + HWND m_window; + POINT m_minsz = POINT{0, 0}; + POINT m_maxsz = POINT{0, 0}; + DWORD m_main_thread = GetCurrentThreadId(); + ICoreWebView2 *m_webview = nullptr; + ICoreWebView2Controller *m_controller = nullptr; + + class webview2_com_handler + : public ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler, + public ICoreWebView2CreateCoreWebView2ControllerCompletedHandler, + public ICoreWebView2WebMessageReceivedEventHandler, + public ICoreWebView2PermissionRequestedEventHandler { + using webview2_com_handler_cb_t = + std::function; + + public: + webview2_com_handler(HWND hwnd, msg_cb_t msgCb, + webview2_com_handler_cb_t cb) + : m_window(hwnd), m_msgCb(msgCb), m_cb(cb) {} + ULONG STDMETHODCALLTYPE AddRef() { return 1; } + ULONG STDMETHODCALLTYPE Release() { return 1; } + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID *ppv) { + return S_OK; + } + HRESULT STDMETHODCALLTYPE Invoke(HRESULT res, + ICoreWebView2Environment *env) { + env->CreateCoreWebView2Controller(m_window, this); + return S_OK; + } + HRESULT STDMETHODCALLTYPE Invoke(HRESULT res, + ICoreWebView2Controller *controller) { + controller->AddRef(); + + ICoreWebView2 *webview; + ::EventRegistrationToken token; + controller->get_CoreWebView2(&webview); + webview->add_WebMessageReceived(this, &token); + webview->add_PermissionRequested(this, &token); + + m_cb(controller); + return S_OK; + } + HRESULT STDMETHODCALLTYPE Invoke( + ICoreWebView2 *sender, ICoreWebView2WebMessageReceivedEventArgs *args) { + LPWSTR message; + args->TryGetWebMessageAsString(&message); + m_msgCb(winrt::to_string(message)); + sender->PostWebMessageAsString(message); + + CoTaskMemFree(message); + return S_OK; + } + HRESULT STDMETHODCALLTYPE + Invoke(ICoreWebView2 *sender, + ICoreWebView2PermissionRequestedEventArgs *args) { + COREWEBVIEW2_PERMISSION_KIND kind; + args->get_PermissionKind(&kind); + if (kind == COREWEBVIEW2_PERMISSION_KIND_CLIPBOARD_READ) { + args->put_State(COREWEBVIEW2_PERMISSION_STATE_ALLOW); + } + return S_OK; + } + + private: + HWND m_window; + msg_cb_t m_msgCb; + webview2_com_handler_cb_t m_cb; + }; +}; + +} // namespace detail + +using browser_engine = detail::win32_edge_engine; + +} // namespace webview + +#endif /* WEBVIEW_GTK, WEBVIEW_COCOA, WEBVIEW_EDGE */ + +namespace webview { + +class webview : public browser_engine { +public: + webview(bool debug = false, void *wnd = nullptr) + : browser_engine(debug, wnd) {} + + void navigate(const std::string &url) { + if (url == "") { + browser_engine::navigate("about:blank"); + return; + } + browser_engine::navigate(url); + } + + using binding_t = std::function; + using binding_ctx_t = std::pair; + + using sync_binding_t = std::function; + using sync_binding_ctx_t = std::pair; + + void bind(const std::string &name, sync_binding_t fn) { + bind( + name, + [](const std::string &seq, const std::string &req, void *arg) { + auto pair = static_cast(arg); + pair->first->resolve(seq, 0, pair->second(req)); + }, + new sync_binding_ctx_t(this, fn)); + } + + void bind(const std::string &name, binding_t f, void *arg) { + auto js = "(function() { var name = '" + name + "';" + R"( + var RPC = window._rpc = (window._rpc || {nextSeq: 1}); + window[name] = function() { + var seq = RPC.nextSeq++; + var promise = new Promise(function(resolve, reject) { + RPC[seq] = { + resolve: resolve, + reject: reject, + }; + }); + window.external.invoke(JSON.stringify({ + id: seq, + method: name, + params: Array.prototype.slice.call(arguments), + })); + return promise; + } + })())"; + init(js); + eval(js); + bindings[name] = new binding_ctx_t(new binding_t(f), arg); + } + + void unbind(const std::string &name) { + if (bindings.find(name) != bindings.end()) { + auto js = "delete window['" + name + "'];"; + init(js); + eval(js); + delete bindings[name]->first; + delete static_cast(bindings[name]->second); + delete bindings[name]; + bindings.erase(name); + } + } + + void resolve(const std::string &seq, int status, const std::string &result) { + dispatch([seq, status, result, this]() { + if (status == 0) { + eval("window._rpc[" + seq + "].resolve(" + result + + "); delete window._rpc[" + seq + "]"); + } else { + eval("window._rpc[" + seq + "].reject(" + result + + "); delete window._rpc[" + seq + "]"); + } + }); + } + +private: + void on_message(const std::string &msg) { + auto seq = detail::json_parse(msg, "id", 0); + auto name = detail::json_parse(msg, "method", 0); + auto args = detail::json_parse(msg, "params", 0); + if (bindings.find(name) == bindings.end()) { + return; + } + auto fn = bindings[name]; + (*fn->first)(seq, args, fn->second); + } + std::map bindings; +}; +} // namespace webview + +WEBVIEW_API webview_t webview_create(int debug, void *wnd) { + auto w = new webview::webview(debug, wnd); + if (!w->window()) { + delete w; + return nullptr; + } + return w; +} + +WEBVIEW_API void webview_destroy(webview_t w) { + delete static_cast(w); +} + +WEBVIEW_API int webview_step(webview_t w, int blocking) { + return static_cast(w)->step(blocking); +} + +WEBVIEW_API void webview_run(webview_t w) { + static_cast(w)->run(); +} + +WEBVIEW_API void webview_terminate(webview_t w) { + static_cast(w)->terminate(); +} + +WEBVIEW_API void webview_dispatch(webview_t w, void (*fn)(webview_t, void *), + void *arg) { + static_cast(w)->dispatch([=]() { fn(w, arg); }); +} + +WEBVIEW_API void *webview_get_window(webview_t w) { + return static_cast(w)->window(); +} + +WEBVIEW_API void webview_set_title(webview_t w, const char *title) { + static_cast(w)->set_title(title); +} + +WEBVIEW_API void webview_set_size(webview_t w, int width, int height, + int hints) { + static_cast(w)->set_size(width, height, hints); +} + +WEBVIEW_API void webview_navigate(webview_t w, const char *url) { + static_cast(w)->navigate(url); +} + +WEBVIEW_API void webview_set_html(webview_t w, const char *html) { + static_cast(w)->set_html(html); +} + +WEBVIEW_API void webview_go_back(webview_t w) { + static_cast(w)->go_back(); +} + +WEBVIEW_API void webview_go_forward(webview_t w) { + static_cast(w)->go_forward(); +} + +WEBVIEW_API void webview_reload(webview_t w) { + static_cast(w)->reload(); +} + +WEBVIEW_API void webview_stop(webview_t w, const char *url) { + static_cast(w)->stop(); +} + +WEBVIEW_API char *webview_get_title(webview_t w) { + return static_cast(w)->get_title(); +} + +WEBVIEW_API char *webview_get_url(webview_t w) { + return static_cast(w)->get_url(); +} + +WEBVIEW_API void webview_init(webview_t w, const char *js) { + static_cast(w)->init(js); +} + +WEBVIEW_API void webview_eval(webview_t w, const char *js) { + static_cast(w)->eval(js); +} + +WEBVIEW_API void webview_bind(webview_t w, const char *name, + void (*fn)(const char *seq, const char *req, + void *arg), + void *arg) { + static_cast(w)->bind( + name, + [=](const std::string &seq, const std::string &req, void *arg) { + fn(seq.c_str(), req.c_str(), arg); + }, + arg); +} + +WEBVIEW_API void webview_unbind(webview_t w, const char *name) { + static_cast(w)->unbind(name); +} + +WEBVIEW_API void webview_return(webview_t w, const char *seq, int status, + const char *result) { + static_cast(w)->resolve(seq, status, result); +} + +#endif /* WEBVIEW_HEADER */ + +#endif /* WEBVIEW_H */ diff --git a/webview2.h b/webview2.h new file mode 100644 index 0000000..ef7f397 --- /dev/null +++ b/webview2.h @@ -0,0 +1,6708 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 8.xx.xxxx */ +/* at a redacted point in time + */ +/* Compiler settings for ../../edge_embedded_browser/client/win/current/webview2.idl: + Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.xx.xxxx + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 475 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif /* __RPCNDR_H_VERSION__ */ + + +#ifndef __webview2_h__ +#define __webview2_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +/* Forward Declarations */ + +#ifndef __ICoreWebView2AcceleratorKeyPressedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2AcceleratorKeyPressedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2AcceleratorKeyPressedEventArgs ICoreWebView2AcceleratorKeyPressedEventArgs; + +#endif /* __ICoreWebView2AcceleratorKeyPressedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2AcceleratorKeyPressedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2AcceleratorKeyPressedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2AcceleratorKeyPressedEventHandler ICoreWebView2AcceleratorKeyPressedEventHandler; + +#endif /* __ICoreWebView2AcceleratorKeyPressedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_FWD_DEFINED__ +#define __ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_FWD_DEFINED__ +typedef interface ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler; + +#endif /* __ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_FWD_DEFINED__ +#define __ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_FWD_DEFINED__ +typedef interface ICoreWebView2CallDevToolsProtocolMethodCompletedHandler ICoreWebView2CallDevToolsProtocolMethodCompletedHandler; + +#endif /* __ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2CapturePreviewCompletedHandler_FWD_DEFINED__ +#define __ICoreWebView2CapturePreviewCompletedHandler_FWD_DEFINED__ +typedef interface ICoreWebView2CapturePreviewCompletedHandler ICoreWebView2CapturePreviewCompletedHandler; + +#endif /* __ICoreWebView2CapturePreviewCompletedHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2_FWD_DEFINED__ +#define __ICoreWebView2_FWD_DEFINED__ +typedef interface ICoreWebView2 ICoreWebView2; + +#endif /* __ICoreWebView2_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2Controller_FWD_DEFINED__ +#define __ICoreWebView2Controller_FWD_DEFINED__ +typedef interface ICoreWebView2Controller ICoreWebView2Controller; + +#endif /* __ICoreWebView2Controller_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ContentLoadingEventArgs_FWD_DEFINED__ +#define __ICoreWebView2ContentLoadingEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2ContentLoadingEventArgs ICoreWebView2ContentLoadingEventArgs; + +#endif /* __ICoreWebView2ContentLoadingEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ContentLoadingEventHandler_FWD_DEFINED__ +#define __ICoreWebView2ContentLoadingEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2ContentLoadingEventHandler ICoreWebView2ContentLoadingEventHandler; + +#endif /* __ICoreWebView2ContentLoadingEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2DocumentTitleChangedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2DocumentTitleChangedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2DocumentTitleChangedEventHandler ICoreWebView2DocumentTitleChangedEventHandler; + +#endif /* __ICoreWebView2DocumentTitleChangedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ContainsFullScreenElementChangedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2ContainsFullScreenElementChangedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2ContainsFullScreenElementChangedEventHandler ICoreWebView2ContainsFullScreenElementChangedEventHandler; + +#endif /* __ICoreWebView2ContainsFullScreenElementChangedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_FWD_DEFINED__ +#define __ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_FWD_DEFINED__ +typedef interface ICoreWebView2CreateCoreWebView2ControllerCompletedHandler ICoreWebView2CreateCoreWebView2ControllerCompletedHandler; + +#endif /* __ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_FWD_DEFINED__ +#define __ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_FWD_DEFINED__ +typedef interface ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler; + +#endif /* __ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2Deferral_FWD_DEFINED__ +#define __ICoreWebView2Deferral_FWD_DEFINED__ +typedef interface ICoreWebView2Deferral ICoreWebView2Deferral; + +#endif /* __ICoreWebView2Deferral_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2DevToolsProtocolEventReceivedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2DevToolsProtocolEventReceivedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2DevToolsProtocolEventReceivedEventArgs ICoreWebView2DevToolsProtocolEventReceivedEventArgs; + +#endif /* __ICoreWebView2DevToolsProtocolEventReceivedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2DevToolsProtocolEventReceivedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2DevToolsProtocolEventReceivedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2DevToolsProtocolEventReceivedEventHandler ICoreWebView2DevToolsProtocolEventReceivedEventHandler; + +#endif /* __ICoreWebView2DevToolsProtocolEventReceivedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2DevToolsProtocolEventReceiver_FWD_DEFINED__ +#define __ICoreWebView2DevToolsProtocolEventReceiver_FWD_DEFINED__ +typedef interface ICoreWebView2DevToolsProtocolEventReceiver ICoreWebView2DevToolsProtocolEventReceiver; + +#endif /* __ICoreWebView2DevToolsProtocolEventReceiver_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2Environment_FWD_DEFINED__ +#define __ICoreWebView2Environment_FWD_DEFINED__ +typedef interface ICoreWebView2Environment ICoreWebView2Environment; + +#endif /* __ICoreWebView2Environment_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2EnvironmentOptions_FWD_DEFINED__ +#define __ICoreWebView2EnvironmentOptions_FWD_DEFINED__ +typedef interface ICoreWebView2EnvironmentOptions ICoreWebView2EnvironmentOptions; + +#endif /* __ICoreWebView2EnvironmentOptions_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ExecuteScriptCompletedHandler_FWD_DEFINED__ +#define __ICoreWebView2ExecuteScriptCompletedHandler_FWD_DEFINED__ +typedef interface ICoreWebView2ExecuteScriptCompletedHandler ICoreWebView2ExecuteScriptCompletedHandler; + +#endif /* __ICoreWebView2ExecuteScriptCompletedHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2FocusChangedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2FocusChangedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2FocusChangedEventHandler ICoreWebView2FocusChangedEventHandler; + +#endif /* __ICoreWebView2FocusChangedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2HistoryChangedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2HistoryChangedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2HistoryChangedEventHandler ICoreWebView2HistoryChangedEventHandler; + +#endif /* __ICoreWebView2HistoryChangedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2HttpHeadersCollectionIterator_FWD_DEFINED__ +#define __ICoreWebView2HttpHeadersCollectionIterator_FWD_DEFINED__ +typedef interface ICoreWebView2HttpHeadersCollectionIterator ICoreWebView2HttpHeadersCollectionIterator; + +#endif /* __ICoreWebView2HttpHeadersCollectionIterator_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2HttpRequestHeaders_FWD_DEFINED__ +#define __ICoreWebView2HttpRequestHeaders_FWD_DEFINED__ +typedef interface ICoreWebView2HttpRequestHeaders ICoreWebView2HttpRequestHeaders; + +#endif /* __ICoreWebView2HttpRequestHeaders_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2HttpResponseHeaders_FWD_DEFINED__ +#define __ICoreWebView2HttpResponseHeaders_FWD_DEFINED__ +typedef interface ICoreWebView2HttpResponseHeaders ICoreWebView2HttpResponseHeaders; + +#endif /* __ICoreWebView2HttpResponseHeaders_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2MoveFocusRequestedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2MoveFocusRequestedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2MoveFocusRequestedEventArgs ICoreWebView2MoveFocusRequestedEventArgs; + +#endif /* __ICoreWebView2MoveFocusRequestedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2MoveFocusRequestedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2MoveFocusRequestedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2MoveFocusRequestedEventHandler ICoreWebView2MoveFocusRequestedEventHandler; + +#endif /* __ICoreWebView2MoveFocusRequestedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationCompletedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2NavigationCompletedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2NavigationCompletedEventArgs ICoreWebView2NavigationCompletedEventArgs; + +#endif /* __ICoreWebView2NavigationCompletedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationCompletedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2NavigationCompletedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2NavigationCompletedEventHandler ICoreWebView2NavigationCompletedEventHandler; + +#endif /* __ICoreWebView2NavigationCompletedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationStartingEventArgs_FWD_DEFINED__ +#define __ICoreWebView2NavigationStartingEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2NavigationStartingEventArgs ICoreWebView2NavigationStartingEventArgs; + +#endif /* __ICoreWebView2NavigationStartingEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationStartingEventHandler_FWD_DEFINED__ +#define __ICoreWebView2NavigationStartingEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2NavigationStartingEventHandler ICoreWebView2NavigationStartingEventHandler; + +#endif /* __ICoreWebView2NavigationStartingEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2NewBrowserVersionAvailableEventHandler_FWD_DEFINED__ +#define __ICoreWebView2NewBrowserVersionAvailableEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2NewBrowserVersionAvailableEventHandler ICoreWebView2NewBrowserVersionAvailableEventHandler; + +#endif /* __ICoreWebView2NewBrowserVersionAvailableEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2NewWindowRequestedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2NewWindowRequestedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2NewWindowRequestedEventArgs ICoreWebView2NewWindowRequestedEventArgs; + +#endif /* __ICoreWebView2NewWindowRequestedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2NewWindowRequestedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2NewWindowRequestedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2NewWindowRequestedEventHandler ICoreWebView2NewWindowRequestedEventHandler; + +#endif /* __ICoreWebView2NewWindowRequestedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2PermissionRequestedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2PermissionRequestedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2PermissionRequestedEventArgs ICoreWebView2PermissionRequestedEventArgs; + +#endif /* __ICoreWebView2PermissionRequestedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2PermissionRequestedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2PermissionRequestedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2PermissionRequestedEventHandler ICoreWebView2PermissionRequestedEventHandler; + +#endif /* __ICoreWebView2PermissionRequestedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ProcessFailedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2ProcessFailedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2ProcessFailedEventArgs ICoreWebView2ProcessFailedEventArgs; + +#endif /* __ICoreWebView2ProcessFailedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ProcessFailedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2ProcessFailedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2ProcessFailedEventHandler ICoreWebView2ProcessFailedEventHandler; + +#endif /* __ICoreWebView2ProcessFailedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ScriptDialogOpeningEventArgs_FWD_DEFINED__ +#define __ICoreWebView2ScriptDialogOpeningEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2ScriptDialogOpeningEventArgs ICoreWebView2ScriptDialogOpeningEventArgs; + +#endif /* __ICoreWebView2ScriptDialogOpeningEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ScriptDialogOpeningEventHandler_FWD_DEFINED__ +#define __ICoreWebView2ScriptDialogOpeningEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2ScriptDialogOpeningEventHandler ICoreWebView2ScriptDialogOpeningEventHandler; + +#endif /* __ICoreWebView2ScriptDialogOpeningEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2Settings_FWD_DEFINED__ +#define __ICoreWebView2Settings_FWD_DEFINED__ +typedef interface ICoreWebView2Settings ICoreWebView2Settings; + +#endif /* __ICoreWebView2Settings_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2SourceChangedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2SourceChangedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2SourceChangedEventArgs ICoreWebView2SourceChangedEventArgs; + +#endif /* __ICoreWebView2SourceChangedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2SourceChangedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2SourceChangedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2SourceChangedEventHandler ICoreWebView2SourceChangedEventHandler; + +#endif /* __ICoreWebView2SourceChangedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WebMessageReceivedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2WebMessageReceivedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2WebMessageReceivedEventArgs ICoreWebView2WebMessageReceivedEventArgs; + +#endif /* __ICoreWebView2WebMessageReceivedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WebMessageReceivedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2WebMessageReceivedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2WebMessageReceivedEventHandler ICoreWebView2WebMessageReceivedEventHandler; + +#endif /* __ICoreWebView2WebMessageReceivedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceRequest_FWD_DEFINED__ +#define __ICoreWebView2WebResourceRequest_FWD_DEFINED__ +typedef interface ICoreWebView2WebResourceRequest ICoreWebView2WebResourceRequest; + +#endif /* __ICoreWebView2WebResourceRequest_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceRequestedEventArgs_FWD_DEFINED__ +#define __ICoreWebView2WebResourceRequestedEventArgs_FWD_DEFINED__ +typedef interface ICoreWebView2WebResourceRequestedEventArgs ICoreWebView2WebResourceRequestedEventArgs; + +#endif /* __ICoreWebView2WebResourceRequestedEventArgs_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceRequestedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2WebResourceRequestedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2WebResourceRequestedEventHandler ICoreWebView2WebResourceRequestedEventHandler; + +#endif /* __ICoreWebView2WebResourceRequestedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceResponse_FWD_DEFINED__ +#define __ICoreWebView2WebResourceResponse_FWD_DEFINED__ +typedef interface ICoreWebView2WebResourceResponse ICoreWebView2WebResourceResponse; + +#endif /* __ICoreWebView2WebResourceResponse_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WindowCloseRequestedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2WindowCloseRequestedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2WindowCloseRequestedEventHandler ICoreWebView2WindowCloseRequestedEventHandler; + +#endif /* __ICoreWebView2WindowCloseRequestedEventHandler_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2WindowFeatures_FWD_DEFINED__ +#define __ICoreWebView2WindowFeatures_FWD_DEFINED__ +typedef interface ICoreWebView2WindowFeatures ICoreWebView2WindowFeatures; + +#endif /* __ICoreWebView2WindowFeatures_FWD_DEFINED__ */ + + +#ifndef __ICoreWebView2ZoomFactorChangedEventHandler_FWD_DEFINED__ +#define __ICoreWebView2ZoomFactorChangedEventHandler_FWD_DEFINED__ +typedef interface ICoreWebView2ZoomFactorChangedEventHandler ICoreWebView2ZoomFactorChangedEventHandler; + +#endif /* __ICoreWebView2ZoomFactorChangedEventHandler_FWD_DEFINED__ */ + + +/* header files for imported files */ +#include "objidl.h" +#include "oaidl.h" +#include "EventToken.h" + +#ifdef __cplusplus +extern "C"{ +#endif + + + +#ifndef __WebView2_LIBRARY_DEFINED__ +#define __WebView2_LIBRARY_DEFINED__ + +/* library WebView2 */ +/* [version][uuid] */ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT + { + COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG = 0, + COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_JPEG = ( COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG + 1 ) + } COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_SCRIPT_DIALOG_KIND + { + COREWEBVIEW2_SCRIPT_DIALOG_KIND_ALERT = 0, + COREWEBVIEW2_SCRIPT_DIALOG_KIND_CONFIRM = ( COREWEBVIEW2_SCRIPT_DIALOG_KIND_ALERT + 1 ) , + COREWEBVIEW2_SCRIPT_DIALOG_KIND_PROMPT = ( COREWEBVIEW2_SCRIPT_DIALOG_KIND_CONFIRM + 1 ) , + COREWEBVIEW2_SCRIPT_DIALOG_KIND_BEFOREUNLOAD = ( COREWEBVIEW2_SCRIPT_DIALOG_KIND_PROMPT + 1 ) + } COREWEBVIEW2_SCRIPT_DIALOG_KIND; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_PROCESS_FAILED_KIND + { + COREWEBVIEW2_PROCESS_FAILED_KIND_BROWSER_PROCESS_EXITED = 0, + COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED = ( COREWEBVIEW2_PROCESS_FAILED_KIND_BROWSER_PROCESS_EXITED + 1 ) , + COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_UNRESPONSIVE = ( COREWEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED + 1 ) + } COREWEBVIEW2_PROCESS_FAILED_KIND; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_PERMISSION_KIND + { + COREWEBVIEW2_PERMISSION_KIND_UNKNOWN_PERMISSION = 0, + COREWEBVIEW2_PERMISSION_KIND_MICROPHONE = ( COREWEBVIEW2_PERMISSION_KIND_UNKNOWN_PERMISSION + 1 ) , + COREWEBVIEW2_PERMISSION_KIND_CAMERA = ( COREWEBVIEW2_PERMISSION_KIND_MICROPHONE + 1 ) , + COREWEBVIEW2_PERMISSION_KIND_GEOLOCATION = ( COREWEBVIEW2_PERMISSION_KIND_CAMERA + 1 ) , + COREWEBVIEW2_PERMISSION_KIND_NOTIFICATIONS = ( COREWEBVIEW2_PERMISSION_KIND_GEOLOCATION + 1 ) , + COREWEBVIEW2_PERMISSION_KIND_OTHER_SENSORS = ( COREWEBVIEW2_PERMISSION_KIND_NOTIFICATIONS + 1 ) , + COREWEBVIEW2_PERMISSION_KIND_CLIPBOARD_READ = ( COREWEBVIEW2_PERMISSION_KIND_OTHER_SENSORS + 1 ) + } COREWEBVIEW2_PERMISSION_KIND; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_PERMISSION_STATE + { + COREWEBVIEW2_PERMISSION_STATE_DEFAULT = 0, + COREWEBVIEW2_PERMISSION_STATE_ALLOW = ( COREWEBVIEW2_PERMISSION_STATE_DEFAULT + 1 ) , + COREWEBVIEW2_PERMISSION_STATE_DENY = ( COREWEBVIEW2_PERMISSION_STATE_ALLOW + 1 ) + } COREWEBVIEW2_PERMISSION_STATE; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_WEB_ERROR_STATUS + { + COREWEBVIEW2_WEB_ERROR_STATUS_UNKNOWN = 0, + COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_COMMON_NAME_IS_INCORRECT = ( COREWEBVIEW2_WEB_ERROR_STATUS_UNKNOWN + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_EXPIRED = ( COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_COMMON_NAME_IS_INCORRECT + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_CLIENT_CERTIFICATE_CONTAINS_ERRORS = ( COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_EXPIRED + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_REVOKED = ( COREWEBVIEW2_WEB_ERROR_STATUS_CLIENT_CERTIFICATE_CONTAINS_ERRORS + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_IS_INVALID = ( COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_REVOKED + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_SERVER_UNREACHABLE = ( COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_IS_INVALID + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_TIMEOUT = ( COREWEBVIEW2_WEB_ERROR_STATUS_SERVER_UNREACHABLE + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_ERROR_HTTP_INVALID_SERVER_RESPONSE = ( COREWEBVIEW2_WEB_ERROR_STATUS_TIMEOUT + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_CONNECTION_ABORTED = ( COREWEBVIEW2_WEB_ERROR_STATUS_ERROR_HTTP_INVALID_SERVER_RESPONSE + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_CONNECTION_RESET = ( COREWEBVIEW2_WEB_ERROR_STATUS_CONNECTION_ABORTED + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_DISCONNECTED = ( COREWEBVIEW2_WEB_ERROR_STATUS_CONNECTION_RESET + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_CANNOT_CONNECT = ( COREWEBVIEW2_WEB_ERROR_STATUS_DISCONNECTED + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_HOST_NAME_NOT_RESOLVED = ( COREWEBVIEW2_WEB_ERROR_STATUS_CANNOT_CONNECT + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_OPERATION_CANCELED = ( COREWEBVIEW2_WEB_ERROR_STATUS_HOST_NAME_NOT_RESOLVED + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_REDIRECT_FAILED = ( COREWEBVIEW2_WEB_ERROR_STATUS_OPERATION_CANCELED + 1 ) , + COREWEBVIEW2_WEB_ERROR_STATUS_UNEXPECTED_ERROR = ( COREWEBVIEW2_WEB_ERROR_STATUS_REDIRECT_FAILED + 1 ) + } COREWEBVIEW2_WEB_ERROR_STATUS; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_WEB_RESOURCE_CONTEXT + { + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL = 0, + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_DOCUMENT = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_STYLESHEET = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_DOCUMENT + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_IMAGE = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_STYLESHEET + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_MEDIA = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_IMAGE + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_FONT = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_MEDIA + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_SCRIPT = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_FONT + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_XML_HTTP_REQUEST = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_SCRIPT + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_FETCH = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_XML_HTTP_REQUEST + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_TEXT_TRACK = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_FETCH + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_EVENT_SOURCE = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_TEXT_TRACK + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_WEBSOCKET = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_EVENT_SOURCE + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_MANIFEST = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_WEBSOCKET + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_SIGNED_EXCHANGE = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_MANIFEST + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_PING = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_SIGNED_EXCHANGE + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_CSP_VIOLATION_REPORT = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_PING + 1 ) , + COREWEBVIEW2_WEB_RESOURCE_CONTEXT_OTHER = ( COREWEBVIEW2_WEB_RESOURCE_CONTEXT_CSP_VIOLATION_REPORT + 1 ) + } COREWEBVIEW2_WEB_RESOURCE_CONTEXT; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_MOVE_FOCUS_REASON + { + COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC = 0, + COREWEBVIEW2_MOVE_FOCUS_REASON_NEXT = ( COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC + 1 ) , + COREWEBVIEW2_MOVE_FOCUS_REASON_PREVIOUS = ( COREWEBVIEW2_MOVE_FOCUS_REASON_NEXT + 1 ) + } COREWEBVIEW2_MOVE_FOCUS_REASON; + +typedef /* [v1_enum] */ +enum COREWEBVIEW2_KEY_EVENT_KIND + { + COREWEBVIEW2_KEY_EVENT_KIND_KEY_DOWN = 0, + COREWEBVIEW2_KEY_EVENT_KIND_KEY_UP = ( COREWEBVIEW2_KEY_EVENT_KIND_KEY_DOWN + 1 ) , + COREWEBVIEW2_KEY_EVENT_KIND_SYSTEM_KEY_DOWN = ( COREWEBVIEW2_KEY_EVENT_KIND_KEY_UP + 1 ) , + COREWEBVIEW2_KEY_EVENT_KIND_SYSTEM_KEY_UP = ( COREWEBVIEW2_KEY_EVENT_KIND_SYSTEM_KEY_DOWN + 1 ) + } COREWEBVIEW2_KEY_EVENT_KIND; + +typedef struct COREWEBVIEW2_PHYSICAL_KEY_STATUS + { + UINT32 RepeatCount; + UINT32 ScanCode; + BOOL IsExtendedKey; + BOOL IsMenuKeyDown; + BOOL WasKeyDown; + BOOL IsKeyReleased; + } COREWEBVIEW2_PHYSICAL_KEY_STATUS; + +STDAPI CreateCoreWebView2EnvironmentWithOptions(PCWSTR browserExecutableFolder, PCWSTR userDataFolder, ICoreWebView2EnvironmentOptions* environmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler* environmentCreatedHandler); +STDAPI CreateCoreWebView2Environment(ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler* environmentCreatedHandler); +STDAPI GetAvailableCoreWebView2BrowserVersionString(PCWSTR browserExecutableFolder, LPWSTR* versionInfo); +STDAPI CompareBrowserVersions(PCWSTR version1, PCWSTR version2, int* result); + +EXTERN_C const IID LIBID_WebView2; + +#ifndef __ICoreWebView2AcceleratorKeyPressedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2AcceleratorKeyPressedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2AcceleratorKeyPressedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2AcceleratorKeyPressedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("9f760f8a-fb79-42be-9990-7b56900fa9c7") + ICoreWebView2AcceleratorKeyPressedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_KeyEventKind( + /* [retval][out] */ COREWEBVIEW2_KEY_EVENT_KIND *keyEventKind) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_VirtualKey( + /* [retval][out] */ UINT *virtualKey) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_KeyEventLParam( + /* [retval][out] */ INT *lParam) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_PhysicalKeyStatus( + /* [retval][out] */ COREWEBVIEW2_PHYSICAL_KEY_STATUS *physicalKeyStatus) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Handled( + /* [retval][out] */ BOOL *handled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Handled( + /* [in] */ BOOL handled) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2AcceleratorKeyPressedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_KeyEventKind )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_KEY_EVENT_KIND *keyEventKind); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_VirtualKey )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This, + /* [retval][out] */ UINT *virtualKey); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_KeyEventLParam )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This, + /* [retval][out] */ INT *lParam); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_PhysicalKeyStatus )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_PHYSICAL_KEY_STATUS *physicalKeyStatus); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Handled )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This, + /* [retval][out] */ BOOL *handled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Handled )( + ICoreWebView2AcceleratorKeyPressedEventArgs * This, + /* [in] */ BOOL handled); + + END_INTERFACE + } ICoreWebView2AcceleratorKeyPressedEventArgsVtbl; + + interface ICoreWebView2AcceleratorKeyPressedEventArgs + { + CONST_VTBL struct ICoreWebView2AcceleratorKeyPressedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_get_KeyEventKind(This,keyEventKind) \ + ( (This)->lpVtbl -> get_KeyEventKind(This,keyEventKind) ) + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_get_VirtualKey(This,virtualKey) \ + ( (This)->lpVtbl -> get_VirtualKey(This,virtualKey) ) + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_get_KeyEventLParam(This,lParam) \ + ( (This)->lpVtbl -> get_KeyEventLParam(This,lParam) ) + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_get_PhysicalKeyStatus(This,physicalKeyStatus) \ + ( (This)->lpVtbl -> get_PhysicalKeyStatus(This,physicalKeyStatus) ) + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_get_Handled(This,handled) \ + ( (This)->lpVtbl -> get_Handled(This,handled) ) + +#define ICoreWebView2AcceleratorKeyPressedEventArgs_put_Handled(This,handled) \ + ( (This)->lpVtbl -> put_Handled(This,handled) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2AcceleratorKeyPressedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2AcceleratorKeyPressedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2AcceleratorKeyPressedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2AcceleratorKeyPressedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2AcceleratorKeyPressedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("b29c7e28-fa79-41a8-8e44-65811c76dcb2") + ICoreWebView2AcceleratorKeyPressedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ ICoreWebView2AcceleratorKeyPressedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2AcceleratorKeyPressedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2AcceleratorKeyPressedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2AcceleratorKeyPressedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2AcceleratorKeyPressedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2AcceleratorKeyPressedEventHandler * This, + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ ICoreWebView2AcceleratorKeyPressedEventArgs *args); + + END_INTERFACE + } ICoreWebView2AcceleratorKeyPressedEventHandlerVtbl; + + interface ICoreWebView2AcceleratorKeyPressedEventHandler + { + CONST_VTBL struct ICoreWebView2AcceleratorKeyPressedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2AcceleratorKeyPressedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2AcceleratorKeyPressedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2AcceleratorKeyPressedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2AcceleratorKeyPressedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2AcceleratorKeyPressedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("b99369f3-9b11-47b5-bc6f-8e7895fcea17") + ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ HRESULT errorCode, + /* [in] */ LPCWSTR id) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler * This, + /* [in] */ HRESULT errorCode, + /* [in] */ LPCWSTR id); + + END_INTERFACE + } ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandlerVtbl; + + interface ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler + { + CONST_VTBL struct ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_Invoke(This,errorCode,id) \ + ( (This)->lpVtbl -> Invoke(This,errorCode,id) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2CallDevToolsProtocolMethodCompletedHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2CallDevToolsProtocolMethodCompletedHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("5c4889f0-5ef6-4c5a-952c-d8f1b92d0574") + ICoreWebView2CallDevToolsProtocolMethodCompletedHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ HRESULT errorCode, + /* [in] */ LPCWSTR returnObjectAsJson) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2CallDevToolsProtocolMethodCompletedHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2CallDevToolsProtocolMethodCompletedHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2CallDevToolsProtocolMethodCompletedHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2CallDevToolsProtocolMethodCompletedHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2CallDevToolsProtocolMethodCompletedHandler * This, + /* [in] */ HRESULT errorCode, + /* [in] */ LPCWSTR returnObjectAsJson); + + END_INTERFACE + } ICoreWebView2CallDevToolsProtocolMethodCompletedHandlerVtbl; + + interface ICoreWebView2CallDevToolsProtocolMethodCompletedHandler + { + CONST_VTBL struct ICoreWebView2CallDevToolsProtocolMethodCompletedHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_Invoke(This,errorCode,returnObjectAsJson) \ + ( (This)->lpVtbl -> Invoke(This,errorCode,returnObjectAsJson) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2CallDevToolsProtocolMethodCompletedHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2CapturePreviewCompletedHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2CapturePreviewCompletedHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2CapturePreviewCompletedHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2CapturePreviewCompletedHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("697e05e9-3d8f-45fa-96f4-8ffe1ededaf5") + ICoreWebView2CapturePreviewCompletedHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ HRESULT errorCode) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2CapturePreviewCompletedHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2CapturePreviewCompletedHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2CapturePreviewCompletedHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2CapturePreviewCompletedHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2CapturePreviewCompletedHandler * This, + /* [in] */ HRESULT errorCode); + + END_INTERFACE + } ICoreWebView2CapturePreviewCompletedHandlerVtbl; + + interface ICoreWebView2CapturePreviewCompletedHandler + { + CONST_VTBL struct ICoreWebView2CapturePreviewCompletedHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2CapturePreviewCompletedHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2CapturePreviewCompletedHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2CapturePreviewCompletedHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2CapturePreviewCompletedHandler_Invoke(This,errorCode) \ + ( (This)->lpVtbl -> Invoke(This,errorCode) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2CapturePreviewCompletedHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2_INTERFACE_DEFINED__ +#define __ICoreWebView2_INTERFACE_DEFINED__ + +/* interface ICoreWebView2 */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("76eceacb-0462-4d94-ac83-423a6793775e") + ICoreWebView2 : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Settings( + /* [retval][out] */ ICoreWebView2Settings **settings) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Source( + /* [retval][out] */ LPWSTR *uri) = 0; + + virtual HRESULT STDMETHODCALLTYPE Navigate( + /* [in] */ LPCWSTR uri) = 0; + + virtual HRESULT STDMETHODCALLTYPE NavigateToString( + /* [in] */ LPCWSTR htmlContent) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_NavigationStarting( + /* [in] */ ICoreWebView2NavigationStartingEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_NavigationStarting( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_ContentLoading( + /* [in] */ ICoreWebView2ContentLoadingEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_ContentLoading( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_SourceChanged( + /* [in] */ ICoreWebView2SourceChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_SourceChanged( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_HistoryChanged( + /* [in] */ ICoreWebView2HistoryChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_HistoryChanged( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_NavigationCompleted( + /* [in] */ ICoreWebView2NavigationCompletedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_NavigationCompleted( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_FrameNavigationStarting( + /* [in] */ ICoreWebView2NavigationStartingEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_FrameNavigationStarting( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_FrameNavigationCompleted( + /* [in] */ ICoreWebView2NavigationCompletedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_FrameNavigationCompleted( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_ScriptDialogOpening( + /* [in] */ ICoreWebView2ScriptDialogOpeningEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_ScriptDialogOpening( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_PermissionRequested( + /* [in] */ ICoreWebView2PermissionRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_PermissionRequested( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_ProcessFailed( + /* [in] */ ICoreWebView2ProcessFailedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_ProcessFailed( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE AddScriptToExecuteOnDocumentCreated( + /* [in] */ LPCWSTR javaScript, + /* [in] */ ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler *handler) = 0; + + virtual HRESULT STDMETHODCALLTYPE RemoveScriptToExecuteOnDocumentCreated( + /* [in] */ LPCWSTR id) = 0; + + virtual HRESULT STDMETHODCALLTYPE ExecuteScript( + /* [in] */ LPCWSTR javaScript, + /* [in] */ ICoreWebView2ExecuteScriptCompletedHandler *handler) = 0; + + virtual HRESULT STDMETHODCALLTYPE CapturePreview( + /* [in] */ COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT imageFormat, + /* [in] */ IStream *imageStream, + /* [in] */ ICoreWebView2CapturePreviewCompletedHandler *handler) = 0; + + virtual HRESULT STDMETHODCALLTYPE Reload( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE PostWebMessageAsJson( + /* [in] */ LPCWSTR webMessageAsJson) = 0; + + virtual HRESULT STDMETHODCALLTYPE PostWebMessageAsString( + /* [in] */ LPCWSTR webMessageAsString) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_WebMessageReceived( + /* [in] */ ICoreWebView2WebMessageReceivedEventHandler *handler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_WebMessageReceived( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE CallDevToolsProtocolMethod( + /* [in] */ LPCWSTR methodName, + /* [in] */ LPCWSTR parametersAsJson, + /* [in] */ ICoreWebView2CallDevToolsProtocolMethodCompletedHandler *handler) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_BrowserProcessId( + /* [retval][out] */ UINT32 *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_CanGoBack( + /* [retval][out] */ BOOL *canGoBack) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_CanGoForward( + /* [retval][out] */ BOOL *canGoForward) = 0; + + virtual HRESULT STDMETHODCALLTYPE GoBack( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE GoForward( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetDevToolsProtocolEventReceiver( + /* [in] */ LPCWSTR eventName, + /* [retval][out] */ ICoreWebView2DevToolsProtocolEventReceiver **receiver) = 0; + + virtual HRESULT STDMETHODCALLTYPE Stop( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_NewWindowRequested( + /* [in] */ ICoreWebView2NewWindowRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_NewWindowRequested( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_DocumentTitleChanged( + /* [in] */ ICoreWebView2DocumentTitleChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_DocumentTitleChanged( + /* [in] */ EventRegistrationToken token) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_DocumentTitle( + /* [retval][out] */ LPWSTR *title) = 0; + + virtual HRESULT STDMETHODCALLTYPE AddHostObjectToScript( + /* [in] */ LPCWSTR name, + /* [in] */ VARIANT *object) = 0; + + virtual HRESULT STDMETHODCALLTYPE RemoveHostObjectFromScript( + /* [in] */ LPCWSTR name) = 0; + + virtual HRESULT STDMETHODCALLTYPE OpenDevToolsWindow( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_ContainsFullScreenElementChanged( + /* [in] */ ICoreWebView2ContainsFullScreenElementChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_ContainsFullScreenElementChanged( + /* [in] */ EventRegistrationToken token) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ContainsFullScreenElement( + /* [retval][out] */ BOOL *containsFullScreenElement) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_WebResourceRequested( + /* [in] */ ICoreWebView2WebResourceRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_WebResourceRequested( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE AddWebResourceRequestedFilter( + /* [in] */ const LPCWSTR uri, + /* [in] */ const COREWEBVIEW2_WEB_RESOURCE_CONTEXT resourceContext) = 0; + + virtual HRESULT STDMETHODCALLTYPE RemoveWebResourceRequestedFilter( + /* [in] */ const LPCWSTR uri, + /* [in] */ const COREWEBVIEW2_WEB_RESOURCE_CONTEXT resourceContext) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_WindowCloseRequested( + /* [in] */ ICoreWebView2WindowCloseRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_WindowCloseRequested( + /* [in] */ EventRegistrationToken token) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2Vtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2 * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2 * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2 * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Settings )( + ICoreWebView2 * This, + /* [retval][out] */ ICoreWebView2Settings **settings); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Source )( + ICoreWebView2 * This, + /* [retval][out] */ LPWSTR *uri); + + HRESULT ( STDMETHODCALLTYPE *Navigate )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR uri); + + HRESULT ( STDMETHODCALLTYPE *NavigateToString )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR htmlContent); + + HRESULT ( STDMETHODCALLTYPE *add_NavigationStarting )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2NavigationStartingEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_NavigationStarting )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_ContentLoading )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2ContentLoadingEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_ContentLoading )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_SourceChanged )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2SourceChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_SourceChanged )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_HistoryChanged )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2HistoryChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_HistoryChanged )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_NavigationCompleted )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2NavigationCompletedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_NavigationCompleted )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_FrameNavigationStarting )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2NavigationStartingEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_FrameNavigationStarting )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_FrameNavigationCompleted )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2NavigationCompletedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_FrameNavigationCompleted )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_ScriptDialogOpening )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2ScriptDialogOpeningEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_ScriptDialogOpening )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_PermissionRequested )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2PermissionRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_PermissionRequested )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_ProcessFailed )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2ProcessFailedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_ProcessFailed )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *AddScriptToExecuteOnDocumentCreated )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR javaScript, + /* [in] */ ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler *handler); + + HRESULT ( STDMETHODCALLTYPE *RemoveScriptToExecuteOnDocumentCreated )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR id); + + HRESULT ( STDMETHODCALLTYPE *ExecuteScript )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR javaScript, + /* [in] */ ICoreWebView2ExecuteScriptCompletedHandler *handler); + + HRESULT ( STDMETHODCALLTYPE *CapturePreview )( + ICoreWebView2 * This, + /* [in] */ COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT imageFormat, + /* [in] */ IStream *imageStream, + /* [in] */ ICoreWebView2CapturePreviewCompletedHandler *handler); + + HRESULT ( STDMETHODCALLTYPE *Reload )( + ICoreWebView2 * This); + + HRESULT ( STDMETHODCALLTYPE *PostWebMessageAsJson )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR webMessageAsJson); + + HRESULT ( STDMETHODCALLTYPE *PostWebMessageAsString )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR webMessageAsString); + + HRESULT ( STDMETHODCALLTYPE *add_WebMessageReceived )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2WebMessageReceivedEventHandler *handler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_WebMessageReceived )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *CallDevToolsProtocolMethod )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR methodName, + /* [in] */ LPCWSTR parametersAsJson, + /* [in] */ ICoreWebView2CallDevToolsProtocolMethodCompletedHandler *handler); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_BrowserProcessId )( + ICoreWebView2 * This, + /* [retval][out] */ UINT32 *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_CanGoBack )( + ICoreWebView2 * This, + /* [retval][out] */ BOOL *canGoBack); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_CanGoForward )( + ICoreWebView2 * This, + /* [retval][out] */ BOOL *canGoForward); + + HRESULT ( STDMETHODCALLTYPE *GoBack )( + ICoreWebView2 * This); + + HRESULT ( STDMETHODCALLTYPE *GoForward )( + ICoreWebView2 * This); + + HRESULT ( STDMETHODCALLTYPE *GetDevToolsProtocolEventReceiver )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR eventName, + /* [retval][out] */ ICoreWebView2DevToolsProtocolEventReceiver **receiver); + + HRESULT ( STDMETHODCALLTYPE *Stop )( + ICoreWebView2 * This); + + HRESULT ( STDMETHODCALLTYPE *add_NewWindowRequested )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2NewWindowRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_NewWindowRequested )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_DocumentTitleChanged )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2DocumentTitleChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_DocumentTitleChanged )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_DocumentTitle )( + ICoreWebView2 * This, + /* [retval][out] */ LPWSTR *title); + + HRESULT ( STDMETHODCALLTYPE *AddHostObjectToScript )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR name, + /* [in] */ VARIANT *object); + + HRESULT ( STDMETHODCALLTYPE *RemoveHostObjectFromScript )( + ICoreWebView2 * This, + /* [in] */ LPCWSTR name); + + HRESULT ( STDMETHODCALLTYPE *OpenDevToolsWindow )( + ICoreWebView2 * This); + + HRESULT ( STDMETHODCALLTYPE *add_ContainsFullScreenElementChanged )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2ContainsFullScreenElementChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_ContainsFullScreenElementChanged )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ContainsFullScreenElement )( + ICoreWebView2 * This, + /* [retval][out] */ BOOL *containsFullScreenElement); + + HRESULT ( STDMETHODCALLTYPE *add_WebResourceRequested )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2WebResourceRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_WebResourceRequested )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *AddWebResourceRequestedFilter )( + ICoreWebView2 * This, + /* [in] */ const LPCWSTR uri, + /* [in] */ const COREWEBVIEW2_WEB_RESOURCE_CONTEXT resourceContext); + + HRESULT ( STDMETHODCALLTYPE *RemoveWebResourceRequestedFilter )( + ICoreWebView2 * This, + /* [in] */ const LPCWSTR uri, + /* [in] */ const COREWEBVIEW2_WEB_RESOURCE_CONTEXT resourceContext); + + HRESULT ( STDMETHODCALLTYPE *add_WindowCloseRequested )( + ICoreWebView2 * This, + /* [in] */ ICoreWebView2WindowCloseRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_WindowCloseRequested )( + ICoreWebView2 * This, + /* [in] */ EventRegistrationToken token); + + END_INTERFACE + } ICoreWebView2Vtbl; + + interface ICoreWebView2 + { + CONST_VTBL struct ICoreWebView2Vtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2_get_Settings(This,settings) \ + ( (This)->lpVtbl -> get_Settings(This,settings) ) + +#define ICoreWebView2_get_Source(This,uri) \ + ( (This)->lpVtbl -> get_Source(This,uri) ) + +#define ICoreWebView2_Navigate(This,uri) \ + ( (This)->lpVtbl -> Navigate(This,uri) ) + +#define ICoreWebView2_NavigateToString(This,htmlContent) \ + ( (This)->lpVtbl -> NavigateToString(This,htmlContent) ) + +#define ICoreWebView2_add_NavigationStarting(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_NavigationStarting(This,eventHandler,token) ) + +#define ICoreWebView2_remove_NavigationStarting(This,token) \ + ( (This)->lpVtbl -> remove_NavigationStarting(This,token) ) + +#define ICoreWebView2_add_ContentLoading(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_ContentLoading(This,eventHandler,token) ) + +#define ICoreWebView2_remove_ContentLoading(This,token) \ + ( (This)->lpVtbl -> remove_ContentLoading(This,token) ) + +#define ICoreWebView2_add_SourceChanged(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_SourceChanged(This,eventHandler,token) ) + +#define ICoreWebView2_remove_SourceChanged(This,token) \ + ( (This)->lpVtbl -> remove_SourceChanged(This,token) ) + +#define ICoreWebView2_add_HistoryChanged(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_HistoryChanged(This,eventHandler,token) ) + +#define ICoreWebView2_remove_HistoryChanged(This,token) \ + ( (This)->lpVtbl -> remove_HistoryChanged(This,token) ) + +#define ICoreWebView2_add_NavigationCompleted(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_NavigationCompleted(This,eventHandler,token) ) + +#define ICoreWebView2_remove_NavigationCompleted(This,token) \ + ( (This)->lpVtbl -> remove_NavigationCompleted(This,token) ) + +#define ICoreWebView2_add_FrameNavigationStarting(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_FrameNavigationStarting(This,eventHandler,token) ) + +#define ICoreWebView2_remove_FrameNavigationStarting(This,token) \ + ( (This)->lpVtbl -> remove_FrameNavigationStarting(This,token) ) + +#define ICoreWebView2_add_FrameNavigationCompleted(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_FrameNavigationCompleted(This,eventHandler,token) ) + +#define ICoreWebView2_remove_FrameNavigationCompleted(This,token) \ + ( (This)->lpVtbl -> remove_FrameNavigationCompleted(This,token) ) + +#define ICoreWebView2_add_ScriptDialogOpening(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_ScriptDialogOpening(This,eventHandler,token) ) + +#define ICoreWebView2_remove_ScriptDialogOpening(This,token) \ + ( (This)->lpVtbl -> remove_ScriptDialogOpening(This,token) ) + +#define ICoreWebView2_add_PermissionRequested(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_PermissionRequested(This,eventHandler,token) ) + +#define ICoreWebView2_remove_PermissionRequested(This,token) \ + ( (This)->lpVtbl -> remove_PermissionRequested(This,token) ) + +#define ICoreWebView2_add_ProcessFailed(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_ProcessFailed(This,eventHandler,token) ) + +#define ICoreWebView2_remove_ProcessFailed(This,token) \ + ( (This)->lpVtbl -> remove_ProcessFailed(This,token) ) + +#define ICoreWebView2_AddScriptToExecuteOnDocumentCreated(This,javaScript,handler) \ + ( (This)->lpVtbl -> AddScriptToExecuteOnDocumentCreated(This,javaScript,handler) ) + +#define ICoreWebView2_RemoveScriptToExecuteOnDocumentCreated(This,id) \ + ( (This)->lpVtbl -> RemoveScriptToExecuteOnDocumentCreated(This,id) ) + +#define ICoreWebView2_ExecuteScript(This,javaScript,handler) \ + ( (This)->lpVtbl -> ExecuteScript(This,javaScript,handler) ) + +#define ICoreWebView2_CapturePreview(This,imageFormat,imageStream,handler) \ + ( (This)->lpVtbl -> CapturePreview(This,imageFormat,imageStream,handler) ) + +#define ICoreWebView2_Reload(This) \ + ( (This)->lpVtbl -> Reload(This) ) + +#define ICoreWebView2_PostWebMessageAsJson(This,webMessageAsJson) \ + ( (This)->lpVtbl -> PostWebMessageAsJson(This,webMessageAsJson) ) + +#define ICoreWebView2_PostWebMessageAsString(This,webMessageAsString) \ + ( (This)->lpVtbl -> PostWebMessageAsString(This,webMessageAsString) ) + +#define ICoreWebView2_add_WebMessageReceived(This,handler,token) \ + ( (This)->lpVtbl -> add_WebMessageReceived(This,handler,token) ) + +#define ICoreWebView2_remove_WebMessageReceived(This,token) \ + ( (This)->lpVtbl -> remove_WebMessageReceived(This,token) ) + +#define ICoreWebView2_CallDevToolsProtocolMethod(This,methodName,parametersAsJson,handler) \ + ( (This)->lpVtbl -> CallDevToolsProtocolMethod(This,methodName,parametersAsJson,handler) ) + +#define ICoreWebView2_get_BrowserProcessId(This,value) \ + ( (This)->lpVtbl -> get_BrowserProcessId(This,value) ) + +#define ICoreWebView2_get_CanGoBack(This,canGoBack) \ + ( (This)->lpVtbl -> get_CanGoBack(This,canGoBack) ) + +#define ICoreWebView2_get_CanGoForward(This,canGoForward) \ + ( (This)->lpVtbl -> get_CanGoForward(This,canGoForward) ) + +#define ICoreWebView2_GoBack(This) \ + ( (This)->lpVtbl -> GoBack(This) ) + +#define ICoreWebView2_GoForward(This) \ + ( (This)->lpVtbl -> GoForward(This) ) + +#define ICoreWebView2_GetDevToolsProtocolEventReceiver(This,eventName,receiver) \ + ( (This)->lpVtbl -> GetDevToolsProtocolEventReceiver(This,eventName,receiver) ) + +#define ICoreWebView2_Stop(This) \ + ( (This)->lpVtbl -> Stop(This) ) + +#define ICoreWebView2_add_NewWindowRequested(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_NewWindowRequested(This,eventHandler,token) ) + +#define ICoreWebView2_remove_NewWindowRequested(This,token) \ + ( (This)->lpVtbl -> remove_NewWindowRequested(This,token) ) + +#define ICoreWebView2_add_DocumentTitleChanged(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_DocumentTitleChanged(This,eventHandler,token) ) + +#define ICoreWebView2_remove_DocumentTitleChanged(This,token) \ + ( (This)->lpVtbl -> remove_DocumentTitleChanged(This,token) ) + +#define ICoreWebView2_get_DocumentTitle(This,title) \ + ( (This)->lpVtbl -> get_DocumentTitle(This,title) ) + +#define ICoreWebView2_AddHostObjectToScript(This,name,object) \ + ( (This)->lpVtbl -> AddHostObjectToScript(This,name,object) ) + +#define ICoreWebView2_RemoveHostObjectFromScript(This,name) \ + ( (This)->lpVtbl -> RemoveHostObjectFromScript(This,name) ) + +#define ICoreWebView2_OpenDevToolsWindow(This) \ + ( (This)->lpVtbl -> OpenDevToolsWindow(This) ) + +#define ICoreWebView2_add_ContainsFullScreenElementChanged(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_ContainsFullScreenElementChanged(This,eventHandler,token) ) + +#define ICoreWebView2_remove_ContainsFullScreenElementChanged(This,token) \ + ( (This)->lpVtbl -> remove_ContainsFullScreenElementChanged(This,token) ) + +#define ICoreWebView2_get_ContainsFullScreenElement(This,containsFullScreenElement) \ + ( (This)->lpVtbl -> get_ContainsFullScreenElement(This,containsFullScreenElement) ) + +#define ICoreWebView2_add_WebResourceRequested(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_WebResourceRequested(This,eventHandler,token) ) + +#define ICoreWebView2_remove_WebResourceRequested(This,token) \ + ( (This)->lpVtbl -> remove_WebResourceRequested(This,token) ) + +#define ICoreWebView2_AddWebResourceRequestedFilter(This,uri,resourceContext) \ + ( (This)->lpVtbl -> AddWebResourceRequestedFilter(This,uri,resourceContext) ) + +#define ICoreWebView2_RemoveWebResourceRequestedFilter(This,uri,resourceContext) \ + ( (This)->lpVtbl -> RemoveWebResourceRequestedFilter(This,uri,resourceContext) ) + +#define ICoreWebView2_add_WindowCloseRequested(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_WindowCloseRequested(This,eventHandler,token) ) + +#define ICoreWebView2_remove_WindowCloseRequested(This,token) \ + ( (This)->lpVtbl -> remove_WindowCloseRequested(This,token) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2Controller_INTERFACE_DEFINED__ +#define __ICoreWebView2Controller_INTERFACE_DEFINED__ + +/* interface ICoreWebView2Controller */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2Controller; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("4d00c0d1-9434-4eb6-8078-8697a560334f") + ICoreWebView2Controller : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsVisible( + /* [retval][out] */ BOOL *isVisible) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_IsVisible( + /* [in] */ BOOL isVisible) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Bounds( + /* [retval][out] */ RECT *bounds) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Bounds( + /* [in] */ RECT bounds) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ZoomFactor( + /* [retval][out] */ double *zoomFactor) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_ZoomFactor( + /* [in] */ double zoomFactor) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_ZoomFactorChanged( + /* [in] */ ICoreWebView2ZoomFactorChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_ZoomFactorChanged( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetBoundsAndZoomFactor( + /* [in] */ RECT bounds, + /* [in] */ double zoomFactor) = 0; + + virtual HRESULT STDMETHODCALLTYPE MoveFocus( + /* [in] */ COREWEBVIEW2_MOVE_FOCUS_REASON reason) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_MoveFocusRequested( + /* [in] */ ICoreWebView2MoveFocusRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_MoveFocusRequested( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_GotFocus( + /* [in] */ ICoreWebView2FocusChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_GotFocus( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_LostFocus( + /* [in] */ ICoreWebView2FocusChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_LostFocus( + /* [in] */ EventRegistrationToken token) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_AcceleratorKeyPressed( + /* [in] */ ICoreWebView2AcceleratorKeyPressedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_AcceleratorKeyPressed( + /* [in] */ EventRegistrationToken token) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ParentWindow( + /* [retval][out] */ HWND *parentWindow) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_ParentWindow( + /* [in] */ HWND parentWindow) = 0; + + virtual HRESULT STDMETHODCALLTYPE NotifyParentWindowPositionChanged( void) = 0; + + virtual HRESULT STDMETHODCALLTYPE Close( void) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_CoreWebView2( + /* [retval][out] */ ICoreWebView2 **coreWebView2) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ControllerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2Controller * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2Controller * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2Controller * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsVisible )( + ICoreWebView2Controller * This, + /* [retval][out] */ BOOL *isVisible); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_IsVisible )( + ICoreWebView2Controller * This, + /* [in] */ BOOL isVisible); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Bounds )( + ICoreWebView2Controller * This, + /* [retval][out] */ RECT *bounds); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Bounds )( + ICoreWebView2Controller * This, + /* [in] */ RECT bounds); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ZoomFactor )( + ICoreWebView2Controller * This, + /* [retval][out] */ double *zoomFactor); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_ZoomFactor )( + ICoreWebView2Controller * This, + /* [in] */ double zoomFactor); + + HRESULT ( STDMETHODCALLTYPE *add_ZoomFactorChanged )( + ICoreWebView2Controller * This, + /* [in] */ ICoreWebView2ZoomFactorChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_ZoomFactorChanged )( + ICoreWebView2Controller * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *SetBoundsAndZoomFactor )( + ICoreWebView2Controller * This, + /* [in] */ RECT bounds, + /* [in] */ double zoomFactor); + + HRESULT ( STDMETHODCALLTYPE *MoveFocus )( + ICoreWebView2Controller * This, + /* [in] */ COREWEBVIEW2_MOVE_FOCUS_REASON reason); + + HRESULT ( STDMETHODCALLTYPE *add_MoveFocusRequested )( + ICoreWebView2Controller * This, + /* [in] */ ICoreWebView2MoveFocusRequestedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_MoveFocusRequested )( + ICoreWebView2Controller * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_GotFocus )( + ICoreWebView2Controller * This, + /* [in] */ ICoreWebView2FocusChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_GotFocus )( + ICoreWebView2Controller * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_LostFocus )( + ICoreWebView2Controller * This, + /* [in] */ ICoreWebView2FocusChangedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_LostFocus )( + ICoreWebView2Controller * This, + /* [in] */ EventRegistrationToken token); + + HRESULT ( STDMETHODCALLTYPE *add_AcceleratorKeyPressed )( + ICoreWebView2Controller * This, + /* [in] */ ICoreWebView2AcceleratorKeyPressedEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_AcceleratorKeyPressed )( + ICoreWebView2Controller * This, + /* [in] */ EventRegistrationToken token); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ParentWindow )( + ICoreWebView2Controller * This, + /* [retval][out] */ HWND *parentWindow); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_ParentWindow )( + ICoreWebView2Controller * This, + /* [in] */ HWND parentWindow); + + HRESULT ( STDMETHODCALLTYPE *NotifyParentWindowPositionChanged )( + ICoreWebView2Controller * This); + + HRESULT ( STDMETHODCALLTYPE *Close )( + ICoreWebView2Controller * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_CoreWebView2 )( + ICoreWebView2Controller * This, + /* [retval][out] */ ICoreWebView2 **coreWebView2); + + END_INTERFACE + } ICoreWebView2ControllerVtbl; + + interface ICoreWebView2Controller + { + CONST_VTBL struct ICoreWebView2ControllerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2Controller_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2Controller_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2Controller_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2Controller_get_IsVisible(This,isVisible) \ + ( (This)->lpVtbl -> get_IsVisible(This,isVisible) ) + +#define ICoreWebView2Controller_put_IsVisible(This,isVisible) \ + ( (This)->lpVtbl -> put_IsVisible(This,isVisible) ) + +#define ICoreWebView2Controller_get_Bounds(This,bounds) \ + ( (This)->lpVtbl -> get_Bounds(This,bounds) ) + +#define ICoreWebView2Controller_put_Bounds(This,bounds) \ + ( (This)->lpVtbl -> put_Bounds(This,bounds) ) + +#define ICoreWebView2Controller_get_ZoomFactor(This,zoomFactor) \ + ( (This)->lpVtbl -> get_ZoomFactor(This,zoomFactor) ) + +#define ICoreWebView2Controller_put_ZoomFactor(This,zoomFactor) \ + ( (This)->lpVtbl -> put_ZoomFactor(This,zoomFactor) ) + +#define ICoreWebView2Controller_add_ZoomFactorChanged(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_ZoomFactorChanged(This,eventHandler,token) ) + +#define ICoreWebView2Controller_remove_ZoomFactorChanged(This,token) \ + ( (This)->lpVtbl -> remove_ZoomFactorChanged(This,token) ) + +#define ICoreWebView2Controller_SetBoundsAndZoomFactor(This,bounds,zoomFactor) \ + ( (This)->lpVtbl -> SetBoundsAndZoomFactor(This,bounds,zoomFactor) ) + +#define ICoreWebView2Controller_MoveFocus(This,reason) \ + ( (This)->lpVtbl -> MoveFocus(This,reason) ) + +#define ICoreWebView2Controller_add_MoveFocusRequested(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_MoveFocusRequested(This,eventHandler,token) ) + +#define ICoreWebView2Controller_remove_MoveFocusRequested(This,token) \ + ( (This)->lpVtbl -> remove_MoveFocusRequested(This,token) ) + +#define ICoreWebView2Controller_add_GotFocus(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_GotFocus(This,eventHandler,token) ) + +#define ICoreWebView2Controller_remove_GotFocus(This,token) \ + ( (This)->lpVtbl -> remove_GotFocus(This,token) ) + +#define ICoreWebView2Controller_add_LostFocus(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_LostFocus(This,eventHandler,token) ) + +#define ICoreWebView2Controller_remove_LostFocus(This,token) \ + ( (This)->lpVtbl -> remove_LostFocus(This,token) ) + +#define ICoreWebView2Controller_add_AcceleratorKeyPressed(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_AcceleratorKeyPressed(This,eventHandler,token) ) + +#define ICoreWebView2Controller_remove_AcceleratorKeyPressed(This,token) \ + ( (This)->lpVtbl -> remove_AcceleratorKeyPressed(This,token) ) + +#define ICoreWebView2Controller_get_ParentWindow(This,parentWindow) \ + ( (This)->lpVtbl -> get_ParentWindow(This,parentWindow) ) + +#define ICoreWebView2Controller_put_ParentWindow(This,parentWindow) \ + ( (This)->lpVtbl -> put_ParentWindow(This,parentWindow) ) + +#define ICoreWebView2Controller_NotifyParentWindowPositionChanged(This) \ + ( (This)->lpVtbl -> NotifyParentWindowPositionChanged(This) ) + +#define ICoreWebView2Controller_Close(This) \ + ( (This)->lpVtbl -> Close(This) ) + +#define ICoreWebView2Controller_get_CoreWebView2(This,coreWebView2) \ + ( (This)->lpVtbl -> get_CoreWebView2(This,coreWebView2) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2Controller_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ContentLoadingEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2ContentLoadingEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ContentLoadingEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ContentLoadingEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("0c8a1275-9b6b-4901-87ad-70df25bafa6e") + ICoreWebView2ContentLoadingEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsErrorPage( + /* [retval][out] */ BOOL *isErrorPage) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_NavigationId( + /* [retval][out] */ UINT64 *navigationId) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ContentLoadingEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ContentLoadingEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ContentLoadingEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ContentLoadingEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsErrorPage )( + ICoreWebView2ContentLoadingEventArgs * This, + /* [retval][out] */ BOOL *isErrorPage); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_NavigationId )( + ICoreWebView2ContentLoadingEventArgs * This, + /* [retval][out] */ UINT64 *navigationId); + + END_INTERFACE + } ICoreWebView2ContentLoadingEventArgsVtbl; + + interface ICoreWebView2ContentLoadingEventArgs + { + CONST_VTBL struct ICoreWebView2ContentLoadingEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ContentLoadingEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ContentLoadingEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ContentLoadingEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ContentLoadingEventArgs_get_IsErrorPage(This,isErrorPage) \ + ( (This)->lpVtbl -> get_IsErrorPage(This,isErrorPage) ) + +#define ICoreWebView2ContentLoadingEventArgs_get_NavigationId(This,navigationId) \ + ( (This)->lpVtbl -> get_NavigationId(This,navigationId) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ContentLoadingEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ContentLoadingEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2ContentLoadingEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ContentLoadingEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ContentLoadingEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("364471e7-f2be-4910-bdba-d72077d51c4b") + ICoreWebView2ContentLoadingEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2ContentLoadingEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ContentLoadingEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ContentLoadingEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ContentLoadingEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ContentLoadingEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2ContentLoadingEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2ContentLoadingEventArgs *args); + + END_INTERFACE + } ICoreWebView2ContentLoadingEventHandlerVtbl; + + interface ICoreWebView2ContentLoadingEventHandler + { + CONST_VTBL struct ICoreWebView2ContentLoadingEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ContentLoadingEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ContentLoadingEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ContentLoadingEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ContentLoadingEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ContentLoadingEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2DocumentTitleChangedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2DocumentTitleChangedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2DocumentTitleChangedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2DocumentTitleChangedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("f5f2b923-953e-4042-9f95-f3a118e1afd4") + ICoreWebView2DocumentTitleChangedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2DocumentTitleChangedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2DocumentTitleChangedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2DocumentTitleChangedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2DocumentTitleChangedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2DocumentTitleChangedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args); + + END_INTERFACE + } ICoreWebView2DocumentTitleChangedEventHandlerVtbl; + + interface ICoreWebView2DocumentTitleChangedEventHandler + { + CONST_VTBL struct ICoreWebView2DocumentTitleChangedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2DocumentTitleChangedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2DocumentTitleChangedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2DocumentTitleChangedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2DocumentTitleChangedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2DocumentTitleChangedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ContainsFullScreenElementChangedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2ContainsFullScreenElementChangedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ContainsFullScreenElementChangedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ContainsFullScreenElementChangedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("e45d98b1-afef-45be-8baf-6c7728867f73") + ICoreWebView2ContainsFullScreenElementChangedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ContainsFullScreenElementChangedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ContainsFullScreenElementChangedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ContainsFullScreenElementChangedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ContainsFullScreenElementChangedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2ContainsFullScreenElementChangedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args); + + END_INTERFACE + } ICoreWebView2ContainsFullScreenElementChangedEventHandlerVtbl; + + interface ICoreWebView2ContainsFullScreenElementChangedEventHandler + { + CONST_VTBL struct ICoreWebView2ContainsFullScreenElementChangedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ContainsFullScreenElementChangedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ContainsFullScreenElementChangedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ContainsFullScreenElementChangedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ContainsFullScreenElementChangedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ContainsFullScreenElementChangedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2CreateCoreWebView2ControllerCompletedHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("6c4819f3-c9b7-4260-8127-c9f5bde7f68c") + ICoreWebView2CreateCoreWebView2ControllerCompletedHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + HRESULT errorCode, + ICoreWebView2Controller *createdController) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2CreateCoreWebView2ControllerCompletedHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2CreateCoreWebView2ControllerCompletedHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2CreateCoreWebView2ControllerCompletedHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2CreateCoreWebView2ControllerCompletedHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2CreateCoreWebView2ControllerCompletedHandler * This, + HRESULT errorCode, + ICoreWebView2Controller *createdController); + + END_INTERFACE + } ICoreWebView2CreateCoreWebView2ControllerCompletedHandlerVtbl; + + interface ICoreWebView2CreateCoreWebView2ControllerCompletedHandler + { + CONST_VTBL struct ICoreWebView2CreateCoreWebView2ControllerCompletedHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_Invoke(This,errorCode,createdController) \ + ( (This)->lpVtbl -> Invoke(This,errorCode,createdController) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2CreateCoreWebView2ControllerCompletedHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("4e8a3389-c9d8-4bd2-b6b5-124fee6cc14d") + ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + HRESULT errorCode, + ICoreWebView2Environment *createdEnvironment) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * This, + HRESULT errorCode, + ICoreWebView2Environment *createdEnvironment); + + END_INTERFACE + } ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerVtbl; + + interface ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler + { + CONST_VTBL struct ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_Invoke(This,errorCode,createdEnvironment) \ + ( (This)->lpVtbl -> Invoke(This,errorCode,createdEnvironment) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2Deferral_INTERFACE_DEFINED__ +#define __ICoreWebView2Deferral_INTERFACE_DEFINED__ + +/* interface ICoreWebView2Deferral */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2Deferral; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("c10e7f7b-b585-46f0-a623-8befbf3e4ee0") + ICoreWebView2Deferral : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Complete( void) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2DeferralVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2Deferral * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2Deferral * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2Deferral * This); + + HRESULT ( STDMETHODCALLTYPE *Complete )( + ICoreWebView2Deferral * This); + + END_INTERFACE + } ICoreWebView2DeferralVtbl; + + interface ICoreWebView2Deferral + { + CONST_VTBL struct ICoreWebView2DeferralVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2Deferral_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2Deferral_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2Deferral_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2Deferral_Complete(This) \ + ( (This)->lpVtbl -> Complete(This) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2Deferral_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2DevToolsProtocolEventReceivedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2DevToolsProtocolEventReceivedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2DevToolsProtocolEventReceivedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2DevToolsProtocolEventReceivedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("653c2959-bb3a-4377-8632-b58ada4e66c4") + ICoreWebView2DevToolsProtocolEventReceivedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ParameterObjectAsJson( + /* [retval][out] */ LPWSTR *parameterObjectAsJson) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2DevToolsProtocolEventReceivedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2DevToolsProtocolEventReceivedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2DevToolsProtocolEventReceivedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2DevToolsProtocolEventReceivedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ParameterObjectAsJson )( + ICoreWebView2DevToolsProtocolEventReceivedEventArgs * This, + /* [retval][out] */ LPWSTR *parameterObjectAsJson); + + END_INTERFACE + } ICoreWebView2DevToolsProtocolEventReceivedEventArgsVtbl; + + interface ICoreWebView2DevToolsProtocolEventReceivedEventArgs + { + CONST_VTBL struct ICoreWebView2DevToolsProtocolEventReceivedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2DevToolsProtocolEventReceivedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2DevToolsProtocolEventReceivedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2DevToolsProtocolEventReceivedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2DevToolsProtocolEventReceivedEventArgs_get_ParameterObjectAsJson(This,parameterObjectAsJson) \ + ( (This)->lpVtbl -> get_ParameterObjectAsJson(This,parameterObjectAsJson) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2DevToolsProtocolEventReceivedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2DevToolsProtocolEventReceivedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2DevToolsProtocolEventReceivedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2DevToolsProtocolEventReceivedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2DevToolsProtocolEventReceivedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("e2fda4be-5456-406c-a261-3d452138362c") + ICoreWebView2DevToolsProtocolEventReceivedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2DevToolsProtocolEventReceivedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2DevToolsProtocolEventReceivedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2DevToolsProtocolEventReceivedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2DevToolsProtocolEventReceivedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2DevToolsProtocolEventReceivedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2DevToolsProtocolEventReceivedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2DevToolsProtocolEventReceivedEventArgs *args); + + END_INTERFACE + } ICoreWebView2DevToolsProtocolEventReceivedEventHandlerVtbl; + + interface ICoreWebView2DevToolsProtocolEventReceivedEventHandler + { + CONST_VTBL struct ICoreWebView2DevToolsProtocolEventReceivedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2DevToolsProtocolEventReceivedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2DevToolsProtocolEventReceivedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2DevToolsProtocolEventReceivedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2DevToolsProtocolEventReceivedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2DevToolsProtocolEventReceivedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2DevToolsProtocolEventReceiver_INTERFACE_DEFINED__ +#define __ICoreWebView2DevToolsProtocolEventReceiver_INTERFACE_DEFINED__ + +/* interface ICoreWebView2DevToolsProtocolEventReceiver */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2DevToolsProtocolEventReceiver; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("b32ca51a-8371-45e9-9317-af021d080367") + ICoreWebView2DevToolsProtocolEventReceiver : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE add_DevToolsProtocolEventReceived( + /* [in] */ ICoreWebView2DevToolsProtocolEventReceivedEventHandler *handler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_DevToolsProtocolEventReceived( + /* [in] */ EventRegistrationToken token) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2DevToolsProtocolEventReceiverVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2DevToolsProtocolEventReceiver * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2DevToolsProtocolEventReceiver * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2DevToolsProtocolEventReceiver * This); + + HRESULT ( STDMETHODCALLTYPE *add_DevToolsProtocolEventReceived )( + ICoreWebView2DevToolsProtocolEventReceiver * This, + /* [in] */ ICoreWebView2DevToolsProtocolEventReceivedEventHandler *handler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_DevToolsProtocolEventReceived )( + ICoreWebView2DevToolsProtocolEventReceiver * This, + /* [in] */ EventRegistrationToken token); + + END_INTERFACE + } ICoreWebView2DevToolsProtocolEventReceiverVtbl; + + interface ICoreWebView2DevToolsProtocolEventReceiver + { + CONST_VTBL struct ICoreWebView2DevToolsProtocolEventReceiverVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2DevToolsProtocolEventReceiver_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2DevToolsProtocolEventReceiver_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2DevToolsProtocolEventReceiver_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2DevToolsProtocolEventReceiver_add_DevToolsProtocolEventReceived(This,handler,token) \ + ( (This)->lpVtbl -> add_DevToolsProtocolEventReceived(This,handler,token) ) + +#define ICoreWebView2DevToolsProtocolEventReceiver_remove_DevToolsProtocolEventReceived(This,token) \ + ( (This)->lpVtbl -> remove_DevToolsProtocolEventReceived(This,token) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2DevToolsProtocolEventReceiver_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2Environment_INTERFACE_DEFINED__ +#define __ICoreWebView2Environment_INTERFACE_DEFINED__ + +/* interface ICoreWebView2Environment */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2Environment; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("b96d755e-0319-4e92-a296-23436f46a1fc") + ICoreWebView2Environment : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE CreateCoreWebView2Controller( + HWND parentWindow, + ICoreWebView2CreateCoreWebView2ControllerCompletedHandler *handler) = 0; + + virtual HRESULT STDMETHODCALLTYPE CreateWebResourceResponse( + /* [in] */ IStream *content, + /* [in] */ int statusCode, + /* [in] */ LPCWSTR reasonPhrase, + /* [in] */ LPCWSTR headers, + /* [retval][out] */ ICoreWebView2WebResourceResponse **response) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_BrowserVersionString( + /* [retval][out] */ LPWSTR *versionInfo) = 0; + + virtual HRESULT STDMETHODCALLTYPE add_NewBrowserVersionAvailable( + /* [in] */ ICoreWebView2NewBrowserVersionAvailableEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token) = 0; + + virtual HRESULT STDMETHODCALLTYPE remove_NewBrowserVersionAvailable( + /* [in] */ EventRegistrationToken token) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2EnvironmentVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2Environment * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2Environment * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2Environment * This); + + HRESULT ( STDMETHODCALLTYPE *CreateCoreWebView2Controller )( + ICoreWebView2Environment * This, + HWND parentWindow, + ICoreWebView2CreateCoreWebView2ControllerCompletedHandler *handler); + + HRESULT ( STDMETHODCALLTYPE *CreateWebResourceResponse )( + ICoreWebView2Environment * This, + /* [in] */ IStream *content, + /* [in] */ int statusCode, + /* [in] */ LPCWSTR reasonPhrase, + /* [in] */ LPCWSTR headers, + /* [retval][out] */ ICoreWebView2WebResourceResponse **response); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_BrowserVersionString )( + ICoreWebView2Environment * This, + /* [retval][out] */ LPWSTR *versionInfo); + + HRESULT ( STDMETHODCALLTYPE *add_NewBrowserVersionAvailable )( + ICoreWebView2Environment * This, + /* [in] */ ICoreWebView2NewBrowserVersionAvailableEventHandler *eventHandler, + /* [out] */ EventRegistrationToken *token); + + HRESULT ( STDMETHODCALLTYPE *remove_NewBrowserVersionAvailable )( + ICoreWebView2Environment * This, + /* [in] */ EventRegistrationToken token); + + END_INTERFACE + } ICoreWebView2EnvironmentVtbl; + + interface ICoreWebView2Environment + { + CONST_VTBL struct ICoreWebView2EnvironmentVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2Environment_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2Environment_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2Environment_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2Environment_CreateCoreWebView2Controller(This,parentWindow,handler) \ + ( (This)->lpVtbl -> CreateCoreWebView2Controller(This,parentWindow,handler) ) + +#define ICoreWebView2Environment_CreateWebResourceResponse(This,content,statusCode,reasonPhrase,headers,response) \ + ( (This)->lpVtbl -> CreateWebResourceResponse(This,content,statusCode,reasonPhrase,headers,response) ) + +#define ICoreWebView2Environment_get_BrowserVersionString(This,versionInfo) \ + ( (This)->lpVtbl -> get_BrowserVersionString(This,versionInfo) ) + +#define ICoreWebView2Environment_add_NewBrowserVersionAvailable(This,eventHandler,token) \ + ( (This)->lpVtbl -> add_NewBrowserVersionAvailable(This,eventHandler,token) ) + +#define ICoreWebView2Environment_remove_NewBrowserVersionAvailable(This,token) \ + ( (This)->lpVtbl -> remove_NewBrowserVersionAvailable(This,token) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2Environment_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2EnvironmentOptions_INTERFACE_DEFINED__ +#define __ICoreWebView2EnvironmentOptions_INTERFACE_DEFINED__ + +/* interface ICoreWebView2EnvironmentOptions */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2EnvironmentOptions; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("2fde08a8-1e9a-4766-8c05-95a9ceb9d1c5") + ICoreWebView2EnvironmentOptions : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AdditionalBrowserArguments( + /* [retval][out] */ LPWSTR *value) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_AdditionalBrowserArguments( + /* [in] */ LPCWSTR value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Language( + /* [retval][out] */ LPWSTR *value) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Language( + /* [in] */ LPCWSTR value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_TargetCompatibleBrowserVersion( + /* [retval][out] */ LPWSTR *value) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_TargetCompatibleBrowserVersion( + /* [in] */ LPCWSTR value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AllowSingleSignOnUsingOSPrimaryAccount( + /* [retval][out] */ BOOL *allow) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_AllowSingleSignOnUsingOSPrimaryAccount( + /* [in] */ BOOL allow) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2EnvironmentOptionsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2EnvironmentOptions * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2EnvironmentOptions * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2EnvironmentOptions * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_AdditionalBrowserArguments )( + ICoreWebView2EnvironmentOptions * This, + /* [retval][out] */ LPWSTR *value); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_AdditionalBrowserArguments )( + ICoreWebView2EnvironmentOptions * This, + /* [in] */ LPCWSTR value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Language )( + ICoreWebView2EnvironmentOptions * This, + /* [retval][out] */ LPWSTR *value); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Language )( + ICoreWebView2EnvironmentOptions * This, + /* [in] */ LPCWSTR value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_TargetCompatibleBrowserVersion )( + ICoreWebView2EnvironmentOptions * This, + /* [retval][out] */ LPWSTR *value); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_TargetCompatibleBrowserVersion )( + ICoreWebView2EnvironmentOptions * This, + /* [in] */ LPCWSTR value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_AllowSingleSignOnUsingOSPrimaryAccount )( + ICoreWebView2EnvironmentOptions * This, + /* [retval][out] */ BOOL *allow); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_AllowSingleSignOnUsingOSPrimaryAccount )( + ICoreWebView2EnvironmentOptions * This, + /* [in] */ BOOL allow); + + END_INTERFACE + } ICoreWebView2EnvironmentOptionsVtbl; + + interface ICoreWebView2EnvironmentOptions + { + CONST_VTBL struct ICoreWebView2EnvironmentOptionsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2EnvironmentOptions_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2EnvironmentOptions_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2EnvironmentOptions_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2EnvironmentOptions_get_AdditionalBrowserArguments(This,value) \ + ( (This)->lpVtbl -> get_AdditionalBrowserArguments(This,value) ) + +#define ICoreWebView2EnvironmentOptions_put_AdditionalBrowserArguments(This,value) \ + ( (This)->lpVtbl -> put_AdditionalBrowserArguments(This,value) ) + +#define ICoreWebView2EnvironmentOptions_get_Language(This,value) \ + ( (This)->lpVtbl -> get_Language(This,value) ) + +#define ICoreWebView2EnvironmentOptions_put_Language(This,value) \ + ( (This)->lpVtbl -> put_Language(This,value) ) + +#define ICoreWebView2EnvironmentOptions_get_TargetCompatibleBrowserVersion(This,value) \ + ( (This)->lpVtbl -> get_TargetCompatibleBrowserVersion(This,value) ) + +#define ICoreWebView2EnvironmentOptions_put_TargetCompatibleBrowserVersion(This,value) \ + ( (This)->lpVtbl -> put_TargetCompatibleBrowserVersion(This,value) ) + +#define ICoreWebView2EnvironmentOptions_get_AllowSingleSignOnUsingOSPrimaryAccount(This,allow) \ + ( (This)->lpVtbl -> get_AllowSingleSignOnUsingOSPrimaryAccount(This,allow) ) + +#define ICoreWebView2EnvironmentOptions_put_AllowSingleSignOnUsingOSPrimaryAccount(This,allow) \ + ( (This)->lpVtbl -> put_AllowSingleSignOnUsingOSPrimaryAccount(This,allow) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2EnvironmentOptions_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ExecuteScriptCompletedHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2ExecuteScriptCompletedHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ExecuteScriptCompletedHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ExecuteScriptCompletedHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("49511172-cc67-4bca-9923-137112f4c4cc") + ICoreWebView2ExecuteScriptCompletedHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ HRESULT errorCode, + /* [in] */ LPCWSTR resultObjectAsJson) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ExecuteScriptCompletedHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ExecuteScriptCompletedHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ExecuteScriptCompletedHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ExecuteScriptCompletedHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2ExecuteScriptCompletedHandler * This, + /* [in] */ HRESULT errorCode, + /* [in] */ LPCWSTR resultObjectAsJson); + + END_INTERFACE + } ICoreWebView2ExecuteScriptCompletedHandlerVtbl; + + interface ICoreWebView2ExecuteScriptCompletedHandler + { + CONST_VTBL struct ICoreWebView2ExecuteScriptCompletedHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ExecuteScriptCompletedHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ExecuteScriptCompletedHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ExecuteScriptCompletedHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ExecuteScriptCompletedHandler_Invoke(This,errorCode,resultObjectAsJson) \ + ( (This)->lpVtbl -> Invoke(This,errorCode,resultObjectAsJson) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ExecuteScriptCompletedHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2FocusChangedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2FocusChangedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2FocusChangedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2FocusChangedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("05ea24bd-6452-4926-9014-4b82b498135d") + ICoreWebView2FocusChangedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ IUnknown *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2FocusChangedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2FocusChangedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2FocusChangedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2FocusChangedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2FocusChangedEventHandler * This, + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ IUnknown *args); + + END_INTERFACE + } ICoreWebView2FocusChangedEventHandlerVtbl; + + interface ICoreWebView2FocusChangedEventHandler + { + CONST_VTBL struct ICoreWebView2FocusChangedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2FocusChangedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2FocusChangedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2FocusChangedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2FocusChangedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2FocusChangedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2HistoryChangedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2HistoryChangedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2HistoryChangedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2HistoryChangedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("c79a420c-efd9-4058-9295-3e8b4bcab645") + ICoreWebView2HistoryChangedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2HistoryChangedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2HistoryChangedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2HistoryChangedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2HistoryChangedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2HistoryChangedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args); + + END_INTERFACE + } ICoreWebView2HistoryChangedEventHandlerVtbl; + + interface ICoreWebView2HistoryChangedEventHandler + { + CONST_VTBL struct ICoreWebView2HistoryChangedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2HistoryChangedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2HistoryChangedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2HistoryChangedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2HistoryChangedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2HistoryChangedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2HttpHeadersCollectionIterator_INTERFACE_DEFINED__ +#define __ICoreWebView2HttpHeadersCollectionIterator_INTERFACE_DEFINED__ + +/* interface ICoreWebView2HttpHeadersCollectionIterator */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2HttpHeadersCollectionIterator; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("0702fc30-f43b-47bb-ab52-a42cb552ad9f") + ICoreWebView2HttpHeadersCollectionIterator : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE GetCurrentHeader( + /* [out] */ LPWSTR *name, + /* [out] */ LPWSTR *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_HasCurrentHeader( + /* [retval][out] */ BOOL *hasCurrent) = 0; + + virtual HRESULT STDMETHODCALLTYPE MoveNext( + /* [retval][out] */ BOOL *hasNext) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2HttpHeadersCollectionIteratorVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2HttpHeadersCollectionIterator * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2HttpHeadersCollectionIterator * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2HttpHeadersCollectionIterator * This); + + HRESULT ( STDMETHODCALLTYPE *GetCurrentHeader )( + ICoreWebView2HttpHeadersCollectionIterator * This, + /* [out] */ LPWSTR *name, + /* [out] */ LPWSTR *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasCurrentHeader )( + ICoreWebView2HttpHeadersCollectionIterator * This, + /* [retval][out] */ BOOL *hasCurrent); + + HRESULT ( STDMETHODCALLTYPE *MoveNext )( + ICoreWebView2HttpHeadersCollectionIterator * This, + /* [retval][out] */ BOOL *hasNext); + + END_INTERFACE + } ICoreWebView2HttpHeadersCollectionIteratorVtbl; + + interface ICoreWebView2HttpHeadersCollectionIterator + { + CONST_VTBL struct ICoreWebView2HttpHeadersCollectionIteratorVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2HttpHeadersCollectionIterator_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2HttpHeadersCollectionIterator_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2HttpHeadersCollectionIterator_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2HttpHeadersCollectionIterator_GetCurrentHeader(This,name,value) \ + ( (This)->lpVtbl -> GetCurrentHeader(This,name,value) ) + +#define ICoreWebView2HttpHeadersCollectionIterator_get_HasCurrentHeader(This,hasCurrent) \ + ( (This)->lpVtbl -> get_HasCurrentHeader(This,hasCurrent) ) + +#define ICoreWebView2HttpHeadersCollectionIterator_MoveNext(This,hasNext) \ + ( (This)->lpVtbl -> MoveNext(This,hasNext) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2HttpHeadersCollectionIterator_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2HttpRequestHeaders_INTERFACE_DEFINED__ +#define __ICoreWebView2HttpRequestHeaders_INTERFACE_DEFINED__ + +/* interface ICoreWebView2HttpRequestHeaders */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2HttpRequestHeaders; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("e86cac0e-5523-465c-b536-8fb9fc8c8c60") + ICoreWebView2HttpRequestHeaders : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE GetHeader( + /* [in] */ LPCWSTR name, + /* [retval][out] */ LPWSTR *value) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetHeaders( + /* [in] */ LPCWSTR name, + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator) = 0; + + virtual HRESULT STDMETHODCALLTYPE Contains( + /* [in] */ LPCWSTR name, + /* [retval][out] */ BOOL *contains) = 0; + + virtual HRESULT STDMETHODCALLTYPE SetHeader( + /* [in] */ LPCWSTR name, + /* [in] */ LPCWSTR value) = 0; + + virtual HRESULT STDMETHODCALLTYPE RemoveHeader( + /* [in] */ LPCWSTR name) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetIterator( + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2HttpRequestHeadersVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2HttpRequestHeaders * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2HttpRequestHeaders * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2HttpRequestHeaders * This); + + HRESULT ( STDMETHODCALLTYPE *GetHeader )( + ICoreWebView2HttpRequestHeaders * This, + /* [in] */ LPCWSTR name, + /* [retval][out] */ LPWSTR *value); + + HRESULT ( STDMETHODCALLTYPE *GetHeaders )( + ICoreWebView2HttpRequestHeaders * This, + /* [in] */ LPCWSTR name, + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator); + + HRESULT ( STDMETHODCALLTYPE *Contains )( + ICoreWebView2HttpRequestHeaders * This, + /* [in] */ LPCWSTR name, + /* [retval][out] */ BOOL *contains); + + HRESULT ( STDMETHODCALLTYPE *SetHeader )( + ICoreWebView2HttpRequestHeaders * This, + /* [in] */ LPCWSTR name, + /* [in] */ LPCWSTR value); + + HRESULT ( STDMETHODCALLTYPE *RemoveHeader )( + ICoreWebView2HttpRequestHeaders * This, + /* [in] */ LPCWSTR name); + + HRESULT ( STDMETHODCALLTYPE *GetIterator )( + ICoreWebView2HttpRequestHeaders * This, + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator); + + END_INTERFACE + } ICoreWebView2HttpRequestHeadersVtbl; + + interface ICoreWebView2HttpRequestHeaders + { + CONST_VTBL struct ICoreWebView2HttpRequestHeadersVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2HttpRequestHeaders_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2HttpRequestHeaders_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2HttpRequestHeaders_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2HttpRequestHeaders_GetHeader(This,name,value) \ + ( (This)->lpVtbl -> GetHeader(This,name,value) ) + +#define ICoreWebView2HttpRequestHeaders_GetHeaders(This,name,iterator) \ + ( (This)->lpVtbl -> GetHeaders(This,name,iterator) ) + +#define ICoreWebView2HttpRequestHeaders_Contains(This,name,contains) \ + ( (This)->lpVtbl -> Contains(This,name,contains) ) + +#define ICoreWebView2HttpRequestHeaders_SetHeader(This,name,value) \ + ( (This)->lpVtbl -> SetHeader(This,name,value) ) + +#define ICoreWebView2HttpRequestHeaders_RemoveHeader(This,name) \ + ( (This)->lpVtbl -> RemoveHeader(This,name) ) + +#define ICoreWebView2HttpRequestHeaders_GetIterator(This,iterator) \ + ( (This)->lpVtbl -> GetIterator(This,iterator) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2HttpRequestHeaders_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2HttpResponseHeaders_INTERFACE_DEFINED__ +#define __ICoreWebView2HttpResponseHeaders_INTERFACE_DEFINED__ + +/* interface ICoreWebView2HttpResponseHeaders */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2HttpResponseHeaders; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("03c5ff5a-9b45-4a88-881c-89a9f328619c") + ICoreWebView2HttpResponseHeaders : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE AppendHeader( + /* [in] */ LPCWSTR name, + /* [in] */ LPCWSTR value) = 0; + + virtual HRESULT STDMETHODCALLTYPE Contains( + /* [in] */ LPCWSTR name, + /* [retval][out] */ BOOL *contains) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetHeader( + /* [in] */ LPCWSTR name, + /* [retval][out] */ LPWSTR *value) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetHeaders( + /* [in] */ LPCWSTR name, + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetIterator( + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2HttpResponseHeadersVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2HttpResponseHeaders * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2HttpResponseHeaders * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2HttpResponseHeaders * This); + + HRESULT ( STDMETHODCALLTYPE *AppendHeader )( + ICoreWebView2HttpResponseHeaders * This, + /* [in] */ LPCWSTR name, + /* [in] */ LPCWSTR value); + + HRESULT ( STDMETHODCALLTYPE *Contains )( + ICoreWebView2HttpResponseHeaders * This, + /* [in] */ LPCWSTR name, + /* [retval][out] */ BOOL *contains); + + HRESULT ( STDMETHODCALLTYPE *GetHeader )( + ICoreWebView2HttpResponseHeaders * This, + /* [in] */ LPCWSTR name, + /* [retval][out] */ LPWSTR *value); + + HRESULT ( STDMETHODCALLTYPE *GetHeaders )( + ICoreWebView2HttpResponseHeaders * This, + /* [in] */ LPCWSTR name, + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator); + + HRESULT ( STDMETHODCALLTYPE *GetIterator )( + ICoreWebView2HttpResponseHeaders * This, + /* [retval][out] */ ICoreWebView2HttpHeadersCollectionIterator **iterator); + + END_INTERFACE + } ICoreWebView2HttpResponseHeadersVtbl; + + interface ICoreWebView2HttpResponseHeaders + { + CONST_VTBL struct ICoreWebView2HttpResponseHeadersVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2HttpResponseHeaders_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2HttpResponseHeaders_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2HttpResponseHeaders_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2HttpResponseHeaders_AppendHeader(This,name,value) \ + ( (This)->lpVtbl -> AppendHeader(This,name,value) ) + +#define ICoreWebView2HttpResponseHeaders_Contains(This,name,contains) \ + ( (This)->lpVtbl -> Contains(This,name,contains) ) + +#define ICoreWebView2HttpResponseHeaders_GetHeader(This,name,value) \ + ( (This)->lpVtbl -> GetHeader(This,name,value) ) + +#define ICoreWebView2HttpResponseHeaders_GetHeaders(This,name,iterator) \ + ( (This)->lpVtbl -> GetHeaders(This,name,iterator) ) + +#define ICoreWebView2HttpResponseHeaders_GetIterator(This,iterator) \ + ( (This)->lpVtbl -> GetIterator(This,iterator) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2HttpResponseHeaders_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2MoveFocusRequestedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2MoveFocusRequestedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2MoveFocusRequestedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2MoveFocusRequestedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("2d6aa13b-3839-4a15-92fc-d88b3c0d9c9d") + ICoreWebView2MoveFocusRequestedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Reason( + /* [retval][out] */ COREWEBVIEW2_MOVE_FOCUS_REASON *reason) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Handled( + /* [retval][out] */ BOOL *value) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Handled( + /* [in] */ BOOL value) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2MoveFocusRequestedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2MoveFocusRequestedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2MoveFocusRequestedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2MoveFocusRequestedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Reason )( + ICoreWebView2MoveFocusRequestedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_MOVE_FOCUS_REASON *reason); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Handled )( + ICoreWebView2MoveFocusRequestedEventArgs * This, + /* [retval][out] */ BOOL *value); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Handled )( + ICoreWebView2MoveFocusRequestedEventArgs * This, + /* [in] */ BOOL value); + + END_INTERFACE + } ICoreWebView2MoveFocusRequestedEventArgsVtbl; + + interface ICoreWebView2MoveFocusRequestedEventArgs + { + CONST_VTBL struct ICoreWebView2MoveFocusRequestedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2MoveFocusRequestedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2MoveFocusRequestedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2MoveFocusRequestedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2MoveFocusRequestedEventArgs_get_Reason(This,reason) \ + ( (This)->lpVtbl -> get_Reason(This,reason) ) + +#define ICoreWebView2MoveFocusRequestedEventArgs_get_Handled(This,value) \ + ( (This)->lpVtbl -> get_Handled(This,value) ) + +#define ICoreWebView2MoveFocusRequestedEventArgs_put_Handled(This,value) \ + ( (This)->lpVtbl -> put_Handled(This,value) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2MoveFocusRequestedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2MoveFocusRequestedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2MoveFocusRequestedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2MoveFocusRequestedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2MoveFocusRequestedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("69035451-6dc7-4cb8-9bce-b2bd70ad289f") + ICoreWebView2MoveFocusRequestedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ ICoreWebView2MoveFocusRequestedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2MoveFocusRequestedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2MoveFocusRequestedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2MoveFocusRequestedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2MoveFocusRequestedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2MoveFocusRequestedEventHandler * This, + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ ICoreWebView2MoveFocusRequestedEventArgs *args); + + END_INTERFACE + } ICoreWebView2MoveFocusRequestedEventHandlerVtbl; + + interface ICoreWebView2MoveFocusRequestedEventHandler + { + CONST_VTBL struct ICoreWebView2MoveFocusRequestedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2MoveFocusRequestedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2MoveFocusRequestedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2MoveFocusRequestedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2MoveFocusRequestedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2MoveFocusRequestedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationCompletedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2NavigationCompletedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2NavigationCompletedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2NavigationCompletedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("30d68b7d-20d9-4752-a9ca-ec8448fbb5c1") + ICoreWebView2NavigationCompletedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsSuccess( + /* [retval][out] */ BOOL *isSuccess) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_WebErrorStatus( + /* [retval][out] */ COREWEBVIEW2_WEB_ERROR_STATUS *webErrorStatus) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_NavigationId( + /* [retval][out] */ UINT64 *navigationId) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2NavigationCompletedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2NavigationCompletedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2NavigationCompletedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2NavigationCompletedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsSuccess )( + ICoreWebView2NavigationCompletedEventArgs * This, + /* [retval][out] */ BOOL *isSuccess); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_WebErrorStatus )( + ICoreWebView2NavigationCompletedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_WEB_ERROR_STATUS *webErrorStatus); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_NavigationId )( + ICoreWebView2NavigationCompletedEventArgs * This, + /* [retval][out] */ UINT64 *navigationId); + + END_INTERFACE + } ICoreWebView2NavigationCompletedEventArgsVtbl; + + interface ICoreWebView2NavigationCompletedEventArgs + { + CONST_VTBL struct ICoreWebView2NavigationCompletedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2NavigationCompletedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2NavigationCompletedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2NavigationCompletedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2NavigationCompletedEventArgs_get_IsSuccess(This,isSuccess) \ + ( (This)->lpVtbl -> get_IsSuccess(This,isSuccess) ) + +#define ICoreWebView2NavigationCompletedEventArgs_get_WebErrorStatus(This,webErrorStatus) \ + ( (This)->lpVtbl -> get_WebErrorStatus(This,webErrorStatus) ) + +#define ICoreWebView2NavigationCompletedEventArgs_get_NavigationId(This,navigationId) \ + ( (This)->lpVtbl -> get_NavigationId(This,navigationId) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2NavigationCompletedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationCompletedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2NavigationCompletedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2NavigationCompletedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2NavigationCompletedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("d33a35bf-1c49-4f98-93ab-006e0533fe1c") + ICoreWebView2NavigationCompletedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2NavigationCompletedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2NavigationCompletedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2NavigationCompletedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2NavigationCompletedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2NavigationCompletedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2NavigationCompletedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2NavigationCompletedEventArgs *args); + + END_INTERFACE + } ICoreWebView2NavigationCompletedEventHandlerVtbl; + + interface ICoreWebView2NavigationCompletedEventHandler + { + CONST_VTBL struct ICoreWebView2NavigationCompletedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2NavigationCompletedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2NavigationCompletedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2NavigationCompletedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2NavigationCompletedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2NavigationCompletedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationStartingEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2NavigationStartingEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2NavigationStartingEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2NavigationStartingEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("5b495469-e119-438a-9b18-7604f25f2e49") + ICoreWebView2NavigationStartingEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Uri( + /* [retval][out] */ LPWSTR *uri) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsUserInitiated( + /* [retval][out] */ BOOL *isUserInitiated) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsRedirected( + /* [retval][out] */ BOOL *isRedirected) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_RequestHeaders( + /* [retval][out] */ ICoreWebView2HttpRequestHeaders **requestHeaders) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Cancel( + /* [retval][out] */ BOOL *cancel) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Cancel( + /* [in] */ BOOL cancel) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_NavigationId( + /* [retval][out] */ UINT64 *navigationId) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2NavigationStartingEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2NavigationStartingEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2NavigationStartingEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Uri )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [retval][out] */ LPWSTR *uri); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsUserInitiated )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [retval][out] */ BOOL *isUserInitiated); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsRedirected )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [retval][out] */ BOOL *isRedirected); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_RequestHeaders )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [retval][out] */ ICoreWebView2HttpRequestHeaders **requestHeaders); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Cancel )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [retval][out] */ BOOL *cancel); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Cancel )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [in] */ BOOL cancel); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_NavigationId )( + ICoreWebView2NavigationStartingEventArgs * This, + /* [retval][out] */ UINT64 *navigationId); + + END_INTERFACE + } ICoreWebView2NavigationStartingEventArgsVtbl; + + interface ICoreWebView2NavigationStartingEventArgs + { + CONST_VTBL struct ICoreWebView2NavigationStartingEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2NavigationStartingEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2NavigationStartingEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2NavigationStartingEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2NavigationStartingEventArgs_get_Uri(This,uri) \ + ( (This)->lpVtbl -> get_Uri(This,uri) ) + +#define ICoreWebView2NavigationStartingEventArgs_get_IsUserInitiated(This,isUserInitiated) \ + ( (This)->lpVtbl -> get_IsUserInitiated(This,isUserInitiated) ) + +#define ICoreWebView2NavigationStartingEventArgs_get_IsRedirected(This,isRedirected) \ + ( (This)->lpVtbl -> get_IsRedirected(This,isRedirected) ) + +#define ICoreWebView2NavigationStartingEventArgs_get_RequestHeaders(This,requestHeaders) \ + ( (This)->lpVtbl -> get_RequestHeaders(This,requestHeaders) ) + +#define ICoreWebView2NavigationStartingEventArgs_get_Cancel(This,cancel) \ + ( (This)->lpVtbl -> get_Cancel(This,cancel) ) + +#define ICoreWebView2NavigationStartingEventArgs_put_Cancel(This,cancel) \ + ( (This)->lpVtbl -> put_Cancel(This,cancel) ) + +#define ICoreWebView2NavigationStartingEventArgs_get_NavigationId(This,navigationId) \ + ( (This)->lpVtbl -> get_NavigationId(This,navigationId) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2NavigationStartingEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2NavigationStartingEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2NavigationStartingEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2NavigationStartingEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2NavigationStartingEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("9adbe429-f36d-432b-9ddc-f8881fbd76e3") + ICoreWebView2NavigationStartingEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2NavigationStartingEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2NavigationStartingEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2NavigationStartingEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2NavigationStartingEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2NavigationStartingEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2NavigationStartingEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2NavigationStartingEventArgs *args); + + END_INTERFACE + } ICoreWebView2NavigationStartingEventHandlerVtbl; + + interface ICoreWebView2NavigationStartingEventHandler + { + CONST_VTBL struct ICoreWebView2NavigationStartingEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2NavigationStartingEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2NavigationStartingEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2NavigationStartingEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2NavigationStartingEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2NavigationStartingEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2NewBrowserVersionAvailableEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2NewBrowserVersionAvailableEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2NewBrowserVersionAvailableEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2NewBrowserVersionAvailableEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("f9a2976e-d34e-44fc-adee-81b6b57ca914") + ICoreWebView2NewBrowserVersionAvailableEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2Environment *webviewEnvironment, + /* [in] */ IUnknown *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2NewBrowserVersionAvailableEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2NewBrowserVersionAvailableEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2NewBrowserVersionAvailableEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2NewBrowserVersionAvailableEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2NewBrowserVersionAvailableEventHandler * This, + /* [in] */ ICoreWebView2Environment *webviewEnvironment, + /* [in] */ IUnknown *args); + + END_INTERFACE + } ICoreWebView2NewBrowserVersionAvailableEventHandlerVtbl; + + interface ICoreWebView2NewBrowserVersionAvailableEventHandler + { + CONST_VTBL struct ICoreWebView2NewBrowserVersionAvailableEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2NewBrowserVersionAvailableEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2NewBrowserVersionAvailableEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2NewBrowserVersionAvailableEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2NewBrowserVersionAvailableEventHandler_Invoke(This,webviewEnvironment,args) \ + ( (This)->lpVtbl -> Invoke(This,webviewEnvironment,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2NewBrowserVersionAvailableEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2NewWindowRequestedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2NewWindowRequestedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2NewWindowRequestedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2NewWindowRequestedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("34acb11c-fc37-4418-9132-f9c21d1eafb9") + ICoreWebView2NewWindowRequestedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Uri( + /* [retval][out] */ LPWSTR *uri) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_NewWindow( + /* [in] */ ICoreWebView2 *newWindow) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_NewWindow( + /* [retval][out] */ ICoreWebView2 **newWindow) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Handled( + /* [in] */ BOOL handled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Handled( + /* [retval][out] */ BOOL *handled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsUserInitiated( + /* [retval][out] */ BOOL *isUserInitiated) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetDeferral( + /* [retval][out] */ ICoreWebView2Deferral **deferral) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_WindowFeatures( + /* [retval][out] */ ICoreWebView2WindowFeatures **value) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2NewWindowRequestedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2NewWindowRequestedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2NewWindowRequestedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Uri )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [retval][out] */ LPWSTR *uri); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_NewWindow )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [in] */ ICoreWebView2 *newWindow); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_NewWindow )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [retval][out] */ ICoreWebView2 **newWindow); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Handled )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [in] */ BOOL handled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Handled )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [retval][out] */ BOOL *handled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsUserInitiated )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [retval][out] */ BOOL *isUserInitiated); + + HRESULT ( STDMETHODCALLTYPE *GetDeferral )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [retval][out] */ ICoreWebView2Deferral **deferral); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_WindowFeatures )( + ICoreWebView2NewWindowRequestedEventArgs * This, + /* [retval][out] */ ICoreWebView2WindowFeatures **value); + + END_INTERFACE + } ICoreWebView2NewWindowRequestedEventArgsVtbl; + + interface ICoreWebView2NewWindowRequestedEventArgs + { + CONST_VTBL struct ICoreWebView2NewWindowRequestedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2NewWindowRequestedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2NewWindowRequestedEventArgs_get_Uri(This,uri) \ + ( (This)->lpVtbl -> get_Uri(This,uri) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_put_NewWindow(This,newWindow) \ + ( (This)->lpVtbl -> put_NewWindow(This,newWindow) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_get_NewWindow(This,newWindow) \ + ( (This)->lpVtbl -> get_NewWindow(This,newWindow) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_put_Handled(This,handled) \ + ( (This)->lpVtbl -> put_Handled(This,handled) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_get_Handled(This,handled) \ + ( (This)->lpVtbl -> get_Handled(This,handled) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_get_IsUserInitiated(This,isUserInitiated) \ + ( (This)->lpVtbl -> get_IsUserInitiated(This,isUserInitiated) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_GetDeferral(This,deferral) \ + ( (This)->lpVtbl -> GetDeferral(This,deferral) ) + +#define ICoreWebView2NewWindowRequestedEventArgs_get_WindowFeatures(This,value) \ + ( (This)->lpVtbl -> get_WindowFeatures(This,value) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2NewWindowRequestedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2NewWindowRequestedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2NewWindowRequestedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2NewWindowRequestedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2NewWindowRequestedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("d4c185fe-c81c-4989-97af-2d3fa7ab5651") + ICoreWebView2NewWindowRequestedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2NewWindowRequestedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2NewWindowRequestedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2NewWindowRequestedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2NewWindowRequestedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2NewWindowRequestedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2NewWindowRequestedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2NewWindowRequestedEventArgs *args); + + END_INTERFACE + } ICoreWebView2NewWindowRequestedEventHandlerVtbl; + + interface ICoreWebView2NewWindowRequestedEventHandler + { + CONST_VTBL struct ICoreWebView2NewWindowRequestedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2NewWindowRequestedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2NewWindowRequestedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2NewWindowRequestedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2NewWindowRequestedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2NewWindowRequestedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2PermissionRequestedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2PermissionRequestedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2PermissionRequestedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2PermissionRequestedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("973ae2ef-ff18-4894-8fb2-3c758f046810") + ICoreWebView2PermissionRequestedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Uri( + /* [retval][out] */ LPWSTR *uri) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_PermissionKind( + /* [retval][out] */ COREWEBVIEW2_PERMISSION_KIND *permissionKind) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsUserInitiated( + /* [retval][out] */ BOOL *isUserInitiated) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_State( + /* [retval][out] */ COREWEBVIEW2_PERMISSION_STATE *state) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_State( + /* [in] */ COREWEBVIEW2_PERMISSION_STATE state) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetDeferral( + /* [retval][out] */ ICoreWebView2Deferral **deferral) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2PermissionRequestedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2PermissionRequestedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2PermissionRequestedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2PermissionRequestedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Uri )( + ICoreWebView2PermissionRequestedEventArgs * This, + /* [retval][out] */ LPWSTR *uri); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_PermissionKind )( + ICoreWebView2PermissionRequestedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_PERMISSION_KIND *permissionKind); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsUserInitiated )( + ICoreWebView2PermissionRequestedEventArgs * This, + /* [retval][out] */ BOOL *isUserInitiated); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_State )( + ICoreWebView2PermissionRequestedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_PERMISSION_STATE *state); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_State )( + ICoreWebView2PermissionRequestedEventArgs * This, + /* [in] */ COREWEBVIEW2_PERMISSION_STATE state); + + HRESULT ( STDMETHODCALLTYPE *GetDeferral )( + ICoreWebView2PermissionRequestedEventArgs * This, + /* [retval][out] */ ICoreWebView2Deferral **deferral); + + END_INTERFACE + } ICoreWebView2PermissionRequestedEventArgsVtbl; + + interface ICoreWebView2PermissionRequestedEventArgs + { + CONST_VTBL struct ICoreWebView2PermissionRequestedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2PermissionRequestedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2PermissionRequestedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2PermissionRequestedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2PermissionRequestedEventArgs_get_Uri(This,uri) \ + ( (This)->lpVtbl -> get_Uri(This,uri) ) + +#define ICoreWebView2PermissionRequestedEventArgs_get_PermissionKind(This,permissionKind) \ + ( (This)->lpVtbl -> get_PermissionKind(This,permissionKind) ) + +#define ICoreWebView2PermissionRequestedEventArgs_get_IsUserInitiated(This,isUserInitiated) \ + ( (This)->lpVtbl -> get_IsUserInitiated(This,isUserInitiated) ) + +#define ICoreWebView2PermissionRequestedEventArgs_get_State(This,state) \ + ( (This)->lpVtbl -> get_State(This,state) ) + +#define ICoreWebView2PermissionRequestedEventArgs_put_State(This,state) \ + ( (This)->lpVtbl -> put_State(This,state) ) + +#define ICoreWebView2PermissionRequestedEventArgs_GetDeferral(This,deferral) \ + ( (This)->lpVtbl -> GetDeferral(This,deferral) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2PermissionRequestedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2PermissionRequestedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2PermissionRequestedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2PermissionRequestedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2PermissionRequestedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("15e1c6a3-c72a-4df3-91d7-d097fbec6bfd") + ICoreWebView2PermissionRequestedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2PermissionRequestedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2PermissionRequestedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2PermissionRequestedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2PermissionRequestedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2PermissionRequestedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2PermissionRequestedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2PermissionRequestedEventArgs *args); + + END_INTERFACE + } ICoreWebView2PermissionRequestedEventHandlerVtbl; + + interface ICoreWebView2PermissionRequestedEventHandler + { + CONST_VTBL struct ICoreWebView2PermissionRequestedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2PermissionRequestedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2PermissionRequestedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2PermissionRequestedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2PermissionRequestedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2PermissionRequestedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ProcessFailedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2ProcessFailedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ProcessFailedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ProcessFailedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("8155a9a4-1474-4a86-8cae-151b0fa6b8ca") + ICoreWebView2ProcessFailedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ProcessFailedKind( + /* [retval][out] */ COREWEBVIEW2_PROCESS_FAILED_KIND *processFailedKind) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ProcessFailedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ProcessFailedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ProcessFailedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ProcessFailedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ProcessFailedKind )( + ICoreWebView2ProcessFailedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_PROCESS_FAILED_KIND *processFailedKind); + + END_INTERFACE + } ICoreWebView2ProcessFailedEventArgsVtbl; + + interface ICoreWebView2ProcessFailedEventArgs + { + CONST_VTBL struct ICoreWebView2ProcessFailedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ProcessFailedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ProcessFailedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ProcessFailedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ProcessFailedEventArgs_get_ProcessFailedKind(This,processFailedKind) \ + ( (This)->lpVtbl -> get_ProcessFailedKind(This,processFailedKind) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ProcessFailedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ProcessFailedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2ProcessFailedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ProcessFailedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ProcessFailedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("79e0aea4-990b-42d9-aa1d-0fcc2e5bc7f1") + ICoreWebView2ProcessFailedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2ProcessFailedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ProcessFailedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ProcessFailedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ProcessFailedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ProcessFailedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2ProcessFailedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2ProcessFailedEventArgs *args); + + END_INTERFACE + } ICoreWebView2ProcessFailedEventHandlerVtbl; + + interface ICoreWebView2ProcessFailedEventHandler + { + CONST_VTBL struct ICoreWebView2ProcessFailedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ProcessFailedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ProcessFailedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ProcessFailedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ProcessFailedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ProcessFailedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ScriptDialogOpeningEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2ScriptDialogOpeningEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ScriptDialogOpeningEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ScriptDialogOpeningEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("7390bb70-abe0-4843-9529-f143b31b03d6") + ICoreWebView2ScriptDialogOpeningEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Uri( + /* [retval][out] */ LPWSTR *uri) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Kind( + /* [retval][out] */ COREWEBVIEW2_SCRIPT_DIALOG_KIND *kind) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Message( + /* [retval][out] */ LPWSTR *message) = 0; + + virtual HRESULT STDMETHODCALLTYPE Accept( void) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_DefaultText( + /* [retval][out] */ LPWSTR *defaultText) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ResultText( + /* [retval][out] */ LPWSTR *resultText) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_ResultText( + /* [in] */ LPCWSTR resultText) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetDeferral( + /* [retval][out] */ ICoreWebView2Deferral **deferral) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ScriptDialogOpeningEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ScriptDialogOpeningEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ScriptDialogOpeningEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Uri )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [retval][out] */ LPWSTR *uri); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Kind )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_SCRIPT_DIALOG_KIND *kind); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Message )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [retval][out] */ LPWSTR *message); + + HRESULT ( STDMETHODCALLTYPE *Accept )( + ICoreWebView2ScriptDialogOpeningEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_DefaultText )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [retval][out] */ LPWSTR *defaultText); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ResultText )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [retval][out] */ LPWSTR *resultText); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_ResultText )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [in] */ LPCWSTR resultText); + + HRESULT ( STDMETHODCALLTYPE *GetDeferral )( + ICoreWebView2ScriptDialogOpeningEventArgs * This, + /* [retval][out] */ ICoreWebView2Deferral **deferral); + + END_INTERFACE + } ICoreWebView2ScriptDialogOpeningEventArgsVtbl; + + interface ICoreWebView2ScriptDialogOpeningEventArgs + { + CONST_VTBL struct ICoreWebView2ScriptDialogOpeningEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ScriptDialogOpeningEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ScriptDialogOpeningEventArgs_get_Uri(This,uri) \ + ( (This)->lpVtbl -> get_Uri(This,uri) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_get_Kind(This,kind) \ + ( (This)->lpVtbl -> get_Kind(This,kind) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_get_Message(This,message) \ + ( (This)->lpVtbl -> get_Message(This,message) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_Accept(This) \ + ( (This)->lpVtbl -> Accept(This) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_get_DefaultText(This,defaultText) \ + ( (This)->lpVtbl -> get_DefaultText(This,defaultText) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_get_ResultText(This,resultText) \ + ( (This)->lpVtbl -> get_ResultText(This,resultText) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_put_ResultText(This,resultText) \ + ( (This)->lpVtbl -> put_ResultText(This,resultText) ) + +#define ICoreWebView2ScriptDialogOpeningEventArgs_GetDeferral(This,deferral) \ + ( (This)->lpVtbl -> GetDeferral(This,deferral) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ScriptDialogOpeningEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ScriptDialogOpeningEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2ScriptDialogOpeningEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ScriptDialogOpeningEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ScriptDialogOpeningEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("ef381bf9-afa8-4e37-91c4-8ac48524bdfb") + ICoreWebView2ScriptDialogOpeningEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2ScriptDialogOpeningEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ScriptDialogOpeningEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ScriptDialogOpeningEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ScriptDialogOpeningEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ScriptDialogOpeningEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2ScriptDialogOpeningEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2ScriptDialogOpeningEventArgs *args); + + END_INTERFACE + } ICoreWebView2ScriptDialogOpeningEventHandlerVtbl; + + interface ICoreWebView2ScriptDialogOpeningEventHandler + { + CONST_VTBL struct ICoreWebView2ScriptDialogOpeningEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ScriptDialogOpeningEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ScriptDialogOpeningEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ScriptDialogOpeningEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ScriptDialogOpeningEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ScriptDialogOpeningEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2Settings_INTERFACE_DEFINED__ +#define __ICoreWebView2Settings_INTERFACE_DEFINED__ + +/* interface ICoreWebView2Settings */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2Settings; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("e562e4f0-d7fa-43ac-8d71-c05150499f00") + ICoreWebView2Settings : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsScriptEnabled( + /* [retval][out] */ BOOL *isScriptEnabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_IsScriptEnabled( + /* [in] */ BOOL isScriptEnabled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsWebMessageEnabled( + /* [retval][out] */ BOOL *isWebMessageEnabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_IsWebMessageEnabled( + /* [in] */ BOOL isWebMessageEnabled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AreDefaultScriptDialogsEnabled( + /* [retval][out] */ BOOL *areDefaultScriptDialogsEnabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_AreDefaultScriptDialogsEnabled( + /* [in] */ BOOL areDefaultScriptDialogsEnabled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsStatusBarEnabled( + /* [retval][out] */ BOOL *isStatusBarEnabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_IsStatusBarEnabled( + /* [in] */ BOOL isStatusBarEnabled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AreDevToolsEnabled( + /* [retval][out] */ BOOL *areDevToolsEnabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_AreDevToolsEnabled( + /* [in] */ BOOL areDevToolsEnabled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AreDefaultContextMenusEnabled( + /* [retval][out] */ BOOL *enabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_AreDefaultContextMenusEnabled( + /* [in] */ BOOL enabled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AreHostObjectsAllowed( + /* [retval][out] */ BOOL *allowed) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_AreHostObjectsAllowed( + /* [in] */ BOOL allowed) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsZoomControlEnabled( + /* [retval][out] */ BOOL *enabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_IsZoomControlEnabled( + /* [in] */ BOOL enabled) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsBuiltInErrorPageEnabled( + /* [retval][out] */ BOOL *enabled) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_IsBuiltInErrorPageEnabled( + /* [in] */ BOOL enabled) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2SettingsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2Settings * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2Settings * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2Settings * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsScriptEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *isScriptEnabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_IsScriptEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL isScriptEnabled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsWebMessageEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *isWebMessageEnabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_IsWebMessageEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL isWebMessageEnabled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_AreDefaultScriptDialogsEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *areDefaultScriptDialogsEnabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_AreDefaultScriptDialogsEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL areDefaultScriptDialogsEnabled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsStatusBarEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *isStatusBarEnabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_IsStatusBarEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL isStatusBarEnabled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_AreDevToolsEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *areDevToolsEnabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_AreDevToolsEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL areDevToolsEnabled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_AreDefaultContextMenusEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *enabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_AreDefaultContextMenusEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL enabled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_AreHostObjectsAllowed )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *allowed); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_AreHostObjectsAllowed )( + ICoreWebView2Settings * This, + /* [in] */ BOOL allowed); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsZoomControlEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *enabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_IsZoomControlEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL enabled); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsBuiltInErrorPageEnabled )( + ICoreWebView2Settings * This, + /* [retval][out] */ BOOL *enabled); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_IsBuiltInErrorPageEnabled )( + ICoreWebView2Settings * This, + /* [in] */ BOOL enabled); + + END_INTERFACE + } ICoreWebView2SettingsVtbl; + + interface ICoreWebView2Settings + { + CONST_VTBL struct ICoreWebView2SettingsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2Settings_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2Settings_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2Settings_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2Settings_get_IsScriptEnabled(This,isScriptEnabled) \ + ( (This)->lpVtbl -> get_IsScriptEnabled(This,isScriptEnabled) ) + +#define ICoreWebView2Settings_put_IsScriptEnabled(This,isScriptEnabled) \ + ( (This)->lpVtbl -> put_IsScriptEnabled(This,isScriptEnabled) ) + +#define ICoreWebView2Settings_get_IsWebMessageEnabled(This,isWebMessageEnabled) \ + ( (This)->lpVtbl -> get_IsWebMessageEnabled(This,isWebMessageEnabled) ) + +#define ICoreWebView2Settings_put_IsWebMessageEnabled(This,isWebMessageEnabled) \ + ( (This)->lpVtbl -> put_IsWebMessageEnabled(This,isWebMessageEnabled) ) + +#define ICoreWebView2Settings_get_AreDefaultScriptDialogsEnabled(This,areDefaultScriptDialogsEnabled) \ + ( (This)->lpVtbl -> get_AreDefaultScriptDialogsEnabled(This,areDefaultScriptDialogsEnabled) ) + +#define ICoreWebView2Settings_put_AreDefaultScriptDialogsEnabled(This,areDefaultScriptDialogsEnabled) \ + ( (This)->lpVtbl -> put_AreDefaultScriptDialogsEnabled(This,areDefaultScriptDialogsEnabled) ) + +#define ICoreWebView2Settings_get_IsStatusBarEnabled(This,isStatusBarEnabled) \ + ( (This)->lpVtbl -> get_IsStatusBarEnabled(This,isStatusBarEnabled) ) + +#define ICoreWebView2Settings_put_IsStatusBarEnabled(This,isStatusBarEnabled) \ + ( (This)->lpVtbl -> put_IsStatusBarEnabled(This,isStatusBarEnabled) ) + +#define ICoreWebView2Settings_get_AreDevToolsEnabled(This,areDevToolsEnabled) \ + ( (This)->lpVtbl -> get_AreDevToolsEnabled(This,areDevToolsEnabled) ) + +#define ICoreWebView2Settings_put_AreDevToolsEnabled(This,areDevToolsEnabled) \ + ( (This)->lpVtbl -> put_AreDevToolsEnabled(This,areDevToolsEnabled) ) + +#define ICoreWebView2Settings_get_AreDefaultContextMenusEnabled(This,enabled) \ + ( (This)->lpVtbl -> get_AreDefaultContextMenusEnabled(This,enabled) ) + +#define ICoreWebView2Settings_put_AreDefaultContextMenusEnabled(This,enabled) \ + ( (This)->lpVtbl -> put_AreDefaultContextMenusEnabled(This,enabled) ) + +#define ICoreWebView2Settings_get_AreHostObjectsAllowed(This,allowed) \ + ( (This)->lpVtbl -> get_AreHostObjectsAllowed(This,allowed) ) + +#define ICoreWebView2Settings_put_AreHostObjectsAllowed(This,allowed) \ + ( (This)->lpVtbl -> put_AreHostObjectsAllowed(This,allowed) ) + +#define ICoreWebView2Settings_get_IsZoomControlEnabled(This,enabled) \ + ( (This)->lpVtbl -> get_IsZoomControlEnabled(This,enabled) ) + +#define ICoreWebView2Settings_put_IsZoomControlEnabled(This,enabled) \ + ( (This)->lpVtbl -> put_IsZoomControlEnabled(This,enabled) ) + +#define ICoreWebView2Settings_get_IsBuiltInErrorPageEnabled(This,enabled) \ + ( (This)->lpVtbl -> get_IsBuiltInErrorPageEnabled(This,enabled) ) + +#define ICoreWebView2Settings_put_IsBuiltInErrorPageEnabled(This,enabled) \ + ( (This)->lpVtbl -> put_IsBuiltInErrorPageEnabled(This,enabled) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2Settings_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2SourceChangedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2SourceChangedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2SourceChangedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2SourceChangedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("31e0e545-1dba-4266-8914-f63848a1f7d7") + ICoreWebView2SourceChangedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsNewDocument( + /* [retval][out] */ BOOL *isNewDocument) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2SourceChangedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2SourceChangedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2SourceChangedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2SourceChangedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_IsNewDocument )( + ICoreWebView2SourceChangedEventArgs * This, + /* [retval][out] */ BOOL *isNewDocument); + + END_INTERFACE + } ICoreWebView2SourceChangedEventArgsVtbl; + + interface ICoreWebView2SourceChangedEventArgs + { + CONST_VTBL struct ICoreWebView2SourceChangedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2SourceChangedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2SourceChangedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2SourceChangedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2SourceChangedEventArgs_get_IsNewDocument(This,isNewDocument) \ + ( (This)->lpVtbl -> get_IsNewDocument(This,isNewDocument) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2SourceChangedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2SourceChangedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2SourceChangedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2SourceChangedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2SourceChangedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("3c067f9f-5388-4772-8b48-79f7ef1ab37c") + ICoreWebView2SourceChangedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2SourceChangedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2SourceChangedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2SourceChangedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2SourceChangedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2SourceChangedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2SourceChangedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2SourceChangedEventArgs *args); + + END_INTERFACE + } ICoreWebView2SourceChangedEventHandlerVtbl; + + interface ICoreWebView2SourceChangedEventHandler + { + CONST_VTBL struct ICoreWebView2SourceChangedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2SourceChangedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2SourceChangedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2SourceChangedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2SourceChangedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2SourceChangedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WebMessageReceivedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2WebMessageReceivedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WebMessageReceivedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WebMessageReceivedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("0f99a40c-e962-4207-9e92-e3d542eff849") + ICoreWebView2WebMessageReceivedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Source( + /* [retval][out] */ LPWSTR *source) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_WebMessageAsJson( + /* [retval][out] */ LPWSTR *webMessageAsJson) = 0; + + virtual HRESULT STDMETHODCALLTYPE TryGetWebMessageAsString( + /* [retval][out] */ LPWSTR *webMessageAsString) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WebMessageReceivedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WebMessageReceivedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WebMessageReceivedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WebMessageReceivedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Source )( + ICoreWebView2WebMessageReceivedEventArgs * This, + /* [retval][out] */ LPWSTR *source); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_WebMessageAsJson )( + ICoreWebView2WebMessageReceivedEventArgs * This, + /* [retval][out] */ LPWSTR *webMessageAsJson); + + HRESULT ( STDMETHODCALLTYPE *TryGetWebMessageAsString )( + ICoreWebView2WebMessageReceivedEventArgs * This, + /* [retval][out] */ LPWSTR *webMessageAsString); + + END_INTERFACE + } ICoreWebView2WebMessageReceivedEventArgsVtbl; + + interface ICoreWebView2WebMessageReceivedEventArgs + { + CONST_VTBL struct ICoreWebView2WebMessageReceivedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WebMessageReceivedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WebMessageReceivedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WebMessageReceivedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WebMessageReceivedEventArgs_get_Source(This,source) \ + ( (This)->lpVtbl -> get_Source(This,source) ) + +#define ICoreWebView2WebMessageReceivedEventArgs_get_WebMessageAsJson(This,webMessageAsJson) \ + ( (This)->lpVtbl -> get_WebMessageAsJson(This,webMessageAsJson) ) + +#define ICoreWebView2WebMessageReceivedEventArgs_TryGetWebMessageAsString(This,webMessageAsString) \ + ( (This)->lpVtbl -> TryGetWebMessageAsString(This,webMessageAsString) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WebMessageReceivedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WebMessageReceivedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2WebMessageReceivedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WebMessageReceivedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WebMessageReceivedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("57213f19-00e6-49fa-8e07-898ea01ecbd2") + ICoreWebView2WebMessageReceivedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2WebMessageReceivedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WebMessageReceivedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WebMessageReceivedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WebMessageReceivedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WebMessageReceivedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2WebMessageReceivedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2WebMessageReceivedEventArgs *args); + + END_INTERFACE + } ICoreWebView2WebMessageReceivedEventHandlerVtbl; + + interface ICoreWebView2WebMessageReceivedEventHandler + { + CONST_VTBL struct ICoreWebView2WebMessageReceivedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WebMessageReceivedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WebMessageReceivedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WebMessageReceivedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WebMessageReceivedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WebMessageReceivedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceRequest_INTERFACE_DEFINED__ +#define __ICoreWebView2WebResourceRequest_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WebResourceRequest */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WebResourceRequest; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("97055cd4-512c-4264-8b5f-e3f446cea6a5") + ICoreWebView2WebResourceRequest : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Uri( + /* [retval][out] */ LPWSTR *uri) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Uri( + /* [in] */ LPCWSTR uri) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Method( + /* [retval][out] */ LPWSTR *method) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Method( + /* [in] */ LPCWSTR method) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Content( + /* [retval][out] */ IStream **content) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Content( + /* [in] */ IStream *content) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Headers( + /* [retval][out] */ ICoreWebView2HttpRequestHeaders **headers) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WebResourceRequestVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WebResourceRequest * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WebResourceRequest * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WebResourceRequest * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Uri )( + ICoreWebView2WebResourceRequest * This, + /* [retval][out] */ LPWSTR *uri); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Uri )( + ICoreWebView2WebResourceRequest * This, + /* [in] */ LPCWSTR uri); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Method )( + ICoreWebView2WebResourceRequest * This, + /* [retval][out] */ LPWSTR *method); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Method )( + ICoreWebView2WebResourceRequest * This, + /* [in] */ LPCWSTR method); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Content )( + ICoreWebView2WebResourceRequest * This, + /* [retval][out] */ IStream **content); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Content )( + ICoreWebView2WebResourceRequest * This, + /* [in] */ IStream *content); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Headers )( + ICoreWebView2WebResourceRequest * This, + /* [retval][out] */ ICoreWebView2HttpRequestHeaders **headers); + + END_INTERFACE + } ICoreWebView2WebResourceRequestVtbl; + + interface ICoreWebView2WebResourceRequest + { + CONST_VTBL struct ICoreWebView2WebResourceRequestVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WebResourceRequest_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WebResourceRequest_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WebResourceRequest_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WebResourceRequest_get_Uri(This,uri) \ + ( (This)->lpVtbl -> get_Uri(This,uri) ) + +#define ICoreWebView2WebResourceRequest_put_Uri(This,uri) \ + ( (This)->lpVtbl -> put_Uri(This,uri) ) + +#define ICoreWebView2WebResourceRequest_get_Method(This,method) \ + ( (This)->lpVtbl -> get_Method(This,method) ) + +#define ICoreWebView2WebResourceRequest_put_Method(This,method) \ + ( (This)->lpVtbl -> put_Method(This,method) ) + +#define ICoreWebView2WebResourceRequest_get_Content(This,content) \ + ( (This)->lpVtbl -> get_Content(This,content) ) + +#define ICoreWebView2WebResourceRequest_put_Content(This,content) \ + ( (This)->lpVtbl -> put_Content(This,content) ) + +#define ICoreWebView2WebResourceRequest_get_Headers(This,headers) \ + ( (This)->lpVtbl -> get_Headers(This,headers) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WebResourceRequest_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceRequestedEventArgs_INTERFACE_DEFINED__ +#define __ICoreWebView2WebResourceRequestedEventArgs_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WebResourceRequestedEventArgs */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WebResourceRequestedEventArgs; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("453e667f-12c7-49d4-be6d-ddbe7956f57a") + ICoreWebView2WebResourceRequestedEventArgs : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Request( + /* [retval][out] */ ICoreWebView2WebResourceRequest **request) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Response( + /* [retval][out] */ ICoreWebView2WebResourceResponse **response) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Response( + /* [in] */ ICoreWebView2WebResourceResponse *response) = 0; + + virtual HRESULT STDMETHODCALLTYPE GetDeferral( + /* [retval][out] */ ICoreWebView2Deferral **deferral) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ResourceContext( + /* [retval][out] */ COREWEBVIEW2_WEB_RESOURCE_CONTEXT *context) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WebResourceRequestedEventArgsVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WebResourceRequestedEventArgs * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WebResourceRequestedEventArgs * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WebResourceRequestedEventArgs * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Request )( + ICoreWebView2WebResourceRequestedEventArgs * This, + /* [retval][out] */ ICoreWebView2WebResourceRequest **request); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Response )( + ICoreWebView2WebResourceRequestedEventArgs * This, + /* [retval][out] */ ICoreWebView2WebResourceResponse **response); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Response )( + ICoreWebView2WebResourceRequestedEventArgs * This, + /* [in] */ ICoreWebView2WebResourceResponse *response); + + HRESULT ( STDMETHODCALLTYPE *GetDeferral )( + ICoreWebView2WebResourceRequestedEventArgs * This, + /* [retval][out] */ ICoreWebView2Deferral **deferral); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ResourceContext )( + ICoreWebView2WebResourceRequestedEventArgs * This, + /* [retval][out] */ COREWEBVIEW2_WEB_RESOURCE_CONTEXT *context); + + END_INTERFACE + } ICoreWebView2WebResourceRequestedEventArgsVtbl; + + interface ICoreWebView2WebResourceRequestedEventArgs + { + CONST_VTBL struct ICoreWebView2WebResourceRequestedEventArgsVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WebResourceRequestedEventArgs_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WebResourceRequestedEventArgs_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WebResourceRequestedEventArgs_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WebResourceRequestedEventArgs_get_Request(This,request) \ + ( (This)->lpVtbl -> get_Request(This,request) ) + +#define ICoreWebView2WebResourceRequestedEventArgs_get_Response(This,response) \ + ( (This)->lpVtbl -> get_Response(This,response) ) + +#define ICoreWebView2WebResourceRequestedEventArgs_put_Response(This,response) \ + ( (This)->lpVtbl -> put_Response(This,response) ) + +#define ICoreWebView2WebResourceRequestedEventArgs_GetDeferral(This,deferral) \ + ( (This)->lpVtbl -> GetDeferral(This,deferral) ) + +#define ICoreWebView2WebResourceRequestedEventArgs_get_ResourceContext(This,context) \ + ( (This)->lpVtbl -> get_ResourceContext(This,context) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WebResourceRequestedEventArgs_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceRequestedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2WebResourceRequestedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WebResourceRequestedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WebResourceRequestedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("ab00b74c-15f1-4646-80e8-e76341d25d71") + ICoreWebView2WebResourceRequestedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2WebResourceRequestedEventArgs *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WebResourceRequestedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WebResourceRequestedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WebResourceRequestedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WebResourceRequestedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2WebResourceRequestedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ ICoreWebView2WebResourceRequestedEventArgs *args); + + END_INTERFACE + } ICoreWebView2WebResourceRequestedEventHandlerVtbl; + + interface ICoreWebView2WebResourceRequestedEventHandler + { + CONST_VTBL struct ICoreWebView2WebResourceRequestedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WebResourceRequestedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WebResourceRequestedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WebResourceRequestedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WebResourceRequestedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WebResourceRequestedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WebResourceResponse_INTERFACE_DEFINED__ +#define __ICoreWebView2WebResourceResponse_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WebResourceResponse */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WebResourceResponse; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("aafcc94f-fa27-48fd-97df-830ef75aaec9") + ICoreWebView2WebResourceResponse : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Content( + /* [retval][out] */ IStream **content) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Content( + /* [in] */ IStream *content) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Headers( + /* [retval][out] */ ICoreWebView2HttpResponseHeaders **headers) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_StatusCode( + /* [retval][out] */ int *statusCode) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_StatusCode( + /* [in] */ int statusCode) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ReasonPhrase( + /* [retval][out] */ LPWSTR *reasonPhrase) = 0; + + virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_ReasonPhrase( + /* [in] */ LPCWSTR reasonPhrase) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WebResourceResponseVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WebResourceResponse * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WebResourceResponse * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WebResourceResponse * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Content )( + ICoreWebView2WebResourceResponse * This, + /* [retval][out] */ IStream **content); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_Content )( + ICoreWebView2WebResourceResponse * This, + /* [in] */ IStream *content); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Headers )( + ICoreWebView2WebResourceResponse * This, + /* [retval][out] */ ICoreWebView2HttpResponseHeaders **headers); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_StatusCode )( + ICoreWebView2WebResourceResponse * This, + /* [retval][out] */ int *statusCode); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_StatusCode )( + ICoreWebView2WebResourceResponse * This, + /* [in] */ int statusCode); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ReasonPhrase )( + ICoreWebView2WebResourceResponse * This, + /* [retval][out] */ LPWSTR *reasonPhrase); + + /* [propput] */ HRESULT ( STDMETHODCALLTYPE *put_ReasonPhrase )( + ICoreWebView2WebResourceResponse * This, + /* [in] */ LPCWSTR reasonPhrase); + + END_INTERFACE + } ICoreWebView2WebResourceResponseVtbl; + + interface ICoreWebView2WebResourceResponse + { + CONST_VTBL struct ICoreWebView2WebResourceResponseVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WebResourceResponse_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WebResourceResponse_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WebResourceResponse_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WebResourceResponse_get_Content(This,content) \ + ( (This)->lpVtbl -> get_Content(This,content) ) + +#define ICoreWebView2WebResourceResponse_put_Content(This,content) \ + ( (This)->lpVtbl -> put_Content(This,content) ) + +#define ICoreWebView2WebResourceResponse_get_Headers(This,headers) \ + ( (This)->lpVtbl -> get_Headers(This,headers) ) + +#define ICoreWebView2WebResourceResponse_get_StatusCode(This,statusCode) \ + ( (This)->lpVtbl -> get_StatusCode(This,statusCode) ) + +#define ICoreWebView2WebResourceResponse_put_StatusCode(This,statusCode) \ + ( (This)->lpVtbl -> put_StatusCode(This,statusCode) ) + +#define ICoreWebView2WebResourceResponse_get_ReasonPhrase(This,reasonPhrase) \ + ( (This)->lpVtbl -> get_ReasonPhrase(This,reasonPhrase) ) + +#define ICoreWebView2WebResourceResponse_put_ReasonPhrase(This,reasonPhrase) \ + ( (This)->lpVtbl -> put_ReasonPhrase(This,reasonPhrase) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WebResourceResponse_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WindowCloseRequestedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2WindowCloseRequestedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WindowCloseRequestedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WindowCloseRequestedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("5c19e9e0-092f-486b-affa-ca8231913039") + ICoreWebView2WindowCloseRequestedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WindowCloseRequestedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WindowCloseRequestedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WindowCloseRequestedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WindowCloseRequestedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2WindowCloseRequestedEventHandler * This, + /* [in] */ ICoreWebView2 *sender, + /* [in] */ IUnknown *args); + + END_INTERFACE + } ICoreWebView2WindowCloseRequestedEventHandlerVtbl; + + interface ICoreWebView2WindowCloseRequestedEventHandler + { + CONST_VTBL struct ICoreWebView2WindowCloseRequestedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WindowCloseRequestedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WindowCloseRequestedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WindowCloseRequestedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WindowCloseRequestedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WindowCloseRequestedEventHandler_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2WindowFeatures_INTERFACE_DEFINED__ +#define __ICoreWebView2WindowFeatures_INTERFACE_DEFINED__ + +/* interface ICoreWebView2WindowFeatures */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2WindowFeatures; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("5eaf559f-b46e-4397-8860-e422f287ff1e") + ICoreWebView2WindowFeatures : public IUnknown + { + public: + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_HasPosition( + /* [retval][out] */ BOOL *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_HasSize( + /* [retval][out] */ BOOL *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Left( + /* [retval][out] */ UINT32 *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Top( + /* [retval][out] */ UINT32 *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Height( + /* [retval][out] */ UINT32 *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Width( + /* [retval][out] */ UINT32 *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ShouldDisplayMenuBar( + /* [retval][out] */ BOOL *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ShouldDisplayStatus( + /* [retval][out] */ BOOL *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ShouldDisplayToolbar( + /* [retval][out] */ BOOL *value) = 0; + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ShouldDisplayScrollBars( + /* [retval][out] */ BOOL *value) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2WindowFeaturesVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2WindowFeatures * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2WindowFeatures * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2WindowFeatures * This); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasPosition )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ BOOL *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_HasSize )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ BOOL *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Left )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ UINT32 *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Top )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ UINT32 *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Height )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ UINT32 *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_Width )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ UINT32 *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShouldDisplayMenuBar )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ BOOL *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShouldDisplayStatus )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ BOOL *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShouldDisplayToolbar )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ BOOL *value); + + /* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_ShouldDisplayScrollBars )( + ICoreWebView2WindowFeatures * This, + /* [retval][out] */ BOOL *value); + + END_INTERFACE + } ICoreWebView2WindowFeaturesVtbl; + + interface ICoreWebView2WindowFeatures + { + CONST_VTBL struct ICoreWebView2WindowFeaturesVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2WindowFeatures_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2WindowFeatures_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2WindowFeatures_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2WindowFeatures_get_HasPosition(This,value) \ + ( (This)->lpVtbl -> get_HasPosition(This,value) ) + +#define ICoreWebView2WindowFeatures_get_HasSize(This,value) \ + ( (This)->lpVtbl -> get_HasSize(This,value) ) + +#define ICoreWebView2WindowFeatures_get_Left(This,value) \ + ( (This)->lpVtbl -> get_Left(This,value) ) + +#define ICoreWebView2WindowFeatures_get_Top(This,value) \ + ( (This)->lpVtbl -> get_Top(This,value) ) + +#define ICoreWebView2WindowFeatures_get_Height(This,value) \ + ( (This)->lpVtbl -> get_Height(This,value) ) + +#define ICoreWebView2WindowFeatures_get_Width(This,value) \ + ( (This)->lpVtbl -> get_Width(This,value) ) + +#define ICoreWebView2WindowFeatures_get_ShouldDisplayMenuBar(This,value) \ + ( (This)->lpVtbl -> get_ShouldDisplayMenuBar(This,value) ) + +#define ICoreWebView2WindowFeatures_get_ShouldDisplayStatus(This,value) \ + ( (This)->lpVtbl -> get_ShouldDisplayStatus(This,value) ) + +#define ICoreWebView2WindowFeatures_get_ShouldDisplayToolbar(This,value) \ + ( (This)->lpVtbl -> get_ShouldDisplayToolbar(This,value) ) + +#define ICoreWebView2WindowFeatures_get_ShouldDisplayScrollBars(This,value) \ + ( (This)->lpVtbl -> get_ShouldDisplayScrollBars(This,value) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2WindowFeatures_INTERFACE_DEFINED__ */ + + +#ifndef __ICoreWebView2ZoomFactorChangedEventHandler_INTERFACE_DEFINED__ +#define __ICoreWebView2ZoomFactorChangedEventHandler_INTERFACE_DEFINED__ + +/* interface ICoreWebView2ZoomFactorChangedEventHandler */ +/* [unique][object][uuid] */ + + +EXTERN_C const IID IID_ICoreWebView2ZoomFactorChangedEventHandler; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("b52d71d6-c4df-4543-a90c-64a3e60f38cb") + ICoreWebView2ZoomFactorChangedEventHandler : public IUnknown + { + public: + virtual HRESULT STDMETHODCALLTYPE Invoke( + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ IUnknown *args) = 0; + + }; + + +#else /* C style interface */ + + typedef struct ICoreWebView2ZoomFactorChangedEventHandlerVtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + ICoreWebView2ZoomFactorChangedEventHandler * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + ICoreWebView2ZoomFactorChangedEventHandler * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + ICoreWebView2ZoomFactorChangedEventHandler * This); + + HRESULT ( STDMETHODCALLTYPE *Invoke )( + ICoreWebView2ZoomFactorChangedEventHandler * This, + /* [in] */ ICoreWebView2Controller *sender, + /* [in] */ IUnknown *args); + + END_INTERFACE + } ICoreWebView2ZoomFactorChangedEventHandlerVtbl; + + interface ICoreWebView2ZoomFactorChangedEventHandler + { + CONST_VTBL struct ICoreWebView2ZoomFactorChangedEventHandlerVtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define ICoreWebView2ZoomFactorChangedEventHandler_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define ICoreWebView2ZoomFactorChangedEventHandler_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define ICoreWebView2ZoomFactorChangedEventHandler_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define ICoreWebView2ZoomFactorChangedEventHandler_Invoke(This,sender,args) \ + ( (This)->lpVtbl -> Invoke(This,sender,args) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + + + +#endif /* __ICoreWebView2ZoomFactorChangedEventHandler_INTERFACE_DEFINED__ */ + +#endif /* __WebView2_LIBRARY_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + +