summaryrefslogtreecommitdiff
path: root/sc/source/ui/inc/xmlsourcedlg.hxx
blob: 3e9fc05f5a05a400141e5f4272523cd1e6f78e82 (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * 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/.
 */

#ifndef INCLUDED_SC_SOURCE_UI_INC_XMLSOURCEDLG_HXX
#define INCLUDED_SC_SOURCE_UI_INC_XMLSOURCEDLG_HXX

#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/layout.hxx>
#include <vcl/treelistbox.hxx>

#include "anyrefdg.hxx"
#include <orcusxml.hxx>

#include <set>
#include <memory>
#include <vector>

class ScDocument;
class ScRange;
class ScOrcusXMLContext;

struct CustomCompare
{
    weld::TreeView& mrLbTree;
    CustomCompare(weld::TreeView& rLbTree)
        : mrLbTree(rLbTree)
    {
    }
    bool operator()(const std::unique_ptr<weld::TreeIter>& lhs, const std::unique_ptr<weld::TreeIter>& rhs) const
    {
        return mrLbTree.iter_compare(*lhs, *rhs) == -1;
    }
};


class ScXMLSourceDlg : public ScAnyRefDlgController
{
    OUString maSrcPath;

    ScOrcusXMLTreeParam maXMLParam;
    std::unique_ptr<weld::TreeIter> mxCurRefEntry;
    std::unique_ptr<ScOrcusXMLContext> mpXMLContext;

    ScDocument* mpDoc;
    bool mbDlgLostFocus;

    formula::RefEdit* mpActiveEdit;
    std::unique_ptr<weld::Button> mxBtnSelectSource;
    std::unique_ptr<weld::Label> mxFtSourceFile;

    std::unique_ptr<weld::Container> mxMapGrid;

    std::unique_ptr<weld::TreeView> mxLbTree;
    std::unique_ptr<formula::RefEdit> mxRefEdit;
    std::unique_ptr<formula::RefButton> mxRefBtn;

    std::unique_ptr<weld::Button> mxBtnOk;
    std::unique_ptr<weld::Button> mxBtnCancel;

    CustomCompare maCustomCompare;

    std::set<std::unique_ptr<weld::TreeIter>, CustomCompare> maCellLinks;
    std::set<std::unique_ptr<weld::TreeIter>, CustomCompare> maRangeLinks;

public:
    ScXMLSourceDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent, ScDocument* pDoc);
    virtual ~ScXMLSourceDlg() override;

    virtual bool IsRefInputMode() const override;
    virtual void SetReference(const ScRange& rRange, ScDocument* pDoc) override;
    virtual void Deactivate() override;
    virtual void SetActive() override;
    virtual void Close() override;

private:

    void SelectSourceFile();
    void LoadSourceFileStructure(const OUString& rPath);
    void TreeItemSelected();
    void DefaultElementSelected(weld::TreeIter& rEntry);
    void RepeatElementSelected(weld::TreeIter& rEntry);
    void AttributeSelected(weld::TreeIter& rEntry);

    void SetNonLinkable();
    void SetSingleLinkable();
    void SetRangeLinkable();
    void SelectAllChildEntries(weld::TreeIter& rEntry);

    /**
     * Check if any of its parents is linked or repeated.  The passed entry is
     * not checked; its parent is the first one to be checked, then all its
     * parents get checked all the way to the root.
     */
    bool IsParentDirty(weld::TreeIter* pEntry) const;

    bool IsChildrenDirty(weld::TreeIter* pEntry) const;

    void OkPressed();
    void CancelPressed();
    void RefEditModified();

    DECL_LINK(BtnPressedHdl, weld::Button&, void);
    DECL_LINK(TreeItemSelectHdl, weld::TreeView&, void);
    DECL_LINK(RefModifiedHdl, formula::RefEdit&, void);
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */