AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AWindowManager.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13#include <AUI/Thread/IEventLoop.h>
   14#include "AUI/Common/ATimer.h"
   15#include "AUI/Platform/Pipe.h"
   16#include "AUI/Util/AWatchdog.h"
   17#include "IRenderingContext.h"
   18
   19class AWindow;
   20
   21class API_AUI_VIEWS AWindowManager: public IEventLoop {
   22    friend class AWindow;
   23    friend class AClipboard;
   24private:
   25    AWatchdog mWatchdog;
   26    _<ATimer> mHangTimer;
   27
   28protected:
   29    IEventLoop::Handle mHandle;
   30    ADeque<_<AWindow>> mWindows;
   31    bool mLoopRunning = false;
   32
   33public:
   34    AWindowManager();
   35    ~AWindowManager() override;
   36
   37    AWatchdog& watchdog() noexcept {
   38        return mWatchdog;
   39    }
   40
   41    bool isLoopRunning() const { return mLoopRunning; }
   42
   43    void removeAllWindows() {
   44        auto windows = std::move(mWindows); // keeping it safe
   45        windows.clear();
   46    }
   47
   48    void closeAllWindows();
   49    void notifyProcessMessages() override;
   50    void loop() override;
   51
   52    const ADeque<_<AWindow>>& getWindows() const {
   53        return mWindows;
   54    }
   55
   56    void start() {
   57        mLoopRunning = true;
   58    }
   59    void stop() {
   60        mLoopRunning = false;
   61        notifyProcessMessages();
   62    }
   63
   64    virtual void initNativeWindow(const IRenderingContext::Init& init);
   65
   66    template<typename T>
   67    [[nodiscard]] ADeque<_<T>> getWindowsOfType() const {
   68        ADeque<_<T>> result;
   69        for (auto& w : mWindows) {
   70            if (auto c = _cast<T>(w)) {
   71                result << c;
   72            }
   73        }
   74
   75        return std::move(result);
   76    }
   77};
A std::deque with AUI extensions.
Definition ADeque.h:27
Watchdog helper class.
Definition AWatchdog.h:38
void loop() override
Do message processing loop.
void notifyProcessMessages() override
Notifies this IEventLoop that its thread got a new message to process.
Represents a window in the underlying windowing system.
Definition AWindow.h:45
Definition IEventLoop.h:33
virtual void notifyProcessMessages()=0
Notifies this IEventLoop that its thread got a new message to process.
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
class_of c
Selects views that are of the specified classes.
Definition class_of.h:84