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