1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_STARMATH_INC_ELEMENTSDOCKINGWINDOW_HXX
21 #define INCLUDED_STARMATH_INC_ELEMENTSDOCKINGWINDOW_HXX
22 
23 #include <sfx2/dockwin.hxx>
24 #include <vcl/scrbar.hxx>
25 
26 #include "format.hxx"
27 #include <memory>
28 #include <tuple>
29 
30 #include "AccessibleSmElementsControl.hxx"
31 
32 class SmDocShell;
33 class SmNode;
34 class SmParser;
35 
36 class SmElement
37 {
38     std::unique_ptr<SmNode> mpNode;
39     OUString const          maText;
40     OUString const          maHelpText;
41 
42 public:
43     Point mBoxLocation;
44     Size  mBoxSize;
45 
46     SmElement(std::unique_ptr<SmNode>&& pNode, const OUString& aText, const OUString& aHelpText);
47     virtual ~SmElement();
48 
49     const std::unique_ptr<SmNode>& getNode() const;
getText() const50     const OUString& getText() const { return maText; }
getHelpText() const51     const OUString& getHelpText() const { return maHelpText; }
52 
isSeparator() const53     virtual bool isSeparator() const { return false; }
54 };
55 
56 class SmElementSeparator : public SmElement
57 {
58 public:
59     SmElementSeparator();
60 
isSeparator() const61     bool isSeparator() const override { return true; }
62 };
63 
64 typedef std::pair<const char*, const char*> SmElementDescr;
65 
66 class SmElementsControl : public Control
67 {
68     friend class ElementSelectorUIObject;
69     friend class ElementUIObject;
70 
71     static const SmElementDescr m_aUnaryBinaryOperatorsList[];
72     static const SmElementDescr m_aRelationsList[];
73     static const SmElementDescr m_aSetOperationsList[];
74     static const SmElementDescr m_aFunctionsList[];
75     static const SmElementDescr m_aOperatorsList[];
76     static const SmElementDescr m_aAttributesList[];
77     static const SmElementDescr m_aBracketsList[];
78     static const SmElementDescr m_aFormatsList[];
79     static const SmElementDescr m_aOthersList[];
80     static const SmElementDescr m_aExamplesList[];
81     static const std::tuple<const char*, const SmElementDescr*, size_t> m_aCategories[];
82     static const size_t m_aCategoriesSize;
83 
84     virtual void ApplySettings(vcl::RenderContext&) override;
85     virtual void DataChanged(const DataChangedEvent&) override;
86     virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
87     virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
88     virtual void MouseMove(const MouseEvent& rMEvt) override;
89     virtual void RequestHelp(const HelpEvent& rHEvt) override;
90     virtual void Resize() override;
91     virtual void GetFocus() override;
92     virtual void LoseFocus() override;
93     virtual void KeyInput(const KeyEvent& rKEvt) override;
94     css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
95 
96     SmDocShell*   mpDocShell;
97     SmFormat      maFormat;
98     OString       msCurrentSetId;
99     sal_uInt16    m_nCurrentElement;
100     sal_uInt16    m_nCurrentRolloverElement;
101     sal_uInt16 m_nCurrentOffset;
102     Link<SmElement&,void> maSelectHdlLink;
103 
104     std::vector< std::unique_ptr<SmElement> > maElementList;
105     Size          maMaxElementDimensions;
106     bool          mbVerticalMode;
107     VclPtr< ScrollBar > mxScroll;
108     bool m_bFirstPaintAfterLayout;
109     rtl::Reference<AccessibleSmElementsControl> m_xAccessible;
110 
111     void addElement(SmParser &rParser, const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText);
112     void addElements(const SmElementDescr aElementsArray[], sal_uInt16 size);
113     SmElement* current() const;
114     void setCurrentElement(sal_uInt16);
hasRollover() const115     bool hasRollover() const { return m_nCurrentRolloverElement != SAL_MAX_UINT16; }
116 
117     void stepFocus(const bool bBackward);
118     void pageFocus(const bool bBackward);
119     // common code of page and step focus
120     inline void scrollToElement(const bool, const SmElement*);
121     inline sal_uInt16 nextElement(const bool, const sal_uInt16, const sal_uInt16);
122 
123     void build();
124 
125     //if pContext is not NULL, then draw, otherwise
126     //just layout
127     void LayoutOrPaintContents(vcl::RenderContext *pContext = nullptr);
128 
129 public:
130     explicit SmElementsControl(vcl::Window *pParent);
131     virtual ~SmElementsControl() override;
132     virtual void dispose() override;
133 
categories()134     static const auto& categories() { return m_aCategories; }
categoriesSize()135     static size_t categoriesSize() { return m_aCategoriesSize; }
elementSetId() const136     const OString& elementSetId() const { return msCurrentSetId; }
137     void setElementSetId(const char* pSetId);
138 
139     void setVerticalMode(bool bVertical);
140 
141     sal_uInt16 itemCount() const;
142     sal_uInt16 itemHighlighted() const;
143     sal_uInt16 itemAtPos(const Point& rPos) const;
144     tools::Rectangle itemPosRect(sal_uInt16) const;
145     bool itemIsSeparator(sal_uInt16) const;
146     bool itemIsVisible(sal_uInt16) const;
147     OUString itemName(sal_uInt16) const;
148     bool itemTrigger(sal_uInt16);
149     void setItemHighlighted(sal_uInt16);
itemOffset() const150     sal_uInt16 itemOffset() const { return m_nCurrentOffset; }
151     css::uno::Reference<css::accessibility::XAccessible> scrollbarAccessible() const;
152 
153     Size GetOptimalSize() const override;
154 
155     DECL_LINK( ScrollHdl, ScrollBar*, void );
156     void DoScroll(long nDelta);
157 
SetSelectHdl(const Link<SmElement &,void> & rLink)158     void SetSelectHdl(const Link<SmElement&,void>& rLink) { maSelectHdlLink = rLink; }
159 
160     virtual FactoryFunction GetUITestFactory() const override;
161 };
162 
163 class SmElementsDockingWindow : public SfxDockingWindow
164 {
165     VclPtr<SmElementsControl>  mpElementsControl;
166     VclPtr<ListBox>            mpElementListBox;
167 
168     virtual void Resize() override;
169     SmViewShell* GetView();
170 
171     DECL_LINK(SelectClickHandler, SmElement&, void);
172     DECL_LINK(ElementSelectedHandle, ListBox&, void);
173 
174 public:
175 
176     SmElementsDockingWindow( SfxBindings* pBindings,
177                              SfxChildWindow* pChildWindow,
178                              vcl::Window* pParent );
179     virtual ~SmElementsDockingWindow() override;
180     virtual void dispose() override;
181 
182     virtual void EndDocking( const tools::Rectangle& rReactangle, bool bFloatMode) override;
183     virtual void ToggleFloatingMode() override;
184 };
185 
186 class SmElementsDockingWindowWrapper final : public SfxChildWindow
187 {
188     SFX_DECL_CHILDWINDOW_WITHID(SmElementsDockingWindowWrapper);
189 
190     SmElementsDockingWindowWrapper( vcl::Window* pParentWindow,
191                                     sal_uInt16 nId,
192                                     SfxBindings* pBindings,
193                                     SfxChildWinInfo* pInfo );
194     virtual ~SmElementsDockingWindowWrapper() override;
195 };
196 
197 #endif // INCLUDED_STARMATH_INC_ELEMENTSDOCKINGWINDOW_HXX
198 
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
200