Update ooo320-m1
[ooovba.git] / chart2 / source / controller / dialogs / dlg_DataEditor.cxx
blobf7273dc875a5de09a41338838ee01b4a7fb68086
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlg_DataEditor.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "dlg_DataEditor.hxx"
35 #include "dlg_DataEditor.hrc"
36 #include "Strings.hrc"
37 #include "DataBrowser.hxx"
39 #include "ResId.hxx"
40 #include "Strings.hrc"
41 #include "SchSlotIds.hxx"
42 #include <sfx2/dispatch.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <vcl/taskpanelist.hxx>
45 #include <svtools/miscopt.hxx>
46 #include <svtools/pathoptions.hxx>
48 // for SfxBoolItem
49 #include <svtools/eitem.hxx>
51 #include <vcl/edit.hxx>
53 #include <com/sun/star/frame/XStorable.hpp>
54 #include <com/sun/star/chart2/XChartDocument.hpp>
56 // for storing/reading the position and size of the dialog
57 // #include <svtools/viewoptions.hxx>
59 using namespace ::com::sun::star;
60 using ::com::sun::star::uno::Reference;
61 using ::rtl::OUString;
64 namespace chart
67 DataEditor::DataEditor(
68 Window* pParent,
69 const Reference< chart2::XChartDocument > & xChartDoc,
70 const Reference< uno::XComponentContext > & xContext ) :
71 ModalDialog( pParent, SchResId( DLG_DIAGRAM_DATA )),
72 m_bReadOnly( false ),
73 m_apBrwData( new DataBrowser( this, SchResId( CTL_DATA ), true /* bLiveUpdate */)),
74 m_aTbxData( this, SchResId( TBX_DATA )),
75 m_xChartDoc( xChartDoc ),
76 m_xContext( xContext ),
77 m_aToolboxImageList( SchResId( IL_DIAGRAM_DATA )),
78 m_aToolboxImageListHighContrast( SchResId( IL_HC_DIAGRAM_DATA ))
80 FreeResource();
82 // set min size to current size
83 SetMinOutputSizePixel( GetOutputSizePixel() );
85 ApplyImageList();
87 m_aTbxData.SetSizePixel( m_aTbxData.CalcWindowSizePixel() );
88 m_aTbxData.SetSelectHdl( LINK( this, DataEditor, ToolboxHdl ));
90 m_apBrwData->SetCursorMovedHdl( LINK( this, DataEditor, BrowserCursorMovedHdl ));
91 m_apBrwData->SetCellModifiedHdl( LINK( this, DataEditor, CellModified ));
93 UpdateData();
94 GrabFocus();
95 m_apBrwData->GrabFocus();
97 bool bReadOnly = true;
98 Reference< frame::XStorable > xStor( m_xChartDoc, uno::UNO_QUERY );
99 if( xStor.is())
100 bReadOnly = xStor->isReadonly();
101 SetReadOnly( bReadOnly );
103 // #101228# change buttons to flat-look if set so by user
104 SvtMiscOptions aMiscOptions;
105 const sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() );
106 // react on changes
107 aMiscOptions.AddListener( LINK( this, DataEditor, MiscHdl ) );
108 m_aTbxData.SetOutStyle( nStyle );
110 // set good window width
111 Size aWinSize( GetOutputSizePixel());
112 Size aWinSizeWithBorder( GetSizePixel());
113 Point aWinPos( OutputToAbsoluteScreenPixel( GetPosPixel()));
114 sal_Int32 nMinWidth = aWinSize.getWidth();
115 sal_Int32 nMaxWidth = GetDesktopRectPixel().getWidth() -
116 (aWinSizeWithBorder.getWidth() - aWinSize.getWidth() + aWinPos.getX()) - 10; // leave some space
117 sal_Int32 nBrowserWidth = m_apBrwData->GetTotalWidth() + 12 + 16; // plus padding + 16?
118 sal_Int32 nWindowWidth = ::std::max( nMinWidth, nBrowserWidth );
119 nWindowWidth = ::std::min( nMaxWidth, nBrowserWidth );
120 aWinSize.setWidth( nWindowWidth );
121 SetOutputSizePixel( aWinSize );
122 AdaptBrowseBoxSize();
124 // ImplAdjustHeaderControls( false /* bRefreshFromModel */ );
126 // allow travelling to toolbar with F6
127 notifySystemWindow( this, & m_aTbxData, ::comphelper::mem_fun( & TaskPaneList::AddWindow ));
130 DataEditor::~DataEditor()
132 notifySystemWindow( this, & m_aTbxData, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow ));
134 SvtMiscOptions aMiscOptions;
135 aMiscOptions.RemoveListener( LINK( this, DataEditor, MiscHdl ) );
137 OSL_TRACE( "DataEditor: DTOR" );
140 // react on click (or keypress) on toolbar icon
141 IMPL_LINK( DataEditor, ToolboxHdl, void *, EMPTYARG )
143 switch( m_aTbxData.GetCurItemId() )
145 case TBI_DATA_INSERT_ROW:
146 m_apBrwData->InsertRow();
147 break;
148 case TBI_DATA_INSERT_COL:
149 m_apBrwData->InsertColumn();
150 // ImplAdjustHeaderControls( true /* bRefreshFromModel */ );
151 break;
152 case TBI_DATA_DELETE_ROW:
153 m_apBrwData->RemoveRow();
154 break;
155 case TBI_DATA_DELETE_COL:
156 m_apBrwData->RemoveColumn();
157 // ImplAdjustHeaderControls( true /* bRefreshFromModel */ );
158 break;
159 case TBI_DATA_SWAP_COL :
160 m_apBrwData->SwapColumn ();
161 // ImplAdjustHeaderControls( true /* bRefreshFromModel */ );
162 break;
163 case TBI_DATA_SWAP_ROW :
164 m_apBrwData->SwapRow ();
165 break;
166 // case TBI_DATA_SORT_COL :
167 // m_apBrwData->QuickSortCol();
168 // break;
169 // case TBI_DATA_SORT_ROW :
170 // m_apBrwData->QuickSortRow();
171 // break;
172 // case TBI_DATA_SORT_TABLE_COL :
173 // m_apBrwData->QuickSortTableCols ();
174 // break;
175 // case TBI_DATA_SORT_TABLE_ROW :
176 // m_apBrwData->QuickSortTableRows ();
177 // break;
180 return 0;
183 // refresh toolbar icons according to currently selected cell in brwose box
184 IMPL_LINK( DataEditor, BrowserCursorMovedHdl, void *, EMPTYARG )
186 if( m_bReadOnly )
187 return 0;
189 if( m_apBrwData->IsEnableItem() )
191 m_aTbxData.EnableItem( TBI_DATA_INSERT_ROW, m_apBrwData->MayInsertRow() );
192 m_aTbxData.EnableItem( TBI_DATA_INSERT_COL, m_apBrwData->MayInsertColumn() );
193 m_aTbxData.EnableItem( TBI_DATA_DELETE_ROW, m_apBrwData->MayDeleteRow() );
194 m_aTbxData.EnableItem( TBI_DATA_DELETE_COL, m_apBrwData->MayDeleteColumn() );
196 m_aTbxData.EnableItem( TBI_DATA_SWAP_COL, m_apBrwData->MaySwapColumns() );
197 m_aTbxData.EnableItem( TBI_DATA_SWAP_ROW, m_apBrwData->MaySwapRows() );
199 else
201 m_aTbxData.EnableItem( TBI_DATA_INSERT_ROW, FALSE );
202 m_aTbxData.EnableItem( TBI_DATA_INSERT_COL, FALSE );
203 m_aTbxData.EnableItem( TBI_DATA_SWAP_COL, FALSE );
204 m_aTbxData.EnableItem( TBI_DATA_SWAP_ROW, FALSE );
206 // m_aTbxData.EnableItem( TBI_DATA_SORT_COL, m_apBrwData->MaySortColumn() );
207 // m_aTbxData.EnableItem( TBI_DATA_SORT_ROW, m_apBrwData->MaySortRow() );
208 // m_aTbxData.EnableItem( TBI_DATA_SORT_TABLE_COL, m_apBrwData->MaySortColumn() );
209 // m_aTbxData.EnableItem( TBI_DATA_SORT_TABLE_ROW, m_apBrwData->MaySortRow() );
211 return 0;
214 // disable all modifying controls
215 void DataEditor::SetReadOnly( bool bReadOnly )
217 m_bReadOnly = bReadOnly;
218 if( m_bReadOnly )
220 m_aTbxData.EnableItem( TBI_DATA_INSERT_ROW, FALSE );
221 m_aTbxData.EnableItem( TBI_DATA_INSERT_COL, FALSE );
222 m_aTbxData.EnableItem( TBI_DATA_DELETE_ROW, FALSE );
223 m_aTbxData.EnableItem( TBI_DATA_DELETE_COL, FALSE );
224 m_aTbxData.EnableItem( TBI_DATA_SWAP_COL, FALSE );
225 m_aTbxData.EnableItem( TBI_DATA_SWAP_ROW, FALSE );
226 // m_aTbxData.EnableItem( TBI_DATA_SORT_COL, FALSE );
227 // m_aTbxData.EnableItem( TBI_DATA_SORT_ROW, FALSE );
228 // m_aTbxData.EnableItem( TBI_DATA_SORT_TABLE_ROW, FALSE );
229 // m_aTbxData.EnableItem( TBI_DATA_SORT_TABLE_COL, FALSE );
232 m_apBrwData->SetReadOnly( m_bReadOnly );
235 IMPL_LINK( DataEditor, MiscHdl, void*, EMPTYARG )
237 SvtMiscOptions aMiscOptions;
238 sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() );
240 m_aTbxData.SetOutStyle( nStyle );
242 return 0L;
245 IMPL_LINK( DataEditor, CellModified, void*, EMPTYARG )
247 return 0;
250 // IMPL_LINK( DataEditor, BrowserColumnResized, void*, EMPTYARG )
251 // {
252 // ImplAdjustHeaderControls( false /* bRefreshFromModel */ );
253 // return 0;
254 // }
256 // IMPL_LINK( DataEditor, BrowserContentScrolled, void*, EMPTYARG )
257 // {
258 // ImplAdjustHeaderControls( false /* bRefreshFromModel */ );
259 // return 0;
260 // }
262 void DataEditor::UpdateData()
264 m_apBrwData->SetDataFromModel( m_xChartDoc, m_xContext );
267 // react on the change of the underlying document by displaying the new data
268 // void DataEditor::SFX_NOTIFY(
269 // SfxBroadcaster& rBC,
270 // const TypeId& rBCType,
271 // const SfxHint& rHint,
272 // const TypeId& rHintType )
273 // {
274 // if( rHint.Type() == TYPE(SfxSimpleHint) )
275 // {
276 // // note: if dynamic_cast works this should be changed
277 // switch( static_cast< const SfxSimpleHint & >( rHint ).GetId())
278 // {
279 // case SFX_HINT_DOCCHANGED:
280 // UpdateData();
281 // break;
283 // case SFX_HINT_DYING:
284 // break;
285 // }
286 // }
287 // }
289 // {
290 // BOOL bRet = TRUE;
292 // // confirm changes currently made and not saved
293 // m_apBrwData->EndEditing();
295 // if( m_apBrwData->IsDirty() )
296 // {
297 // QueryBox aSafetyQuery( this, WB_YES_NO_CANCEL | WB_DEF_YES,
298 // String( SchResId( STR_DIAGRAM_DATA_SAFETY_QUERY )));
299 // long nQueryResult = aSafetyQuery.Execute();
301 // bRet = ( nQueryResult != RET_CANCEL );
303 // if( nQueryResult == RET_YES )
304 // {
305 // // save changes
306 // ApplyChangesToModel();
307 // }
308 // }
310 // if( bRet )
311 // {
312 // // close child window
313 // SfxBoolItem aItem( SID_DIAGRAM_DATA, FALSE );
314 // if( m_pBindings )
315 // {
316 // SfxDispatcher* pDisp = m_pBindings->GetDispatcher();
317 // if( pDisp )
318 // pDisp->Execute( SID_DIAGRAM_DATA, SFX_CALLMODE_ASYNCHRON, &aItem, 0L);
319 // else
320 // DBG_ERROR( "Couldn't dispatch command" );
321 // }
322 // }
324 // return ( bRet? SfxFloatingWindow::Close(): FALSE );
325 // }
327 void DataEditor::AdaptBrowseBoxSize()
329 Size aSize( PixelToLogic( GetResizeOutputSizePixel(), MAP_APPFONT ));
330 Size aDataSize;
332 aDataSize.setWidth( aSize.getWidth() - 12 );
333 aDataSize.setHeight( aSize.getHeight() - 31 -24 );
335 m_apBrwData->SetSizePixel( LogicToPixel( aDataSize, MAP_APPFONT ));
338 void DataEditor::Resize()
340 Dialog::Resize();
341 AdaptBrowseBoxSize();
342 // ImplAdjustHeaderControls( false /* bRefreshFromModel */ );
345 BOOL DataEditor::Close()
347 if( ApplyChangesToModel() )
348 return ModalDialog::Close();
349 else
350 return TRUE;
353 bool DataEditor::ApplyChangesToModel()
355 return m_apBrwData->EndEditing();
358 // sets the correct toolbar icons depending on the current mode (e.g. high contrast)
359 void DataEditor::ApplyImageList()
361 bool bIsHighContrast = ( true && GetDisplayBackground().GetColor().IsDark() );
363 ImageList& rImgLst = bIsHighContrast
364 ? m_aToolboxImageListHighContrast
365 : m_aToolboxImageList;
367 m_aTbxData.SetImageList( rImgLst );
370 // add/remove a window (the toolbar) to/from the global list, so that F6
371 // travels/no longer travels over this window. _rMemFunc may be
372 // TaskPaneList::AddWindow or TaskPaneList::RemoveWindow
373 void DataEditor::notifySystemWindow(
374 Window* pWindow, Window* pToRegister,
375 ::comphelper::mem_fun1_t< TaskPaneList, Window* > rMemFunc )
377 OSL_ENSURE( pWindow, "Window must not be null!" );
378 if( !pWindow )
379 return;
380 Window* pParent = pWindow->GetParent();
381 while( pParent && ! pParent->IsSystemWindow() )
383 pParent = pParent->GetParent();
385 if ( pParent && pParent->IsSystemWindow())
387 SystemWindow* pSystemWindow = static_cast< SystemWindow* >( pParent );
388 rMemFunc( pSystemWindow->GetTaskPaneList(),( pToRegister ));
392 } // namespace chart