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 "Strings.hrc"
22 #include "DataBrowser.hxx"
25 #include <sfx2/dispatch.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <vcl/taskpanelist.hxx>
28 #include <svtools/miscopt.hxx>
29 #include <unotools/pathoptions.hxx>
30 #include <svl/eitem.hxx>
31 #include <vcl/edit.hxx>
33 #include <com/sun/star/frame/XStorable.hpp>
34 #include <com/sun/star/chart2/XChartDocument.hpp>
36 using namespace ::com::sun::star
;
37 using ::com::sun::star::uno::Reference
;
42 DataEditor::DataEditor(vcl::Window
* pParent
,
43 const Reference
< chart2::XChartDocument
> & xChartDoc
,
44 const Reference
< uno::XComponentContext
> & xContext
)
45 : ModalDialog(pParent
, "ChartDataDialog",
46 "modules/schart/ui/chartdatadialog.ui")
48 , m_xChartDoc(xChartDoc
)
49 , m_xContext(xContext
)
51 m_xBrwData
.reset(VclPtr
<DataBrowser
>::Create(get
<vcl::Window
>("datawindow"), WB_BORDER
| WB_TABSTOP
, true /* bLiveUpdate */));
52 m_xBrwData
->set_hexpand(true);
53 m_xBrwData
->set_vexpand(true);
54 m_xBrwData
->set_expand(true);
55 Size
aSize(m_xBrwData
->LogicToPixel(Size(232, 121), MAP_APPFONT
));
56 m_xBrwData
->set_width_request(aSize
.Width());
57 m_xBrwData
->set_height_request(aSize
.Height());
60 get(m_pTbxData
, "toolbar");
62 TBI_DATA_INSERT_ROW
= m_pTbxData
->GetItemId("InsertRow");
63 TBI_DATA_INSERT_COL
= m_pTbxData
->GetItemId("InsertColumn");
64 TBI_DATA_INSERT_TEXT_COL
= m_pTbxData
->GetItemId("InsertTextColumn");
65 TBI_DATA_DELETE_ROW
= m_pTbxData
->GetItemId("RemoveRow");
66 TBI_DATA_DELETE_COL
= m_pTbxData
->GetItemId("RemoveColumn");
67 TBI_DATA_SWAP_COL
= m_pTbxData
->GetItemId("SwapColumn");
68 TBI_DATA_SWAP_ROW
= m_pTbxData
->GetItemId("SwapRow");
70 m_pTbxData
->SetSelectHdl( LINK( this, DataEditor
, ToolboxHdl
));
72 m_xBrwData
->SetCursorMovedHdl( LINK( this, DataEditor
, BrowserCursorMovedHdl
));
73 m_xBrwData
->SetCellModifiedHdl( LINK( this, DataEditor
, CellModified
));
77 m_xBrwData
->GrabFocus();
79 bool bReadOnly
= true;
80 Reference
< frame::XStorable
> xStor( m_xChartDoc
, uno::UNO_QUERY
);
82 bReadOnly
= xStor
->isReadonly();
83 SetReadOnly( bReadOnly
);
85 // change buttons to flat-look if set so by user
86 SvtMiscOptions aMiscOptions
;
87 const sal_Int16
nStyle( aMiscOptions
.GetToolboxStyle() );
89 aMiscOptions
.AddListenerLink( LINK( this, DataEditor
, MiscHdl
) );
90 m_pTbxData
->SetOutStyle( nStyle
);
92 // allow travelling to toolbar with F6
93 notifySystemWindow( this, m_pTbxData
, ::comphelper::mem_fun( & TaskPaneList::AddWindow
));
96 DataEditor::~DataEditor()
101 void DataEditor::dispose()
103 notifySystemWindow( this, m_pTbxData
, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow
));
105 SvtMiscOptions aMiscOptions
;
106 aMiscOptions
.RemoveListenerLink( LINK( this, DataEditor
, MiscHdl
) );
108 OSL_TRACE( "DataEditor: DTOR" );
110 m_xBrwData
.disposeAndClear();
111 ModalDialog::dispose();
114 // react on click (or keypress) on toolbar icon
115 IMPL_LINK_NOARG_TYPED(DataEditor
, ToolboxHdl
, ToolBox
*, void)
117 sal_uInt16 nId
= m_pTbxData
->GetCurItemId();
119 if (nId
== TBI_DATA_INSERT_ROW
)
120 m_xBrwData
->InsertRow();
121 else if (nId
== TBI_DATA_INSERT_COL
)
122 m_xBrwData
->InsertColumn();
123 else if (nId
== TBI_DATA_INSERT_TEXT_COL
)
124 m_xBrwData
->InsertTextColumn();
125 else if (nId
== TBI_DATA_DELETE_ROW
)
126 m_xBrwData
->RemoveRow();
127 else if (nId
== TBI_DATA_DELETE_COL
)
128 m_xBrwData
->RemoveColumn();
129 else if (nId
== TBI_DATA_SWAP_COL
)
130 m_xBrwData
->SwapColumn();
131 else if (nId
== TBI_DATA_SWAP_ROW
)
132 m_xBrwData
->SwapRow();
135 // refresh toolbar icons according to currently selected cell in brwose box
136 IMPL_LINK_NOARG(DataEditor
, BrowserCursorMovedHdl
)
141 bool bIsDataValid
= m_xBrwData
->IsEnableItem();
143 m_pTbxData
->EnableItem( TBI_DATA_INSERT_ROW
, bIsDataValid
&& m_xBrwData
->MayInsertRow() );
144 m_pTbxData
->EnableItem( TBI_DATA_INSERT_COL
, bIsDataValid
&& m_xBrwData
->MayInsertColumn() );
145 m_pTbxData
->EnableItem( TBI_DATA_INSERT_TEXT_COL
, bIsDataValid
&& m_xBrwData
->MayInsertColumn() );
146 m_pTbxData
->EnableItem( TBI_DATA_DELETE_ROW
, m_xBrwData
->MayDeleteRow() );
147 m_pTbxData
->EnableItem( TBI_DATA_DELETE_COL
, m_xBrwData
->MayDeleteColumn() );
149 m_pTbxData
->EnableItem( TBI_DATA_SWAP_COL
, bIsDataValid
&& m_xBrwData
->MaySwapColumns() );
150 m_pTbxData
->EnableItem( TBI_DATA_SWAP_ROW
, bIsDataValid
&& m_xBrwData
->MaySwapRows() );
155 // disable all modifying controls
156 void DataEditor::SetReadOnly( bool bReadOnly
)
158 m_bReadOnly
= bReadOnly
;
161 m_pTbxData
->EnableItem( TBI_DATA_INSERT_ROW
, false );
162 m_pTbxData
->EnableItem( TBI_DATA_INSERT_COL
, false );
163 m_pTbxData
->EnableItem( TBI_DATA_INSERT_TEXT_COL
, false );
164 m_pTbxData
->EnableItem( TBI_DATA_DELETE_ROW
, false );
165 m_pTbxData
->EnableItem( TBI_DATA_DELETE_COL
, false );
166 m_pTbxData
->EnableItem( TBI_DATA_SWAP_COL
, false );
167 m_pTbxData
->EnableItem( TBI_DATA_SWAP_ROW
, false );
170 m_xBrwData
->SetReadOnly( m_bReadOnly
);
173 IMPL_LINK_NOARG(DataEditor
, MiscHdl
)
175 SvtMiscOptions aMiscOptions
;
176 sal_Int16
nStyle( aMiscOptions
.GetToolboxStyle() );
178 m_pTbxData
->SetOutStyle( nStyle
);
183 IMPL_STATIC_LINK_NOARG(DataEditor
, CellModified
)
188 void DataEditor::UpdateData()
190 m_xBrwData
->SetDataFromModel( m_xChartDoc
, m_xContext
);
193 bool DataEditor::Close()
195 if( ApplyChangesToModel() )
196 return ModalDialog::Close();
201 bool DataEditor::ApplyChangesToModel()
203 return m_xBrwData
->EndEditing();
206 // add/remove a window (the toolbar) to/from the global list, so that F6
207 // travels/no longer travels over this window. _rMemFunc may be
208 // TaskPaneList::AddWindow or TaskPaneList::RemoveWindow
209 void DataEditor::notifySystemWindow(
210 vcl::Window
* pWindow
, vcl::Window
* pToRegister
,
211 const ::comphelper::mem_fun1_t
<TaskPaneList
, vcl::Window
*>& rMemFunc
)
213 OSL_ENSURE( pWindow
, "Window must not be null!" );
216 vcl::Window
* pParent
= pWindow
->GetParent();
217 while( pParent
&& ! pParent
->IsSystemWindow() )
219 pParent
= pParent
->GetParent();
221 if ( pParent
&& pParent
->IsSystemWindow())
223 SystemWindow
* pSystemWindow
= static_cast< SystemWindow
* >( pParent
);
224 rMemFunc( pSystemWindow
->GetTaskPaneList(),( pToRegister
));
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */