summaryrefslogtreecommitdiffstats
path: root/vcl/inc/treeglue.hxx
blob: 4cb120d81f7f51c1021a2906c107077e5bbfb47a (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
/* -*- 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/.
 */

#include <vcl/toolkit/svtabbx.hxx>
#include "svimpbox.hxx"

//the default NotifyStartDrag is weird to me, and defaults to enabling all
//possibilities when drag starts, while restricting it to some subset of
//the configured drag drop mode would make more sense to me, but I'm not
//going to change the baseclass

class LclHeaderTabListBox final : public SvHeaderTabListBox
{
private:
    Link<SvTreeListEntry*, bool> m_aEditingEntryHdl;
    Link<std::pair<SvTreeListEntry*, OUString>, bool> m_aEditedEntryHdl;

public:
    LclHeaderTabListBox(vcl::Window* pParent, WinBits nWinStyle)
        : SvHeaderTabListBox(pParent, nWinStyle)
    {
    }

    void SetEditingEntryHdl(const Link<SvTreeListEntry*, bool>& rLink)
    {
        m_aEditingEntryHdl = rLink;
    }

    void SetEditedEntryHdl(const Link<std::pair<SvTreeListEntry*, OUString>, bool>& rLink)
    {
        m_aEditedEntryHdl = rLink;
    }

    virtual DragDropMode NotifyStartDrag() override { return GetDragDropMode(); }

    virtual bool EditingEntry(SvTreeListEntry* pEntry) override
    {
        return m_aEditingEntryHdl.Call(pEntry);
    }

    virtual bool EditedEntry(SvTreeListEntry* pEntry, const OUString& rNewText) override
    {
        return m_aEditedEntryHdl.Call(std::pair<SvTreeListEntry*, OUString>(pEntry, rNewText));
    }
};

class LclTabListBox final : public SvTabListBox
{
    Link<SvTreeListBox*, void> m_aModelChangedHdl;
    Link<SvTreeListBox*, bool> m_aStartDragHdl;
    Link<SvTreeListBox*, void> m_aEndDragHdl;
    Link<SvTreeListEntry*, bool> m_aEditingEntryHdl;
    Link<std::pair<SvTreeListEntry*, OUString>, bool> m_aEditedEntryHdl;

public:
    LclTabListBox(vcl::Window* pParent, WinBits nWinStyle)
        : SvTabListBox(pParent, nWinStyle)
    {
    }

    void SetModelChangedHdl(const Link<SvTreeListBox*, void>& rLink) { m_aModelChangedHdl = rLink; }
    void SetStartDragHdl(const Link<SvTreeListBox*, bool>& rLink) { m_aStartDragHdl = rLink; }
    void SetEndDragHdl(const Link<SvTreeListBox*, void>& rLink) { m_aEndDragHdl = rLink; }
    void SetEditingEntryHdl(const Link<SvTreeListEntry*, bool>& rLink)
    {
        m_aEditingEntryHdl = rLink;
    }
    void SetEditedEntryHdl(const Link<std::pair<SvTreeListEntry*, OUString>, bool>& rLink)
    {
        m_aEditedEntryHdl = rLink;
    }

    virtual DragDropMode NotifyStartDrag() override { return GetDragDropMode(); }

    virtual void StartDrag(sal_Int8 nAction, const Point& rPosPixel) override
    {
        if (m_aStartDragHdl.Call(this))
            return;
        SvTabListBox::StartDrag(nAction, rPosPixel);
    }

    virtual void DragFinished(sal_Int8 nDropAction) override
    {
        SvTabListBox::DragFinished(nDropAction);
        m_aEndDragHdl.Call(this);
    }

    virtual void ModelHasCleared() override
    {
        SvTabListBox::ModelHasCleared();
        m_aModelChangedHdl.Call(this);
    }

    virtual void ModelHasInserted(SvTreeListEntry* pEntry) override
    {
        SvTabListBox::ModelHasInserted(pEntry);
        m_aModelChangedHdl.Call(this);
    }

    virtual void ModelHasInsertedTree(SvTreeListEntry* pEntry) override
    {
        SvTabListBox::ModelHasInsertedTree(pEntry);
        m_aModelChangedHdl.Call(this);
    }

    virtual void ModelHasMoved(SvTreeListEntry* pSource) override
    {
        SvTabListBox::ModelHasMoved(pSource);
        m_aModelChangedHdl.Call(this);
    }

    virtual void ModelHasRemoved(SvTreeListEntry* pEntry) override
    {
        SvTabListBox::ModelHasRemoved(pEntry);
        m_aModelChangedHdl.Call(this);
    }

    SvTreeListEntry* GetTargetAtPoint(const Point& rPos, bool bHighLightTarget)
    {
        SvTreeListEntry* pOldTargetEntry = pTargetEntry;
        pTargetEntry = PosOverBody(rPos) ? pImpl->GetEntry(rPos) : nullptr;
        if (pOldTargetEntry != pTargetEntry)
            ImplShowTargetEmphasis(pOldTargetEntry, false);

        // scroll
        if (rPos.Y() < 12)
        {
            ImplShowTargetEmphasis(pTargetEntry, false);
            ScrollOutputArea(+1);
        }
        else
        {
            Size aSize(pImpl->GetOutputSize());
            if (rPos.Y() > aSize.Height() - 12)
            {
                ImplShowTargetEmphasis(pTargetEntry, false);
                ScrollOutputArea(-1);
            }
        }

        if (pTargetEntry && bHighLightTarget)
            ImplShowTargetEmphasis(pTargetEntry, true);
        return pTargetEntry;
    }

    virtual SvTreeListEntry* GetDropTarget(const Point& rPos) override
    {
        return GetTargetAtPoint(rPos, true);
    }

    virtual bool EditingEntry(SvTreeListEntry* pEntry) override
    {
        return m_aEditingEntryHdl.Call(pEntry);
    }

    virtual bool EditedEntry(SvTreeListEntry* pEntry, const OUString& rNewText) override
    {
        return m_aEditedEntryHdl.Call(std::pair<SvTreeListEntry*, OUString>(pEntry, rNewText));
    }
};

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