1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <dlg_DataEditor.hxx>
21 #include "DataBrowser.hxx"
22 #include <comphelper/stl_types.hxx>
24 #include <osl/diagnose.h>
25 #include <vcl/taskpanelist.hxx>
26 #include <svtools/miscopt.hxx>
28 #include <com/sun/star/awt/XWindow.hpp>
29 #include <com/sun/star/frame/XStorable.hpp>
31 using namespace ::com::sun::star
;
32 using ::com::sun::star::uno::Reference
;
37 DataEditor::DataEditor(weld::Window
* pParent
,
38 const Reference
< chart2::XChartDocument
> & xChartDoc
,
39 const Reference
< uno::XComponentContext
> & xContext
)
40 : GenericDialogController(pParent
, "modules/schart/ui/chartdatadialog.ui", "ChartDataDialog")
42 , m_xChartDoc(xChartDoc
)
43 , m_xContext(xContext
)
44 , m_xTbxData(m_xBuilder
->weld_toolbar("toolbar"))
45 , m_xCloseBtn(m_xBuilder
->weld_button("close"))
46 , m_xTable(m_xBuilder
->weld_container("datawindow"))
47 , m_xColumns(m_xBuilder
->weld_container("columns"))
48 , m_xColors(m_xBuilder
->weld_container("colorcolumns"))
49 , m_xTableCtrlParent(m_xTable
->CreateChildFrame())
50 , m_xBrwData(VclPtr
<DataBrowser
>::Create(m_xTableCtrlParent
, m_xColumns
.get(), m_xColors
.get()))
52 m_xCloseBtn
->connect_clicked(LINK(this, DataEditor
, CloseHdl
));
54 Size
aSize(m_xTable
->get_approximate_digit_width() * 75, m_xTable
->get_text_height() * 15);
55 m_xTable
->set_size_request(aSize
.Width(), aSize
.Height());
59 m_xTbxData
->connect_clicked(LINK(this, DataEditor
, ToolboxHdl
));
61 m_xBrwData
->SetCursorMovedHdl( LINK( this, DataEditor
, BrowserCursorMovedHdl
));
63 m_xBrwData
->SetDataFromModel( m_xChartDoc
, m_xContext
);
64 // m_xDialog->grab_focus();
65 // m_xBrwData->GrabFocus();
67 bool bReadOnly
= true;
68 Reference
< frame::XStorable
> xStor( m_xChartDoc
, uno::UNO_QUERY
);
70 bReadOnly
= xStor
->isReadonly();
71 SetReadOnly( bReadOnly
);
74 DataEditor::~DataEditor()
76 m_xBrwData
.disposeAndClear();
77 m_xTableCtrlParent
->dispose();
78 m_xTableCtrlParent
.clear();
81 // react on click (or keypress) on toolbar icon
82 IMPL_LINK(DataEditor
, ToolboxHdl
, const OString
&, rId
, void)
84 if (rId
== "InsertRow")
85 m_xBrwData
->InsertRow();
86 else if (rId
== "InsertColumn")
87 m_xBrwData
->InsertColumn();
88 else if (rId
== "InsertTextColumn")
89 m_xBrwData
->InsertTextColumn();
90 else if (rId
== "RemoveRow")
91 m_xBrwData
->RemoveRow();
92 else if (rId
== "RemoveColumn")
93 m_xBrwData
->RemoveColumn();
94 else if (rId
== "MoveLeftColumn")
95 m_xBrwData
->MoveLeftColumn();
96 else if (rId
== "MoveRightColumn")
97 m_xBrwData
->MoveRightColumn();
98 else if (rId
== "MoveUpRow")
99 m_xBrwData
->MoveUpRow();
100 else if (rId
== "MoveDownRow")
101 m_xBrwData
->MoveDownRow();
104 // refresh toolbar icons according to currently selected cell in browse box
105 IMPL_LINK_NOARG(DataEditor
, BrowserCursorMovedHdl
, DataBrowser
*, void)
110 bool bIsDataValid
= m_xBrwData
->IsEnableItem();
112 m_xTbxData
->set_item_sensitive("InsertRow", bIsDataValid
&& m_xBrwData
->MayInsertRow() );
113 m_xTbxData
->set_item_sensitive("InsertColumn", bIsDataValid
&& m_xBrwData
->MayInsertColumn() );
114 m_xTbxData
->set_item_sensitive("InsertTextColumn", bIsDataValid
&& m_xBrwData
->MayInsertColumn() );
115 m_xTbxData
->set_item_sensitive("RemoveRow", m_xBrwData
->MayDeleteRow() );
116 m_xTbxData
->set_item_sensitive("RemoveColumn", m_xBrwData
->MayDeleteColumn() );
118 m_xTbxData
->set_item_sensitive("MoveLeftColumn", bIsDataValid
&& m_xBrwData
->MayMoveLeftColumns() );
119 m_xTbxData
->set_item_sensitive("MoveRightColumn", bIsDataValid
&& m_xBrwData
->MayMoveRightColumns() );
120 m_xTbxData
->set_item_sensitive("MoveUpRow", bIsDataValid
&& m_xBrwData
->MayMoveDownRows() );
121 m_xTbxData
->set_item_sensitive("MoveDownRow", bIsDataValid
&& m_xBrwData
->MayMoveUpRows() );
124 // disable all modifying controls
125 void DataEditor::SetReadOnly( bool bReadOnly
)
127 m_bReadOnly
= bReadOnly
;
130 m_xTbxData
->set_item_sensitive("InsertRow", false);
131 m_xTbxData
->set_item_sensitive("InsertColumn", false);
132 m_xTbxData
->set_item_sensitive("InsertTextColumn", false);
133 m_xTbxData
->set_item_sensitive("RemoveRow", false);
134 m_xTbxData
->set_item_sensitive("RemoveColumn", false);
135 m_xTbxData
->set_item_sensitive("MoveLeftColumn", false);
136 m_xTbxData
->set_item_sensitive("MoveRightColumn", false);
137 m_xTbxData
->set_item_sensitive("MoveUpRow", false);
138 m_xTbxData
->set_item_sensitive("MoveDownRow", false);
141 m_xBrwData
->SetReadOnly( m_bReadOnly
);
144 IMPL_LINK_NOARG(DataEditor
, CloseHdl
, weld::Button
&, void)
146 bool bApplied
= ApplyChangesToModel();
148 m_xDialog
->response(RET_CLOSE
);
151 bool DataEditor::ApplyChangesToModel()
153 return m_xBrwData
->EndEditing();
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */