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"
23 #include <sfx2/dispatch.hxx>
24 #include <vcl/taskpanelist.hxx>
25 #include <svtools/miscopt.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <svl/eitem.hxx>
28 #include <vcl/edit.hxx>
30 #include <com/sun/star/frame/XStorable.hpp>
31 #include <com/sun/star/chart2/XChartDocument.hpp>
33 using namespace ::com::sun::star
;
34 using ::com::sun::star::uno::Reference
;
39 DataEditor::DataEditor(vcl::Window
* pParent
,
40 const Reference
< chart2::XChartDocument
> & xChartDoc
,
41 const Reference
< uno::XComponentContext
> & xContext
)
42 : ModalDialog(pParent
, "ChartDataDialog",
43 "modules/schart/ui/chartdatadialog.ui")
45 , m_xChartDoc(xChartDoc
)
46 , m_xContext(xContext
)
48 m_xBrwData
.reset(VclPtr
<DataBrowser
>::Create(get
<vcl::Window
>("datawindow"), WB_BORDER
| WB_TABSTOP
, true /* bLiveUpdate */));
49 m_xBrwData
->set_hexpand(true);
50 m_xBrwData
->set_vexpand(true);
51 m_xBrwData
->set_expand(true);
52 Size
aSize(m_xBrwData
->LogicToPixel(Size(232, 121), MapMode(MapUnit::MapAppFont
)));
53 m_xBrwData
->set_width_request(aSize
.Width());
54 m_xBrwData
->set_height_request(aSize
.Height());
57 get(m_pTbxData
, "toolbar");
59 TBI_DATA_INSERT_ROW
= m_pTbxData
->GetItemId("InsertRow");
60 TBI_DATA_INSERT_COL
= m_pTbxData
->GetItemId("InsertColumn");
61 TBI_DATA_INSERT_TEXT_COL
= m_pTbxData
->GetItemId("InsertTextColumn");
62 TBI_DATA_DELETE_ROW
= m_pTbxData
->GetItemId("RemoveRow");
63 TBI_DATA_DELETE_COL
= m_pTbxData
->GetItemId("RemoveColumn");
64 TBI_DATA_MOVE_LEFT_COL
= m_pTbxData
->GetItemId("MoveLeftColumn");
65 TBI_DATA_MOVE_RIGHT_COL
= m_pTbxData
->GetItemId("MoveRightColumn");
66 TBI_DATA_MOVE_UP_ROW
= m_pTbxData
->GetItemId("MoveUpRow");
67 TBI_DATA_MOVE_DOWN_ROW
= m_pTbxData
->GetItemId("MoveDownRow");
69 m_pTbxData
->SetSelectHdl( LINK( this, DataEditor
, ToolboxHdl
));
71 m_xBrwData
->SetCursorMovedHdl( LINK( this, DataEditor
, BrowserCursorMovedHdl
));
73 m_xBrwData
->SetDataFromModel( m_xChartDoc
, m_xContext
);
75 m_xBrwData
->GrabFocus();
77 bool bReadOnly
= true;
78 Reference
< frame::XStorable
> xStor( m_xChartDoc
, uno::UNO_QUERY
);
80 bReadOnly
= xStor
->isReadonly();
81 SetReadOnly( bReadOnly
);
83 // change buttons to flat-look if set so by user
84 SvtMiscOptions aMiscOptions
;
85 const sal_Int16
nStyle( aMiscOptions
.GetToolboxStyle() );
87 aMiscOptions
.AddListenerLink( LINK( this, DataEditor
, MiscHdl
) );
88 m_pTbxData
->SetOutStyle( nStyle
);
90 // allow travelling to toolbar with F6
91 notifySystemWindow( this, m_pTbxData
, ::comphelper::mem_fun( & TaskPaneList::AddWindow
));
94 DataEditor::~DataEditor()
99 void DataEditor::dispose()
101 notifySystemWindow( this, m_pTbxData
, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow
));
103 SvtMiscOptions aMiscOptions
;
104 aMiscOptions
.RemoveListenerLink( LINK( this, DataEditor
, MiscHdl
) );
107 m_xBrwData
.disposeAndClear();
108 ModalDialog::dispose();
111 // react on click (or keypress) on toolbar icon
112 IMPL_LINK_NOARG(DataEditor
, ToolboxHdl
, ToolBox
*, void)
114 sal_uInt16 nId
= m_pTbxData
->GetCurItemId();
116 if (nId
== TBI_DATA_INSERT_ROW
)
117 m_xBrwData
->InsertRow();
118 else if (nId
== TBI_DATA_INSERT_COL
)
119 m_xBrwData
->InsertColumn();
120 else if (nId
== TBI_DATA_INSERT_TEXT_COL
)
121 m_xBrwData
->InsertTextColumn();
122 else if (nId
== TBI_DATA_DELETE_ROW
)
123 m_xBrwData
->RemoveRow();
124 else if (nId
== TBI_DATA_DELETE_COL
)
125 m_xBrwData
->RemoveColumn();
126 else if (nId
== TBI_DATA_MOVE_LEFT_COL
)
127 m_xBrwData
->MoveLeftColumn();
128 else if (nId
== TBI_DATA_MOVE_RIGHT_COL
)
129 m_xBrwData
->MoveRightColumn();
130 else if (nId
== TBI_DATA_MOVE_UP_ROW
)
131 m_xBrwData
->MoveUpRow();
132 else if (nId
== TBI_DATA_MOVE_DOWN_ROW
)
133 m_xBrwData
->MoveDownRow();
136 // refresh toolbar icons according to currently selected cell in browse box
137 IMPL_LINK_NOARG(DataEditor
, BrowserCursorMovedHdl
, DataBrowser
*, void)
142 bool bIsDataValid
= m_xBrwData
->IsEnableItem();
144 m_pTbxData
->EnableItem( TBI_DATA_INSERT_ROW
, bIsDataValid
&& m_xBrwData
->MayInsertRow() );
145 m_pTbxData
->EnableItem( TBI_DATA_INSERT_COL
, bIsDataValid
&& m_xBrwData
->MayInsertColumn() );
146 m_pTbxData
->EnableItem( TBI_DATA_INSERT_TEXT_COL
, bIsDataValid
&& m_xBrwData
->MayInsertColumn() );
147 m_pTbxData
->EnableItem( TBI_DATA_DELETE_ROW
, m_xBrwData
->MayDeleteRow() );
148 m_pTbxData
->EnableItem( TBI_DATA_DELETE_COL
, m_xBrwData
->MayDeleteColumn() );
150 m_pTbxData
->EnableItem( TBI_DATA_MOVE_LEFT_COL
, bIsDataValid
&& m_xBrwData
->MayMoveLeftColumns() );
151 m_pTbxData
->EnableItem( TBI_DATA_MOVE_RIGHT_COL
, bIsDataValid
&& m_xBrwData
->MayMoveRightColumns() );
152 m_pTbxData
->EnableItem( TBI_DATA_MOVE_DOWN_ROW
, bIsDataValid
&& m_xBrwData
->MayMoveDownRows() );
153 m_pTbxData
->EnableItem( TBI_DATA_MOVE_UP_ROW
, bIsDataValid
&& m_xBrwData
->MayMoveUpRows() );
156 // disable all modifying controls
157 void DataEditor::SetReadOnly( bool bReadOnly
)
159 m_bReadOnly
= bReadOnly
;
162 m_pTbxData
->EnableItem( TBI_DATA_INSERT_ROW
, false );
163 m_pTbxData
->EnableItem( TBI_DATA_INSERT_COL
, false );
164 m_pTbxData
->EnableItem( TBI_DATA_INSERT_TEXT_COL
, false );
165 m_pTbxData
->EnableItem( TBI_DATA_DELETE_ROW
, false );
166 m_pTbxData
->EnableItem( TBI_DATA_DELETE_COL
, false );
167 m_pTbxData
->EnableItem( TBI_DATA_MOVE_LEFT_COL
, false );
168 m_pTbxData
->EnableItem( TBI_DATA_MOVE_RIGHT_COL
, false );
169 m_pTbxData
->EnableItem( TBI_DATA_MOVE_UP_ROW
, false );
170 m_pTbxData
->EnableItem( TBI_DATA_MOVE_DOWN_ROW
, false );
173 m_xBrwData
->SetReadOnly( m_bReadOnly
);
176 IMPL_LINK_NOARG(DataEditor
, MiscHdl
, LinkParamNone
*, void)
178 SvtMiscOptions aMiscOptions
;
179 sal_Int16
nStyle( aMiscOptions
.GetToolboxStyle() );
181 m_pTbxData
->SetOutStyle( nStyle
);
184 bool DataEditor::Close()
186 if( ApplyChangesToModel() )
187 return ModalDialog::Close();
192 bool DataEditor::ApplyChangesToModel()
194 return m_xBrwData
->EndEditing();
197 // add/remove a window (the toolbar) to/from the global list, so that F6
198 // travels/no longer travels over this window. _rMemFunc may be
199 // TaskPaneList::AddWindow or TaskPaneList::RemoveWindow
200 void DataEditor::notifySystemWindow(
201 vcl::Window
const * pWindow
, vcl::Window
* pToRegister
,
202 const ::comphelper::mem_fun1_t
<TaskPaneList
, vcl::Window
*>& rMemFunc
)
204 OSL_ENSURE( pWindow
, "Window must not be null!" );
207 vcl::Window
* pParent
= pWindow
->GetParent();
208 while( pParent
&& ! pParent
->IsSystemWindow() )
210 pParent
= pParent
->GetParent();
212 if ( pParent
&& pParent
->IsSystemWindow())
214 SystemWindow
* pSystemWindow
= static_cast< SystemWindow
* >( pParent
);
215 rMemFunc( pSystemWindow
->GetTaskPaneList(), pToRegister
);
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */