summaryrefslogtreecommitdiff
path: root/vcl/inc/jsdialog/jsdialogmessages.hxx
blob: 0007c5195f60fc02999344382cd64ba4b6e8dbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <deque>
#include <mutex>

#include <rtl/ustring.hxx>
#include <vcl/idle.hxx>
#include <vcl/jsdialog/executor.hxx>
#include <vcl/menu.hxx>
#include <vcl/window.hxx>

namespace jsdialog
{
enum MessageType
{
    FullUpdate,
    WidgetUpdate,
    Close,
    Action,
    Popup,
    PopupClose,
    Menu,
};
}

/// Class with the message description for storing in the queue
class JSDialogMessageInfo
{
public:
    jsdialog::MessageType m_eType;
    VclPtr<vcl::Window> m_pWindow;
    VclPtr<PopupMenu> m_pMenu;
    std::unique_ptr<jsdialog::ActionDataMap> m_pData;

private:
    void copy(const JSDialogMessageInfo& rInfo)
    {
        this->m_eType = rInfo.m_eType;
        this->m_pWindow = rInfo.m_pWindow;
        this->m_pMenu = rInfo.m_pMenu;
        if (rInfo.m_pData)
        {
            std::unique_ptr<jsdialog::ActionDataMap> pData(
                new jsdialog::ActionDataMap(*rInfo.m_pData));
            this->m_pData = std::move(pData);
        }
    }

public:
    JSDialogMessageInfo(jsdialog::MessageType eType, VclPtr<vcl::Window> pWindow,
                        std::unique_ptr<jsdialog::ActionDataMap> pData)
        : m_eType(eType)
        , m_pWindow(std::move(pWindow))
        , m_pData(std::move(pData))
    {
    }

    JSDialogMessageInfo(jsdialog::MessageType eType, VclPtr<PopupMenu> pMenu,
                        std::unique_ptr<jsdialog::ActionDataMap> pData)
        : m_eType(eType)
        , m_pMenu(std::move(pMenu))
        , m_pData(std::move(pData))
    {
    }

    JSDialogMessageInfo(const JSDialogMessageInfo& rInfo) { copy(rInfo); }

    JSDialogMessageInfo& operator=(JSDialogMessageInfo aInfo)
    {
        if (this == &aInfo)
            return *this;

        copy(aInfo);
        return *this;
    }
};

class JSDialogNotifyIdle final : public Idle
{
    // used to send message
    VclPtr<vcl::Window> m_aNotifierWindow;
    // used to generate JSON
    VclPtr<vcl::Window> m_aContentWindow;
    OUString m_sTypeOfJSON;
    OString m_LastNotificationMessage;
    bool m_bForce;

    std::deque<JSDialogMessageInfo> m_aMessageQueue;
    std::mutex m_aQueueMutex;

public:
    JSDialogNotifyIdle(VclPtr<vcl::Window> aNotifierWindow, VclPtr<vcl::Window> aContentWindow,
                       const rtl::OUString& sTypeOfJSON);

    void Invoke() override;

    void clearQueue();
    void forceUpdate();
    template <class VclType>
    void sendMessage(const jsdialog::MessageType eType, const VclPtr<VclType>& pTarget,
                     std::unique_ptr<jsdialog::ActionDataMap> pData = nullptr);

private:
    void send(const OString& sMsg);
    OString generateFullUpdate() const;
    OString generateWidgetUpdate(const VclPtr<vcl::Window>& pWindow) const;
    OString generateCloseMessage() const;
    OString generateActionMessage(const VclPtr<vcl::Window>& pWindow,
                                  std::unique_ptr<jsdialog::ActionDataMap> pData) const;
    OString generatePopupMessage(const VclPtr<vcl::Window>& pWindow, const rtl::OUString& sParentId,
                                 const OUString& sCloseId) const;
    OString generateClosePopupMessage(const rtl::OUString& sWindowId) const;
    OString generateMenuMessage(const VclPtr<PopupMenu>& pMenu) const;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */