summaryrefslogtreecommitdiff
path: root/vcl/inc/treeglue.hxx
blob: 05ebee523af7dd37dc7479891b3c13217e3e5d67 (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
/* -*- 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/svimpbox.hxx>
#include <vcl/svtabbx.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 : public SvHeaderTabListBox
{
public:
    LclHeaderTabListBox(vcl::Window* pParent, WinBits nWinStyle)
        : SvHeaderTabListBox(pParent, nWinStyle)
    {
    }

    virtual DragDropMode NotifyStartDrag(TransferDataContainer&, SvTreeListEntry*) override
    {
        return GetDragDropMode();
    }
};

class LclTabListBox : public SvTabListBox
{
    Link<SvTreeListBox*, void> m_aModelChangedHdl;
    Link<SvTreeListBox*, void> 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*, void>& 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(TransferDataContainer&, SvTreeListEntry*) override
    {
        return GetDragDropMode();
    }

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

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

    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);
    }

    virtual SvTreeListEntry* GetDropTarget(const Point& rPos) override
    {
        pTargetEntry = pImpl->GetEntry(rPos);

        // 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);
            }
        }

        return pTargetEntry;
    }

    virtual bool EditingEntry(SvTreeListEntry* pEntry, Selection&) 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: */