summaryrefslogtreecommitdiff
path: root/sw/source/uibase/sidebar/CommentsPanel.hxx
blob: 348388ab21e1b18dc04990526d99b4876d8a7c3f (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#pragma once

#include <vcl/event.hxx>
#include <annotationmark.hxx>
#include <svtools/ctrlbox.hxx>
#include <rtl/ustring.hxx>
#include <memory>

#include <sfx2/sidebar/PanelLayout.hxx>
#include <sfx2/sidebar/ControllerItem.hxx>
#include <AnnotationWin.hxx>
#include <svl/poolitem.hxx>
#include <tools/link.hxx>
#include <vcl/weld.hxx>
#include <PostItMgr.hxx>
#include <postithelper.hxx>
#include <view.hxx>
#include <tools/date.hxx>
#include <tools/datetime.hxx>
#include <tools/time.hxx>
#include <svtools/ctrlbox.hxx>

class SwWrtShell;
class SwView;
class SwPostItField;
class SwFormatField;
class SwAnnotationWin;
class SfxBroadcaster;
class SwPostItMgr;
class SwSidebarItem;

namespace sw::sidebar
{
class CommentsPanel;
class Comment final
{
    friend class CommentsPanel;

private:
    std::unique_ptr<weld::Builder> mxBuilder;
    std::unique_ptr<weld::Container> mxContainer;
    std::unique_ptr<weld::Expander> mxExpander;
    std::unique_ptr<weld::Label> mxAuthor;
    std::unique_ptr<weld::Label> mxDate;
    std::unique_ptr<weld::Label> mxTime;
    std::unique_ptr<weld::Button> mxReply;
    std::unique_ptr<weld::CheckButton> mxResolve;
    std::unique_ptr<weld::TextView> mxTextView;

    sw::sidebar::CommentsPanel& mrCommentsPanel;
    OUString msText;
    OUString msAuthor;
    OUString msInitials; //Initials of Author.
    OUString msName; //Name of the comment
    Date maDate;
    tools::Time maTime;

    void makeEditable() { mxTextView->set_editable(true); }

public:
    Comment(weld::Container* pParent, CommentsPanel& rCommentsPanel);
    ~Comment();
    weld::Widget* get_widget() const { return mxContainer.get(); }
    weld::TextView* getTextView() const { return mxTextView.get(); }

    DECL_LINK(ReplyClicked, weld::Button&, void);
    DECL_LINK(ResolveClicked, weld::Toggleable&, void);
    DECL_LINK(OnFocusOut, weld::Widget&, void);
    DECL_LINK(ContextMenuHdl, const MouseEvent&, bool);

    bool mbResolved;

    void InitControls(const SwPostItField* pPostItField);
    void SetCommentText(OUString sText) { msText = sText; }
    OUString GetAuthor() { return msAuthor; }
    Date GetDate() { return maDate; }
};

class Thread final
{
    friend class CommentsPanel;

private:
    std::unique_ptr<weld::Builder> mxBuilder;
    std::unique_ptr<weld::Container> mxContainer;
    std::unique_ptr<weld::Box> mxCommentBox;
    std::unique_ptr<weld::Label> mxText;

public:
    Thread(weld::Container* pParent);
    ~Thread();
    weld::Widget* get_widget() const { return mxContainer.get(); }
    weld::Box* getCommentBoxWidget() const { return mxCommentBox.get(); }

    sal_uInt16 mnComments = 0;
};

class CommentsPanel : public PanelLayout,
                      public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface,
                      public SfxListener
{
public:
    static std::unique_ptr<PanelLayout> Create(weld::Widget* pParent);

    virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState,
                                  const SfxPoolItem* pState) override;

    virtual void GetControlState(const sal_uInt16 /*nSId*/,
                                 boost::property_tree::ptree& /*rState*/) override{};

    CommentsPanel(weld::Widget* pParent);
    virtual ~CommentsPanel() override;

    void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;

    void EditComment(Comment* pComment);
    void ToggleResolved(Comment* pComment);
    void ReplyComment(Comment* pComment);
    void DeleteComment(Comment* pComment);
    void DeleteThread(Comment* pComment);
    void ResolveThread(Comment* pComment);

    DECL_LINK(FilterByAuthor, weld::ComboBox&, void);
    DECL_LINK(FilterByDate, SvtCalendarBox&, void);
    DECL_LINK(ResetDate, weld::Button&, void);
    DECL_LINK(ShowTimeHdl, weld::Toggleable&, void);
    DECL_LINK(ShowResolvedHdl, weld::Toggleable&, void);
    DECL_LINK(SortHdl, weld::Toggleable&, void);

    // utility functions
    static OUString FormatDate(Date& rDate);
    static OUString FormatTime(tools::Time& rTime);

    weld::Toggleable& getShowResolved() { return *mxShowResolved; }

private:
    SwDoc* mpDoc;
    SwPostItMgr* mpPostItMgr;

    std::unordered_map<sal_uInt32, std::unique_ptr<Thread>> mpThreadsMap;
    std::unordered_map<sal_uInt32, std::unique_ptr<Comment>> mpCommentsMap;
    std::unordered_set<OUString> mpAuthorSet;

    std::unique_ptr<weld::ComboBox> mxFilterAuthor;
    std::unique_ptr<SvtCalendarBox> mxFilterDate;
    std::unique_ptr<weld::Button> mxResetDate;
    std::unique_ptr<weld::CheckButton> mxShowTime;
    std::unique_ptr<weld::CheckButton> mxShowResolved;
    std::unique_ptr<weld::CheckButton> mxShowReference;
    std::unique_ptr<weld::RadioButton> mxSortbyPosition;
    std::unique_ptr<weld::RadioButton> mxSortbyTime;
    std::unique_ptr<weld::Box> mxThreadsContainer;

    sal_uInt16 mnThreads = 0;
    bool mbResetDate = false;

    // utility functions
    sw::annotation::SwAnnotationWin* getRootCommentWin(const SwFormatField* pField);
    static sal_uInt32 getPostItId(sw::annotation::SwAnnotationWin* pAnnotationWin);
    sw::annotation::SwAnnotationWin* getAnnotationWin(Comment* pComment);
    static bool comp_dateTime(SwFormatField* a, SwFormatField* b);
    static SwPosition getAnchorPosition(SwFormatField* pField);
    static bool comp_position(SwFormatField* a, SwFormatField* b);

    // event handlers (To sync with AnnotationWin)
    void populateComments();
    void addComment(const SwFormatField* pField);
    void deleteComment(sal_uInt32 nId);
    void setResolvedStatus(sw::annotation::SwAnnotationWin* pAnnotationWin);
    static void editComment(SwPostItField* pPostItField, Comment* pComment);
    static OUString getReferenceText(SwTextNode* pTextNode, sw::mark::AnnotationMark* pMark);
    void setReferenceText(sal_uInt32 nRootId);

    void populateAuthorComboBox();
};

} //end of namespace sw::sidebar