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_CHART2_SOURCE_CONTROLLER_DIALOGS_DATABROWSER_HXX
21 #define INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_DATABROWSER_HXX
22 
23 #include <svtools/editbrowsebox.hxx>
24 #include <vcl/fmtfield.hxx>
25 #include <vcl/weld.hxx>
26 
27 #include <memory>
28 #include <vector>
29 
30 namespace com { namespace sun { namespace star {
31     namespace awt {
32         class XWindow;
33     }
34     namespace chart2 {
35         class XChartDocument;
36     }
37 }}}
38 
39 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
40 
41 class OutputDevice;
42 
43 namespace chart
44 {
45 
46 class DataBrowserModel;
47 class NumberFormatterWrapper;
48 
49 namespace impl
50 {
51 class SeriesHeader;
52 class SeriesHeaderEdit;
53 }
54 
55 class DataBrowser : public ::svt::EditBrowseBox
56 {
57 protected:
58     // EditBrowseBox overridables
59     virtual void PaintCell( OutputDevice& rDev, const tools::Rectangle& rRect, sal_uInt16 nColumnId ) const override;
60     virtual bool SeekRow( long nRow ) override;
61     virtual bool IsTabAllowed( bool bForward ) const override;
62     virtual ::svt::CellController* GetController( long nRow, sal_uInt16 nCol ) override;
63     virtual void InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol ) override;
64     virtual bool SaveModified() override;
65     virtual void CursorMoved() override;
66     // called whenever the control of the current cell has been modified
67     virtual void CellModified() override;
68     virtual void ColumnResized( sal_uInt16 nColId ) override;
69     virtual void EndScroll() override;
70     virtual void MouseButtonDown( const BrowserMouseEvent& rEvt ) override;
71 
72 public:
73     DataBrowser(const css::uno::Reference<css::awt::XWindow> &rParent,
74                 weld::Container* pColumns, weld::Container* pColors);
75 
76     virtual ~DataBrowser() override;
77     virtual void dispose() override;
78 
79     /** GetCellText returns the text at the given position
80         @param  nRow
81             the number of the row
82         @param  nColId
83             the ID of the column
84         @return
85             the text out of the cell
86     */
87     virtual OUString  GetCellText(long nRow, sal_uInt16 nColId) const override;
88 
89     /** returns the number in the given cell. If a cell is empty or contains a
90         string, the result will be Nan
91     */
92     double GetCellNumber( long nRow, sal_uInt16 nColumnId ) const;
93 
94     bool isDateTimeString( const OUString& aInputString, double& fOutDateTimeValue );
95 
96     // Window
97     virtual void Resize() override;
98 
99     void SetReadOnly( bool bNewState );
IsReadOnly() const100     bool IsReadOnly() const { return m_bIsReadOnly;}
101 
102     void SetDataFromModel( const css::uno::Reference< css::chart2::XChartDocument > & xChartDoc,
103                            const css::uno::Reference< css::uno::XComponentContext > & xContext );
104 
105     // predicates to determine what actions are possible at the current cursor
106     // position.  This depends on the implementation of the according mutators
107     // below.  (They are used for enabling toolbar icons)
108     bool MayInsertRow() const;
109     bool MayInsertColumn() const;
110     bool MayDeleteRow() const;
111     bool MayDeleteColumn() const;
112 
113     bool MayMoveUpRows() const;
114     bool MayMoveDownRows() const;
115     bool MayMoveRightColumns() const;
116     bool MayMoveLeftColumns() const;
117 
118     // mutators mutating data
119     void InsertRow();
120     void InsertColumn();
121     void InsertTextColumn();
122     void RemoveRow();
123     void RemoveColumn();
124 
125     using BrowseBox::RemoveColumn;
126     using BrowseBox::MouseButtonDown;
127 
128     void MoveUpRow();
129     void MoveDownRow();
130     void MoveLeftColumn();
131     void MoveRightColumn();
132 
133     void SetCursorMovedHdl( const Link<DataBrowser*,void>& rLink );
134 
135     /// confirms all pending changes to be ready to be closed
136     bool EndEditing();
137 
138     bool CellContainsNumbers( sal_uInt16 nCol ) const;
139 
140     sal_uInt32 GetNumberFormatKey( sal_uInt16 nCol ) const;
141 
IsEnableItem() const142     bool IsEnableItem() const { return m_bDataValid;}
143     bool IsDataValid() const;
144     void ShowWarningBox();
145     bool ShowQueryBox();
146 
147     void RenewSeriesHeaders();
148 
149 private:
150     css::uno::Reference< css::chart2::XChartDocument > m_xChartDoc;
151     std::unique_ptr< DataBrowserModel > m_apDataBrowserModel;
152 
153     typedef std::vector< std::shared_ptr< impl::SeriesHeader > > tSeriesHeaderContainer;
154     tSeriesHeaderContainer m_aSeriesHeaders;
155 
156     std::shared_ptr< NumberFormatterWrapper >  m_spNumberFormatterWrapper;
157 
158     /// the row that is currently painted
159     long                m_nSeekRow;
160     bool                m_bIsReadOnly;
161     bool                m_bDataValid;
162 
163     VclPtr<FormattedField>      m_aNumberEditField;
164     VclPtr<Edit>                m_aTextEditField;
165     weld::Container*            m_pColumnsWin;
166     weld::Container*            m_pColorsWin;
167 
168     /// note: m_aNumberEditField must precede this member!
169     ::svt::CellControllerRef    m_rNumberEditController;
170     /// note: m_aTextEditField must precede this member!
171     ::svt::CellControllerRef    m_rTextEditController;
172 
173     Link<DataBrowser*,void>     m_aCursorMovedHdlLink;
174 
175     void clearHeaders();
176     void RenewTable();
177     void ImplAdjustHeaderControls();
178 
179     OUString GetColString( sal_Int32 nColumnId ) const;
180 
181     DECL_LINK( SeriesHeaderGotFocus, impl::SeriesHeaderEdit&, void );
182     DECL_LINK( SeriesHeaderChanged,  impl::SeriesHeaderEdit&, void );
183 
184     DataBrowser( const DataBrowser & ) = delete;
185 };
186 
187 } // namespace chart
188 
189 #endif // INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_DATABROWSER_HXX
190 
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
192