| 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 |
#include <dlg_DataEditor.hxx> |
| 21 |
#include "DataBrowser.hxx" |
| 22 |
#include <ChartModel.hxx> |
| 23 |
|
| 24 |
#include <com/sun/star/awt/XWindow.hpp> |
| 25 |
#include <utility> |
| 26 |
|
| 27 |
using namespace ::com::sun::star; |
| 28 |
using ::com::sun::star::uno::Reference; |
| 29 |
|
| 30 |
namespace chart |
| 31 |
{ |
| 32 |
|
| 33 |
DataEditor::DataEditor(weld::Window* pParent, |
| 34 |
rtl::Reference<::chart::ChartModel> xChartDoc, |
| 35 |
const Reference< uno::XComponentContext > & xContext) |
| 36 |
: GenericDialogController(pParent, u"modules/schart/ui/chartdatadialog.ui"_ustr, u"ChartDataDialog"_ustr) |
| 37 |
, m_bReadOnly(false) |
| 38 |
, m_xChartDoc(std::move(xChartDoc)) |
| 39 |
, m_xContext(xContext) |
| 40 |
, m_xTbxData(m_xBuilder->weld_toolbar(u"toolbar"_ustr)) |
| 41 |
, m_xCloseBtn(m_xBuilder->weld_button(u"close"_ustr)) |
| 42 |
, m_xTable(m_xBuilder->weld_container(u"datawindow"_ustr)) |
| 43 |
, m_xColumns(m_xBuilder->weld_box(u"columns"_ustr)) |
| 44 |
, m_xColors(m_xBuilder->weld_box(u"colorcolumns"_ustr)) |
| 45 |
, m_xTableCtrlParent(m_xTable->CreateChildFrame()) |
| 46 |
, m_xBrwData(VclPtr<DataBrowser>::Create(m_xTableCtrlParent, m_xColumns.get(), m_xColors.get())) |
| 47 |
{ |
| 48 |
m_xCloseBtn->connect_clicked(LINK(this, DataEditor, CloseHdl)); |
| 49 |
|
| 50 |
Size aSize(m_xTable->get_approximate_digit_width() * 75, m_xTable->get_text_height() * 15); |
| 51 |
m_xTable->set_size_request(aSize.Width(), aSize.Height()); |
| 52 |
|
| 53 |
m_xBrwData->Show(); |
| 54 |
|
| 55 |
m_xTbxData->connect_clicked(LINK(this, DataEditor, ToolboxHdl)); |
| 56 |
|
| 57 |
m_xBrwData->SetCursorMovedHdl( LINK( this, DataEditor, BrowserCursorMovedHdl )); |
| 58 |
|
| 59 |
m_xBrwData->SetDataFromModel( m_xChartDoc ); |
| 60 |
m_xBrwData->GrabFocus(); |
| 61 |
|
| 62 |
bool bReadOnly = true; |
| 63 |
if( m_xChartDoc.is()) |
| 64 |
bReadOnly = m_xChartDoc->isReadonly(); |
| 65 |
SetReadOnly( bReadOnly ); |
| 66 |
} |
| 67 |
|
| 68 |
DataEditor::~DataEditor() |
| 69 |
{ |
| 70 |
m_xBrwData.disposeAndClear(); |
| 71 |
m_xTableCtrlParent->dispose(); |
| 72 |
m_xTableCtrlParent.clear(); |
| 73 |
} |
| 74 |
|
| 75 |
// react on click (or keypress) on toolbar icon |
| 76 |
IMPL_LINK(DataEditor, ToolboxHdl, const OUString&, rId, void) |
| 77 |
{ |
| 78 |
if (rId == "InsertRow") |
| 79 |
m_xBrwData->InsertRow(); |
| 80 |
else if (rId == "InsertColumn") |
| 81 |
m_xBrwData->InsertColumn(); |
| 82 |
else if (rId == "InsertTextColumn") |
| 83 |
m_xBrwData->InsertTextColumn(); |
| 84 |
else if (rId == "RemoveRow") |
| 85 |
m_xBrwData->RemoveRow(); |
| 86 |
else if (rId == "RemoveColumn") |
| 87 |
m_xBrwData->RemoveColumn(); |
| 88 |
else if (rId == "MoveLeftColumn") |
| 89 |
m_xBrwData->MoveLeftColumn(); |
| 90 |
else if (rId == "MoveRightColumn") |
| 91 |
m_xBrwData->MoveRightColumn(); |
| 92 |
else if (rId == "MoveUpRow") |
| 93 |
m_xBrwData->MoveUpRow(); |
| 94 |
else if (rId == "MoveDownRow") |
| 95 |
m_xBrwData->MoveDownRow(); |
| 96 |
} |
| 97 |
|
| 98 |
// refresh toolbar icons according to currently selected cell in browse box |
| 99 |
IMPL_LINK_NOARG(DataEditor, BrowserCursorMovedHdl, DataBrowser*, void) |
| 100 |
{ |
| 101 |
if( m_bReadOnly ) |
| 102 |
return; |
| 103 |
|
| 104 |
bool bIsDataValid = m_xBrwData->IsEnableItem(); |
| 105 |
|
| 106 |
m_xTbxData->set_item_sensitive(u"InsertRow"_ustr, bIsDataValid && m_xBrwData->MayInsertRow() ); |
| 107 |
m_xTbxData->set_item_sensitive(u"InsertColumn"_ustr, bIsDataValid && m_xBrwData->MayInsertColumn() ); |
| 108 |
m_xTbxData->set_item_sensitive(u"InsertTextColumn"_ustr, bIsDataValid && m_xBrwData->MayInsertColumn() ); |
| 109 |
m_xTbxData->set_item_sensitive(u"RemoveRow"_ustr, m_xBrwData->MayDeleteRow() ); |
| 110 |
m_xTbxData->set_item_sensitive(u"RemoveColumn"_ustr, m_xBrwData->MayDeleteColumn() ); |
| 111 |
|
| 112 |
m_xTbxData->set_item_sensitive(u"MoveLeftColumn"_ustr, bIsDataValid && m_xBrwData->MayMoveLeftColumns() ); |
| 113 |
m_xTbxData->set_item_sensitive(u"MoveRightColumn"_ustr, bIsDataValid && m_xBrwData->MayMoveRightColumns() ); |
| 114 |
m_xTbxData->set_item_sensitive(u"MoveDownRow"_ustr, bIsDataValid && m_xBrwData->MayMoveDownRows() ); |
| 115 |
m_xTbxData->set_item_sensitive(u"MoveUpRow"_ustr, bIsDataValid && m_xBrwData->MayMoveUpRows() ); |
| 116 |
} |
| 117 |
|
| 118 |
// disable all modifying controls |
| 119 |
void DataEditor::SetReadOnly( bool bReadOnly ) |
| 120 |
{ |
| 121 |
m_bReadOnly = bReadOnly; |
| 122 |
if( m_bReadOnly ) |
| 123 |
{ |
| 124 |
m_xTbxData->set_item_sensitive(u"InsertRow"_ustr, false); |
| 125 |
m_xTbxData->set_item_sensitive(u"InsertColumn"_ustr, false); |
| 126 |
m_xTbxData->set_item_sensitive(u"InsertTextColumn"_ustr, false); |
| 127 |
m_xTbxData->set_item_sensitive(u"RemoveRow"_ustr, false); |
| 128 |
m_xTbxData->set_item_sensitive(u"RemoveColumn"_ustr, false); |
| 129 |
m_xTbxData->set_item_sensitive(u"MoveLeftColumn"_ustr, false); |
| 130 |
m_xTbxData->set_item_sensitive(u"MoveRightColumn"_ustr, false); |
| 131 |
m_xTbxData->set_item_sensitive(u"MoveUpRow"_ustr, false); |
| 132 |
m_xTbxData->set_item_sensitive(u"MoveDownRow"_ustr, false); |
| 133 |
} |
| 134 |
|
| 135 |
m_xBrwData->SetReadOnly( m_bReadOnly ); |
| 136 |
} |
| 137 |
|
| 138 |
IMPL_LINK_NOARG(DataEditor, CloseHdl, weld::Button&, void) |
| 139 |
{ |
| 140 |
bool bApplied = m_xBrwData->EndEditing(); // apply changes to model |
| 141 |
if (bApplied) |
| 142 |
m_xDialog->response(RET_CLOSE); |
| 143 |
} |
| 144 |
|
| 145 |
} // namespace chart |
| 146 |
|
| 147 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |