Line data Source code
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 "Strings.hrc"
22 : #include "DataBrowser.hxx"
23 :
24 : #include "ResId.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>
32 :
33 : #include <com/sun/star/frame/XStorable.hpp>
34 : #include <com/sun/star/chart2/XChartDocument.hpp>
35 :
36 : using namespace ::com::sun::star;
37 : using ::com::sun::star::uno::Reference;
38 :
39 : namespace chart
40 : {
41 :
42 0 : 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")
47 : , m_bReadOnly(false)
48 : , m_xChartDoc(xChartDoc)
49 0 : , m_xContext(xContext)
50 : {
51 0 : m_xBrwData.reset(new DataBrowser(get<vcl::Window>("datawindow"), WB_BORDER | WB_TABSTOP, true /* bLiveUpdate */));
52 0 : m_xBrwData->set_hexpand(true);
53 0 : m_xBrwData->set_vexpand(true);
54 0 : m_xBrwData->set_expand(true);
55 0 : Size aSize(m_xBrwData->LogicToPixel(Size(232, 121), MAP_APPFONT));
56 0 : m_xBrwData->set_width_request(aSize.Width());
57 0 : m_xBrwData->set_height_request(aSize.Height());
58 0 : m_xBrwData->Show();
59 :
60 0 : get(m_pTbxData, "toolbar");
61 :
62 0 : TBI_DATA_INSERT_ROW = m_pTbxData->GetItemId("InsertRow");
63 0 : TBI_DATA_INSERT_COL = m_pTbxData->GetItemId("InsertColumn");
64 0 : TBI_DATA_INSERT_TEXT_COL = m_pTbxData->GetItemId("InsertTextColumn");
65 0 : TBI_DATA_DELETE_ROW = m_pTbxData->GetItemId("RemoveRow");
66 0 : TBI_DATA_DELETE_COL = m_pTbxData->GetItemId("RemoveColumn");
67 0 : TBI_DATA_SWAP_COL = m_pTbxData->GetItemId("SwapColumn");
68 0 : TBI_DATA_SWAP_ROW = m_pTbxData->GetItemId("SwapRow");
69 :
70 0 : m_pTbxData->SetSelectHdl( LINK( this, DataEditor, ToolboxHdl ));
71 :
72 0 : m_xBrwData->SetCursorMovedHdl( LINK( this, DataEditor, BrowserCursorMovedHdl ));
73 0 : m_xBrwData->SetCellModifiedHdl( LINK( this, DataEditor, CellModified ));
74 :
75 0 : UpdateData();
76 0 : GrabFocus();
77 0 : m_xBrwData->GrabFocus();
78 :
79 0 : bool bReadOnly = true;
80 0 : Reference< frame::XStorable > xStor( m_xChartDoc, uno::UNO_QUERY );
81 0 : if( xStor.is())
82 0 : bReadOnly = xStor->isReadonly();
83 0 : SetReadOnly( bReadOnly );
84 :
85 : // change buttons to flat-look if set so by user
86 0 : SvtMiscOptions aMiscOptions;
87 0 : const sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() );
88 : // react on changes
89 0 : aMiscOptions.AddListenerLink( LINK( this, DataEditor, MiscHdl ) );
90 0 : m_pTbxData->SetOutStyle( nStyle );
91 :
92 : // allow travelling to toolbar with F6
93 0 : notifySystemWindow( this, m_pTbxData, ::comphelper::mem_fun( & TaskPaneList::AddWindow ));
94 0 : }
95 :
96 0 : DataEditor::~DataEditor()
97 : {
98 0 : notifySystemWindow( this, m_pTbxData, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow ));
99 :
100 0 : SvtMiscOptions aMiscOptions;
101 0 : aMiscOptions.RemoveListenerLink( LINK( this, DataEditor, MiscHdl ) );
102 :
103 0 : OSL_TRACE( "DataEditor: DTOR" );
104 0 : }
105 :
106 : // react on click (or keypress) on toolbar icon
107 0 : IMPL_LINK_NOARG(DataEditor, ToolboxHdl)
108 : {
109 0 : sal_uInt16 nId = m_pTbxData->GetCurItemId();
110 :
111 0 : if (nId == TBI_DATA_INSERT_ROW)
112 0 : m_xBrwData->InsertRow();
113 0 : else if (nId == TBI_DATA_INSERT_COL)
114 0 : m_xBrwData->InsertColumn();
115 0 : else if (nId == TBI_DATA_INSERT_TEXT_COL)
116 0 : m_xBrwData->InsertTextColumn();
117 0 : else if (nId == TBI_DATA_DELETE_ROW)
118 0 : m_xBrwData->RemoveRow();
119 0 : else if (nId == TBI_DATA_DELETE_COL)
120 0 : m_xBrwData->RemoveColumn();
121 0 : else if (nId == TBI_DATA_SWAP_COL)
122 0 : m_xBrwData->SwapColumn();
123 0 : else if (nId == TBI_DATA_SWAP_ROW)
124 0 : m_xBrwData->SwapRow();
125 :
126 0 : return 0;
127 : }
128 :
129 : // refresh toolbar icons according to currently selected cell in brwose box
130 0 : IMPL_LINK_NOARG(DataEditor, BrowserCursorMovedHdl)
131 : {
132 0 : if( m_bReadOnly )
133 0 : return 0;
134 :
135 0 : bool bIsDataValid = m_xBrwData->IsEnableItem();
136 :
137 0 : m_pTbxData->EnableItem( TBI_DATA_INSERT_ROW, bIsDataValid && m_xBrwData->MayInsertRow() );
138 0 : m_pTbxData->EnableItem( TBI_DATA_INSERT_COL, bIsDataValid && m_xBrwData->MayInsertColumn() );
139 0 : m_pTbxData->EnableItem( TBI_DATA_INSERT_TEXT_COL, bIsDataValid && m_xBrwData->MayInsertColumn() );
140 0 : m_pTbxData->EnableItem( TBI_DATA_DELETE_ROW, m_xBrwData->MayDeleteRow() );
141 0 : m_pTbxData->EnableItem( TBI_DATA_DELETE_COL, m_xBrwData->MayDeleteColumn() );
142 :
143 0 : m_pTbxData->EnableItem( TBI_DATA_SWAP_COL, bIsDataValid && m_xBrwData->MaySwapColumns() );
144 0 : m_pTbxData->EnableItem( TBI_DATA_SWAP_ROW, bIsDataValid && m_xBrwData->MaySwapRows() );
145 :
146 0 : return 0;
147 : }
148 :
149 : // disable all modifying controls
150 0 : void DataEditor::SetReadOnly( bool bReadOnly )
151 : {
152 0 : m_bReadOnly = bReadOnly;
153 0 : if( m_bReadOnly )
154 : {
155 0 : m_pTbxData->EnableItem( TBI_DATA_INSERT_ROW, false );
156 0 : m_pTbxData->EnableItem( TBI_DATA_INSERT_COL, false );
157 0 : m_pTbxData->EnableItem( TBI_DATA_INSERT_TEXT_COL, false );
158 0 : m_pTbxData->EnableItem( TBI_DATA_DELETE_ROW, false );
159 0 : m_pTbxData->EnableItem( TBI_DATA_DELETE_COL, false );
160 0 : m_pTbxData->EnableItem( TBI_DATA_SWAP_COL, false );
161 0 : m_pTbxData->EnableItem( TBI_DATA_SWAP_ROW, false );
162 : }
163 :
164 0 : m_xBrwData->SetReadOnly( m_bReadOnly );
165 0 : }
166 :
167 0 : IMPL_LINK_NOARG(DataEditor, MiscHdl)
168 : {
169 0 : SvtMiscOptions aMiscOptions;
170 0 : sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() );
171 :
172 0 : m_pTbxData->SetOutStyle( nStyle );
173 :
174 0 : return 0L;
175 : }
176 :
177 0 : IMPL_LINK_NOARG(DataEditor, CellModified)
178 : {
179 0 : return 0;
180 : }
181 :
182 0 : void DataEditor::UpdateData()
183 : {
184 0 : m_xBrwData->SetDataFromModel( m_xChartDoc, m_xContext );
185 0 : }
186 :
187 0 : bool DataEditor::Close()
188 : {
189 0 : if( ApplyChangesToModel() )
190 0 : return ModalDialog::Close();
191 : else
192 0 : return true;
193 : }
194 :
195 0 : bool DataEditor::ApplyChangesToModel()
196 : {
197 0 : return m_xBrwData->EndEditing();
198 : }
199 :
200 : // add/remove a window (the toolbar) to/from the global list, so that F6
201 : // travels/no longer travels over this window. _rMemFunc may be
202 : // TaskPaneList::AddWindow or TaskPaneList::RemoveWindow
203 0 : void DataEditor::notifySystemWindow(
204 : vcl::Window* pWindow, vcl::Window* pToRegister,
205 : ::comphelper::mem_fun1_t< TaskPaneList, vcl::Window* > rMemFunc )
206 : {
207 : OSL_ENSURE( pWindow, "Window must not be null!" );
208 0 : if( !pWindow )
209 0 : return;
210 0 : vcl::Window* pParent = pWindow->GetParent();
211 0 : while( pParent && ! pParent->IsSystemWindow() )
212 : {
213 0 : pParent = pParent->GetParent();
214 : }
215 0 : if ( pParent && pParent->IsSystemWindow())
216 : {
217 0 : SystemWindow* pSystemWindow = static_cast< SystemWindow* >( pParent );
218 0 : rMemFunc( pSystemWindow->GetTaskPaneList(),( pToRegister ));
219 : }
220 : }
221 :
222 102 : } // namespace chart
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|