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 .
19 #include "GroupsSorting.hxx"
20 #include <connectivity/dbtools.hxx>
21 #include <sot/exchange.hxx>
22 #include <svtools/editbrowsebox.hxx>
23 #include <svtools/imgdef.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/container/XContainerListener.hpp>
26 #include <com/sun/star/report/GroupOn.hpp>
27 #include <com/sun/star/sdbc/DataType.hpp>
29 #include <tools/debug.hxx>
30 #include "RptResId.hrc"
31 #include "rptui_slotid.hrc"
32 #include "ModuleHelper.hxx"
33 #include "helpids.hrc"
34 #include "GroupExchange.hxx"
35 #include "UITools.hxx"
36 #include "UndoActions.hxx"
37 #include "uistrings.hrc"
38 #include "ReportController.hxx"
39 #include "ColumnInfo.hxx"
41 #include <cppuhelper/implbase1.hxx>
42 #include <comphelper/property.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <vcl/settings.hxx>
48 #include <cppuhelper/bootstrap.hxx>
51 #define FIELD_EXPRESSION 1
52 #define GROUPS_START_LEN 5
57 using namespace ::com::sun::star
;
59 using namespace ::comphelper
;
61 void lcl_addToList_throw( ComboBoxControl
& _rListBox
, ::std::vector
<ColumnInfo
>& o_aColumnList
,const uno::Reference
< container::XNameAccess
>& i_xColumns
)
63 uno::Sequence
< OUString
> aEntries
= i_xColumns
->getElementNames();
64 const OUString
* pEntries
= aEntries
.getConstArray();
65 sal_Int32 nEntries
= aEntries
.getLength();
66 for ( sal_Int32 i
= 0; i
< nEntries
; ++i
, ++pEntries
)
68 uno::Reference
< beans::XPropertySet
> xColumn(i_xColumns
->getByName(*pEntries
),uno::UNO_QUERY_THROW
);
70 if ( xColumn
->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL
) )
71 xColumn
->getPropertyValue(PROPERTY_LABEL
) >>= sLabel
;
72 o_aColumnList
.push_back( ColumnInfo(*pEntries
,sLabel
) );
73 if ( !sLabel
.isEmpty() )
74 _rListBox
.InsertEntry( sLabel
);
76 _rListBox
.InsertEntry( *pEntries
);
81 * Separated out from OFieldExpressionControl to prevent collision of ref-counted base classes
83 class OFieldExpressionControl
;
84 class OFieldExpressionControlContainerListener
: public ::cppu::WeakImplHelper1
< container::XContainerListener
>
86 VclPtr
<OFieldExpressionControl
> mpParent
;
88 OFieldExpressionControlContainerListener(OFieldExpressionControl
* pParent
) : mpParent(pParent
) {}
91 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
93 virtual void SAL_CALL
elementInserted(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
94 virtual void SAL_CALL
elementReplaced(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
95 virtual void SAL_CALL
elementRemoved(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
98 class OFieldExpressionControl
: public ::svt::EditBrowseBox
100 ::osl::Mutex m_aMutex
;
101 ::std::vector
<sal_Int32
> m_aGroupPositions
;
102 ::std::vector
<ColumnInfo
> m_aColumnInfo
;
103 VclPtr
< ::svt::ComboBoxControl
> m_pComboCell
;
104 sal_Int32 m_nDataPos
;
105 sal_Int32 m_nCurrentPos
;
106 ImplSVEvent
* m_nPasteEvent
;
107 ImplSVEvent
* m_nDeleteEvent
;
108 VclPtr
<OGroupsSortingDialog
> m_pParent
;
110 OFieldExpressionControlContainerListener aContainerListener
;
112 bool SaveModified(bool _bAppend
);
115 OFieldExpressionControl(OGroupsSortingDialog
* _pParentDialog
, vcl::Window
*_pParent
);
116 virtual ~OFieldExpressionControl();
117 virtual void dispose() SAL_OVERRIDE
;
120 static void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
);
121 // XContainerListener
122 void SAL_CALL
elementInserted(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
);
123 static void SAL_CALL
elementReplaced(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
);
124 void SAL_CALL
elementRemoved(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
);
126 virtual Size
GetOptimalSize() const SAL_OVERRIDE
;
128 void fillColumns(const uno::Reference
< container::XNameAccess
>& _xColumns
);
130 bool IsDeleteAllowed( );
136 inline sal_Int32
getGroupPosition(sal_Int32 _nRow
) const { return _nRow
!= BROWSER_ENDOFSELECTION
? m_aGroupPositions
[_nRow
] : sal_Int32(NO_GROUP
); }
138 inline ::svt::ComboBoxControl
* getExpressionControl() const { return m_pComboCell
; }
140 /** returns the sequence with the selected groups
142 uno::Sequence
<uno::Any
> fillSelectedGroups();
144 /** move groups given by _aGroups
146 void moveGroups(const uno::Sequence
<uno::Any
>& _aGroups
,sal_Int32 _nRow
,bool _bSelect
= true);
148 virtual bool CursorMoving(long nNewRow
, sal_uInt16 nNewCol
) SAL_OVERRIDE
;
149 using ::svt::EditBrowseBox::GetRowCount
;
151 virtual bool IsTabAllowed(bool bForward
) const SAL_OVERRIDE
;
153 virtual void InitController( ::svt::CellControllerRef
& rController
, long nRow
, sal_uInt16 nCol
) SAL_OVERRIDE
;
154 virtual ::svt::CellController
* GetController( long nRow
, sal_uInt16 nCol
) SAL_OVERRIDE
;
155 virtual void PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, sal_uInt16 nColId
) const SAL_OVERRIDE
;
156 virtual bool SeekRow( long nRow
) SAL_OVERRIDE
;
157 virtual bool SaveModified() SAL_OVERRIDE
;
158 virtual OUString
GetCellText( long nRow
, sal_uInt16 nColId
) const SAL_OVERRIDE
;
159 virtual RowStatus
GetRowStatus(long nRow
) const SAL_OVERRIDE
;
161 virtual void KeyInput(const KeyEvent
& rEvt
) SAL_OVERRIDE
;
162 virtual void Command( const CommandEvent
& rEvt
) SAL_OVERRIDE
;
165 virtual void StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
) SAL_OVERRIDE
;
166 virtual sal_Int8
AcceptDrop( const BrowserAcceptDropEvent
& rEvt
) SAL_OVERRIDE
;
167 virtual sal_Int8
ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
) SAL_OVERRIDE
;
169 using BrowseBox::AcceptDrop
;
170 using BrowseBox::ExecuteDrop
;
174 DECL_LINK( DelayedPaste
, void* );
175 DECL_LINK( CBChangeHdl
,ComboBox
*);
177 void InsertRows( long nRow
);
180 DECL_LINK( DelayedDelete
, void* );
185 void OFieldExpressionControlContainerListener::disposing(const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
)
186 { OFieldExpressionControl::disposing(Source
); }
188 void OFieldExpressionControlContainerListener::elementInserted(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
189 { mpParent
->elementInserted(rEvent
); }
191 void OFieldExpressionControlContainerListener::elementReplaced(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
192 { OFieldExpressionControl::elementReplaced(rEvent
); }
194 void OFieldExpressionControlContainerListener::elementRemoved(const ::com::sun::star::container::ContainerEvent
& rEvent
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
195 { mpParent
->elementRemoved(rEvent
); }
198 // class OFieldExpressionControl
199 OFieldExpressionControl::OFieldExpressionControl(OGroupsSortingDialog
* _pParentDialog
, vcl::Window
*_pParent
)
200 :EditBrowseBox( _pParent
, EditBrowseBoxFlags::NONE
, WB_TABSTOP
,
201 BrowserMode::COLUMNSELECTION
| BrowserMode::MULTISELECTION
| BrowserMode::AUTOSIZE_LASTCOL
|
202 BrowserMode::KEEPHIGHLIGHT
| BrowserMode::HLINES
| BrowserMode::VLINES
)
203 ,m_aGroupPositions(GROUPS_START_LEN
,-1)
209 ,m_pParent(_pParentDialog
)
210 ,m_bIgnoreEvent(false)
211 ,aContainerListener(this)
213 SetBorderStyle(WindowBorderStyle::MONO
);
217 OFieldExpressionControl::~OFieldExpressionControl()
223 void OFieldExpressionControl::dispose()
225 aContainerListener
.WeakImplHelper1::acquire();
226 uno::Reference
< report::XGroups
> xGroups
= m_pParent
->getGroups();
227 xGroups
->removeContainerListener(&aContainerListener
);
229 // delete events from queue
231 Application::RemoveUserEvent( m_nPasteEvent
);
233 Application::RemoveUserEvent( m_nDeleteEvent
);
235 m_pComboCell
.disposeAndClear();
237 ::svt::EditBrowseBox::dispose();
240 uno::Sequence
<uno::Any
> OFieldExpressionControl::fillSelectedGroups()
242 uno::Sequence
<uno::Any
> aList
;
243 ::std::vector
<uno::Any
> vClipboardList
;
244 vClipboardList
.reserve(GetSelectRowCount());
246 uno::Reference
<report::XGroups
> xGroups
= m_pParent
->getGroups();
247 sal_Int32 nCount
= xGroups
->getCount();
250 for( long nIndex
=FirstSelectedRow(); nIndex
>= 0 ; nIndex
=NextSelectedRow() )
254 if ( m_aGroupPositions
[nIndex
] != NO_GROUP
)
256 uno::Reference
< report::XGroup
> xOrgGroup(xGroups
->getByIndex(m_aGroupPositions
[nIndex
]),uno::UNO_QUERY
);
257 /*uno::Reference< report::XGroup> xCopy = xGroups->createGroup();
258 ::comphelper::copyProperties(xOrgGroup.get(),xCopy.get());*/
259 vClipboardList
.push_back( uno::makeAny(xOrgGroup
) );
262 catch(uno::Exception
&)
264 OSL_FAIL("Can not access group!");
267 if ( !vClipboardList
.empty() )
268 aList
= uno::Sequence
< uno::Any
>(&vClipboardList
[0], vClipboardList
.size());
273 void OFieldExpressionControl::StartDrag( sal_Int8
/*_nAction*/ , const Point
& /*_rPosPixel*/ )
275 if ( m_pParent
&& !m_pParent
->isReadOnly( ) )
277 uno::Sequence
<uno::Any
> aClipboardList
= fillSelectedGroups();
279 if( aClipboardList
.getLength() )
281 OGroupExchange
* pData
= new OGroupExchange(aClipboardList
);
282 uno::Reference
< ::com::sun::star::datatransfer::XTransferable
> xRef
= pData
;
283 pData
->StartDrag(this, DND_ACTION_MOVE
);
288 sal_Int8
OFieldExpressionControl::AcceptDrop( const BrowserAcceptDropEvent
& rEvt
)
290 sal_Int8 nAction
= DND_ACTION_NONE
;
293 sal_Int32 nPos
= m_pComboCell
->GetSelectEntryPos();
294 if ( COMBOBOX_ENTRY_NOTFOUND
!= nPos
|| !m_pComboCell
->GetText().isEmpty() )
298 if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) && m_pParent
->getGroups()->getCount() > 1 && rEvt
.GetWindow() == &GetDataWindow() )
300 nAction
= DND_ACTION_MOVE
;
305 sal_Int8
OFieldExpressionControl::ExecuteDrop( const BrowserExecuteDropEvent
& rEvt
)
307 sal_Int8 nAction
= DND_ACTION_NONE
;
308 if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) )
310 sal_Int32 nRow
= GetRowAtYPosPixel(rEvt
.maPosPixel
.Y(), false);
313 TransferableDataHelper
aDropped( rEvt
.maDropEvent
.Transferable
);
314 uno::Any aDrop
= aDropped
.GetAny(OGroupExchange::getReportGroupId(), OUString());
315 uno::Sequence
< uno::Any
> aGroups
;
317 if ( aGroups
.getLength() )
319 moveGroups(aGroups
,nRow
);
320 nAction
= DND_ACTION_MOVE
;
326 void OFieldExpressionControl::moveGroups(const uno::Sequence
<uno::Any
>& _aGroups
,sal_Int32 _nRow
,bool _bSelect
)
328 if ( _aGroups
.getLength() )
330 m_bIgnoreEvent
= true;
332 sal_Int32 nRow
= _nRow
;
333 const OUString
sUndoAction(ModuleRes(RID_STR_UNDO_MOVE_GROUP
));
334 const UndoContext
aUndoContext( m_pParent
->m_pController
->getUndoManager(), sUndoAction
);
336 uno::Reference
< report::XGroups
> xGroups
= m_pParent
->getGroups();
337 const uno::Any
* pIter
= _aGroups
.getConstArray();
338 const uno::Any
* pEnd
= pIter
+ _aGroups
.getLength();
339 for(;pIter
!= pEnd
;++pIter
)
341 uno::Reference
< report::XGroup
> xGroup(*pIter
,uno::UNO_QUERY
);
344 uno::Sequence
< beans::PropertyValue
> aArgs(1);
345 aArgs
[0].Name
= PROPERTY_GROUP
;
346 aArgs
[0].Value
<<= xGroup
;
347 // we use this way to create undo actions
348 m_pParent
->m_pController
->executeChecked(SID_GROUP_REMOVE
,aArgs
);
350 if ( nRow
> xGroups
->getCount() )
351 nRow
= xGroups
->getCount();
354 aArgs
[1].Name
= PROPERTY_POSITIONY
;
355 aArgs
[1].Value
<<= nRow
;
356 m_pParent
->m_pController
->executeChecked(SID_GROUP_APPEND
,aArgs
);
361 m_bIgnoreEvent
= false;
366 void OFieldExpressionControl::fillColumns(const uno::Reference
< container::XNameAccess
>& _xColumns
)
368 m_pComboCell
->Clear();
369 if ( _xColumns
.is() )
370 lcl_addToList_throw(*m_pComboCell
,m_aColumnInfo
,_xColumns
);
373 void OFieldExpressionControl::lateInit()
375 uno::Reference
< report::XGroups
> xGroups
= m_pParent
->getGroups();
376 sal_Int32 nGroupsCount
= xGroups
->getCount();
377 m_aGroupPositions
.resize(::std::max
<sal_Int32
>(nGroupsCount
,sal_Int32(GROUPS_START_LEN
)),NO_GROUP
);
378 ::std::vector
<sal_Int32
>::iterator aIter
= m_aGroupPositions
.begin();
379 for (sal_Int32 i
= 0; i
< nGroupsCount
; ++i
,++aIter
)
382 if ( ColCount() == 0 )
384 vcl::Font
aFont( GetDataWindow().GetFont() );
385 aFont
.SetWeight( WEIGHT_NORMAL
);
386 GetDataWindow().SetFont( aFont
);
388 // Font fuer die Ueberschriften auf Light setzen
390 aFont
.SetWeight( WEIGHT_LIGHT
);
393 InsertHandleColumn(static_cast<sal_uInt16
>(GetTextWidth(OUString('0')) * 4)/*, sal_True */);
394 InsertDataColumn( FIELD_EXPRESSION
, OUString(ModuleRes(STR_RPT_EXPRESSION
)), 100);
396 m_pComboCell
= VclPtr
<ComboBoxControl
>::Create( &GetDataWindow() );
397 m_pComboCell
->SetSelectHdl(LINK(this,OFieldExpressionControl
,CBChangeHdl
));
398 m_pComboCell
->SetHelpId(HID_RPT_FIELDEXPRESSION
);
400 Control
* pControls
[] = {m_pComboCell
};
401 for (size_t i
= 0; i
< sizeof(pControls
)/sizeof(pControls
[0]); ++i
)
403 pControls
[i
]->SetGetFocusHdl(LINK(m_pParent
, OGroupsSortingDialog
, OnControlFocusGot
));
404 pControls
[i
]->SetLoseFocusHdl(LINK(m_pParent
, OGroupsSortingDialog
, OnControlFocusLost
));
409 BrowserMode
nMode(BrowserMode::COLUMNSELECTION
| BrowserMode::MULTISELECTION
| BrowserMode::KEEPHIGHLIGHT
|
410 BrowserMode::HLINES
| BrowserMode::VLINES
| BrowserMode::AUTOSIZE_LASTCOL
| BrowserMode::AUTO_VSCROLL
| BrowserMode::AUTO_HSCROLL
);
411 if( m_pParent
->isReadOnly() )
412 nMode
|= BrowserMode::HIDECURSOR
;
414 xGroups
->addContainerListener(&aContainerListener
);
417 // not the first call
418 RowRemoved(0, GetRowCount());
420 RowInserted(0, m_aGroupPositions
.size(), true);
424 IMPL_LINK( OFieldExpressionControl
, CBChangeHdl
, ComboBox
*, /*pComboBox*/ )
432 bool OFieldExpressionControl::IsTabAllowed(bool /*bForward*/) const
438 bool OFieldExpressionControl::SaveModified()
440 return SaveModified(true);
443 bool OFieldExpressionControl::SaveModified(bool _bAppendRow
)
445 sal_Int32 nRow
= GetCurRow();
446 if ( nRow
!= BROWSER_ENDOFSELECTION
)
450 bool bAppend
= false;
451 uno::Reference
< report::XGroup
> xGroup
;
452 if ( m_aGroupPositions
[nRow
] == NO_GROUP
)
455 OUString
sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP
));
456 m_pParent
->m_pController
->getUndoManager().EnterListAction( sUndoAction
, OUString() );
457 xGroup
= m_pParent
->getGroups()->createGroup();
458 xGroup
->setHeaderOn(sal_True
);
460 uno::Sequence
< beans::PropertyValue
> aArgs(2);
461 aArgs
[0].Name
= PROPERTY_GROUP
;
462 aArgs
[0].Value
<<= xGroup
;
463 // find position where to insert the new group
464 sal_Int32 nGroupPos
= 0;
465 ::std::vector
<sal_Int32
>::iterator aIter
= m_aGroupPositions
.begin();
466 ::std::vector
<sal_Int32
>::iterator aEnd
= m_aGroupPositions
.begin() + nRow
;
467 for(;aIter
!= aEnd
;++aIter
)
468 if ( *aIter
!= NO_GROUP
)
469 nGroupPos
= *aIter
+ 1;
470 aArgs
[1].Name
= PROPERTY_POSITIONY
;
471 aArgs
[1].Value
<<= nGroupPos
;
472 m_bIgnoreEvent
= true;
473 m_pParent
->m_pController
->executeChecked(SID_GROUP_APPEND
,aArgs
);
474 m_bIgnoreEvent
= false;
475 OSL_ENSURE(*aIter
== NO_GROUP
,"Illegal iterator!");
476 *aIter
++ = nGroupPos
;
478 aEnd
= m_aGroupPositions
.end();
479 for(;aIter
!= aEnd
;++aIter
)
480 if ( *aIter
!= NO_GROUP
)
484 xGroup
= m_pParent
->getGroup(m_aGroupPositions
[nRow
]);
487 sal_Int32 nPos
= m_pComboCell
->GetSelectEntryPos();
488 OUString sExpression
;
489 if ( COMBOBOX_ENTRY_NOTFOUND
== nPos
)
490 sExpression
= m_pComboCell
->GetText();
493 sExpression
= m_aColumnInfo
[nPos
].sColumnName
;
495 xGroup
->setExpression( sExpression
);
497 ::rptui::adjustSectionName(xGroup
,nPos
);
500 m_pParent
->m_pController
->getUndoManager().LeaveListAction();
504 Controller()->ClearModified();
505 if ( _bAppendRow
&& GetRowCount() == m_pParent
->getGroups()->getCount() )
507 RowInserted( GetRowCount()-1);
508 m_aGroupPositions
.push_back(NO_GROUP
);
512 m_pParent
->DisplayData(nRow
);
514 catch(uno::Exception
&)
516 OSL_FAIL("OFieldExpressionControl::SaveModified: Exception caught!");
523 OUString
OFieldExpressionControl::GetCellText( long nRow
, sal_uInt16
/*nColId*/ ) const
526 if ( nRow
!= BROWSER_ENDOFSELECTION
&& m_aGroupPositions
[nRow
] != NO_GROUP
)
530 uno::Reference
< report::XGroup
> xGroup
= m_pParent
->getGroup(m_aGroupPositions
[nRow
]);
531 OUString sExpression
= xGroup
->getExpression();
533 for(::std::vector
<ColumnInfo
>::const_iterator aIter
= m_aColumnInfo
.begin(); aIter
!= m_aColumnInfo
.end();++aIter
)
535 if ( aIter
->sColumnName
== sExpression
)
537 if ( !aIter
->sLabel
.isEmpty() )
538 sExpression
= aIter
->sLabel
;
544 catch (const uno::Exception
&)
546 OSL_FAIL("Exception caught while getting expression value from the group");
553 void OFieldExpressionControl::InitController( CellControllerRef
& /*rController*/, long nRow
, sal_uInt16 nColumnId
)
556 m_pComboCell
->SetText( GetCellText( nRow
, nColumnId
) );
559 bool OFieldExpressionControl::CursorMoving(long nNewRow
, sal_uInt16 nNewCol
)
562 if (!EditBrowseBox::CursorMoving(nNewRow
, nNewCol
))
564 m_nDataPos
= nNewRow
;
565 long nOldDataPos
= GetCurRow();
566 InvalidateStatusCell( m_nDataPos
);
567 InvalidateStatusCell( nOldDataPos
);
569 m_pParent
->SaveData( nOldDataPos
);
570 m_pParent
->DisplayData( m_nDataPos
);
574 CellController
* OFieldExpressionControl::GetController( long /*nRow*/, sal_uInt16
/*nColumnId*/ )
576 ComboBoxCellController
* pCellController
= new ComboBoxCellController( m_pComboCell
);
577 pCellController
->GetComboBox().SetReadOnly(!m_pParent
->m_pController
->isEditable());
578 return pCellController
;
582 bool OFieldExpressionControl::SeekRow( long _nRow
)
584 // die Basisklasse braucht den Aufruf, da sie sich dort merkt, welche Zeile gepainted wird
585 EditBrowseBox::SeekRow(_nRow
);
586 m_nCurrentPos
= _nRow
;
591 void OFieldExpressionControl::PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
, sal_uInt16 nColumnId
) const
593 OUString aText
=GetCellText( m_nCurrentPos
, nColumnId
);
595 Point
aPos( rRect
.TopLeft() );
596 Size
aTextSize( GetDataWindow().GetTextWidth( aText
), GetDataWindow().GetTextHeight() );
598 if( aPos
.X() < rRect
.Left() || aPos
.X() + aTextSize
.Width() > rRect
.Right() ||
599 aPos
.Y() < rRect
.Top() || aPos
.Y() + aTextSize
.Height() > rRect
.Bottom() )
600 rDev
.SetClipRegion(vcl::Region(rRect
));
602 rDev
.DrawText( aPos
, aText
);
604 if( rDev
.IsClipRegion() )
605 rDev
.SetClipRegion();
608 EditBrowseBox::RowStatus
OFieldExpressionControl::GetRowStatus(long nRow
) const
610 if (nRow
>= 0 && nRow
== m_nDataPos
)
611 return EditBrowseBox::CURRENT
;
612 if ( nRow
!= BROWSER_ENDOFSELECTION
&& nRow
< static_cast<long>(m_aGroupPositions
.size()) && m_aGroupPositions
[nRow
] != NO_GROUP
)
616 uno::Reference
< report::XGroup
> xGroup
= m_pParent
->getGroup(m_aGroupPositions
[nRow
]);
617 return (xGroup
->getHeaderOn() || xGroup
->getFooterOn())? EditBrowseBox::HEADERFOOTER
: EditBrowseBox::CLEAN
;
619 catch(uno::Exception
&)
621 OSL_FAIL("Exception cathced while try to get a group!");
624 return EditBrowseBox::CLEAN
;
628 void SAL_CALL
OFieldExpressionControl::disposing(const lang::EventObject
& /*e*/) throw( uno::RuntimeException
, std::exception
)
632 // XContainerListener
634 void SAL_CALL
OFieldExpressionControl::elementInserted(const container::ContainerEvent
& evt
) throw(uno::RuntimeException
, std::exception
)
636 if ( m_bIgnoreEvent
)
638 SolarMutexGuard aSolarGuard
;
639 ::osl::MutexGuard
aGuard( m_aMutex
);
640 sal_Int32 nGroupPos
= 0;
641 if ( evt
.Accessor
>>= nGroupPos
)
643 if ( nGroupPos
>= GetRowCount() )
645 sal_Int32 nAddedRows
= nGroupPos
- GetRowCount();
646 RowInserted(nAddedRows
);
647 for (sal_Int32 i
= 0; i
< nAddedRows
; ++i
)
648 m_aGroupPositions
.push_back(NO_GROUP
);
649 m_aGroupPositions
[nGroupPos
] = nGroupPos
;
653 ::std::vector
<sal_Int32
>::iterator aFind
= m_aGroupPositions
.begin()+ nGroupPos
;
654 if ( aFind
== m_aGroupPositions
.end() )
655 aFind
= ::std::find(m_aGroupPositions
.begin(),m_aGroupPositions
.end(),NO_GROUP
);
657 if ( aFind
!= m_aGroupPositions
.end() )
659 if ( *aFind
!= NO_GROUP
)
660 aFind
= m_aGroupPositions
.insert(aFind
,nGroupPos
);
664 ::std::vector
<sal_Int32
>::iterator aEnd
= m_aGroupPositions
.end();
665 for(++aFind
;aFind
!= aEnd
;++aFind
)
666 if ( *aFind
!= NO_GROUP
)
674 void SAL_CALL
OFieldExpressionControl::elementReplaced(const container::ContainerEvent
& /*evt*/) throw(uno::RuntimeException
, std::exception
)
678 void SAL_CALL
OFieldExpressionControl::elementRemoved(const container::ContainerEvent
& evt
) throw(uno::RuntimeException
, std::exception
)
680 SolarMutexGuard aSolarGuard
;
681 ::osl::MutexGuard
aGuard( m_aMutex
);
683 if ( m_bIgnoreEvent
)
686 sal_Int32 nGroupPos
= 0;
687 if ( evt
.Accessor
>>= nGroupPos
)
689 ::std::vector
<sal_Int32
>::iterator aFind
= ::std::find(m_aGroupPositions
.begin(),m_aGroupPositions
.end(),nGroupPos
);
690 if ( aFind
!= m_aGroupPositions
.end() )
693 ::std::vector
<sal_Int32
>::iterator aEnd
= m_aGroupPositions
.end();
694 for(++aFind
;aFind
!= aEnd
;++aFind
)
695 if ( *aFind
!= NO_GROUP
)
702 bool OFieldExpressionControl::IsDeleteAllowed( )
704 return !m_pParent
->isReadOnly() && GetSelectRowCount() > 0;
707 void OFieldExpressionControl::KeyInput( const KeyEvent
& rEvt
)
709 if (IsDeleteAllowed())
711 if (rEvt
.GetKeyCode().GetCode() == KEY_DELETE
&& // Delete rows
712 !rEvt
.GetKeyCode().IsShift() &&
713 !rEvt
.GetKeyCode().IsMod1())
719 EditBrowseBox::KeyInput(rEvt
);
722 void OFieldExpressionControl::Command(const CommandEvent
& rEvt
)
724 switch (rEvt
.GetCommand())
726 case CommandEventId::ContextMenu
:
728 if (!rEvt
.IsMouseEvent())
730 EditBrowseBox::Command(rEvt
);
734 sal_uInt16 nColId
= GetColumnAtXPosPixel(rEvt
.GetMousePosPixel().X());
736 if ( nColId
== HANDLE_ID
)
738 PopupMenu
aContextMenu(ModuleRes(RID_GROUPSROWPOPUPMENU
));
739 bool bEnable
= false;
740 long nIndex
= FirstSelectedRow();
741 while( nIndex
>= 0 && !bEnable
)
743 if ( m_aGroupPositions
[nIndex
] != NO_GROUP
)
745 nIndex
= NextSelectedRow();
747 aContextMenu
.EnableItem( SID_DELETE
, IsDeleteAllowed() && bEnable
);
748 switch (aContextMenu
.Execute(this, rEvt
.GetMousePosPixel()))
762 Application::RemoveUserEvent( m_nDeleteEvent
);
763 m_nDeleteEvent
= Application::PostUserEvent( LINK(this, OFieldExpressionControl
, DelayedDelete
), NULL
, true );
772 EditBrowseBox::Command(rEvt
);
777 void OFieldExpressionControl::DeleteRows()
780 bool bIsEditing
= IsEditing();
785 long nIndex
= FirstSelectedRow();
788 nIndex
= GetCurRow();
790 bool bFirstTime
= true;
792 long nOldDataPos
= nIndex
;
793 uno::Sequence
< beans::PropertyValue
> aArgs(1);
794 aArgs
[0].Name
= PROPERTY_GROUP
;
795 m_bIgnoreEvent
= true;
798 if ( m_aGroupPositions
[nIndex
] != NO_GROUP
)
803 OUString
sUndoAction(ModuleRes(RID_STR_UNDO_REMOVE_SELECTION
));
804 m_pParent
->m_pController
->getUndoManager().EnterListAction( sUndoAction
, OUString() );
807 sal_Int32 nGroupPos
= m_aGroupPositions
[nIndex
];
808 uno::Reference
< report::XGroup
> xGroup
= m_pParent
->getGroup(nGroupPos
);
809 aArgs
[0].Value
<<= xGroup
;
810 // we use this way to create undo actions
811 m_pParent
->m_pController
->executeChecked(SID_GROUP_REMOVE
,aArgs
);
813 ::std::vector
<sal_Int32
>::iterator aFind
= ::std::find(m_aGroupPositions
.begin(),m_aGroupPositions
.end(),nGroupPos
);
814 if (aFind
!= m_aGroupPositions
.end())
817 ::std::vector
<sal_Int32
>::iterator aEnd
= m_aGroupPositions
.end();
818 for(++aFind
;aFind
!= aEnd
;++aFind
)
819 if ( *aFind
!= NO_GROUP
)
823 nIndex
= NextSelectedRow();
827 m_pParent
->m_pController
->getUndoManager().LeaveListAction();
829 m_nDataPos
= GetCurRow();
830 InvalidateStatusCell( nOldDataPos
);
831 InvalidateStatusCell( m_nDataPos
);
833 m_pParent
->DisplayData( m_nDataPos
);
834 m_bIgnoreEvent
= false;
839 void OFieldExpressionControl::cut()
846 void OFieldExpressionControl::copy()
849 // set to the right row and save it
850 m_pParent
->SaveData( m_nDataPos
);
852 uno::Sequence
<uno::Any
> aClipboardList
= fillSelectedGroups();
854 if( aClipboardList
.getLength() )
856 OGroupExchange
* pData
= new OGroupExchange(aClipboardList
);
857 uno::Reference
< ::com::sun::star::datatransfer::XTransferable
> xRef
= pData
;
858 pData
->CopyToClipboard(GetParent());
863 void OFieldExpressionControl::paste()
865 TransferableDataHelper
aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
866 if(aTransferData
.HasFormat(OGroupExchange::getReportGroupId()))
869 Application::RemoveUserEvent( m_nPasteEvent
);
870 m_nPasteEvent
= Application::PostUserEvent( LINK(this, OFieldExpressionControl
, DelayedPaste
), NULL
, true );
874 IMPL_LINK_NOARG( OFieldExpressionControl
, DelayedPaste
)
878 sal_Int32 nPastePosition
= GetSelectRowCount() ? FirstSelectedRow() : GetCurRow();
880 InsertRows( nPastePosition
);
882 GoToRow( nPastePosition
);
887 IMPL_LINK_NOARG( OFieldExpressionControl
, DelayedDelete
)
894 void OFieldExpressionControl::InsertRows( long nRow
)
899 // get rows from clipboard
900 TransferableDataHelper
aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
901 if(aTransferData
.HasFormat(OGroupExchange::getReportGroupId()))
903 datatransfer::DataFlavor aFlavor
;
904 SotExchange::GetFormatDataFlavor(OGroupExchange::getReportGroupId(), aFlavor
);
905 uno::Sequence
< uno::Any
> aGroups
;
907 if ((aTransferData
.GetAny(aFlavor
, OUString()) >>= aGroups
) && aGroups
.getLength())
909 m_bIgnoreEvent
= false;
911 const OUString
sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP
));
912 const UndoContext
aUndoContext( m_pParent
->m_pController
->getUndoManager(), sUndoAction
);
914 uno::Reference
<report::XGroups
> xGroups
= m_pParent
->getGroups();
915 sal_Int32 nGroupPos
= 0;
916 ::std::vector
<sal_Int32
>::iterator aIter
= m_aGroupPositions
.begin();
917 ::std::vector
<sal_Int32
>::size_type nRowPos
= static_cast< ::std::vector
<sal_Int32
>::size_type
>(nRow
);
918 if ( nRowPos
< m_aGroupPositions
.size() )
920 ::std::vector
<sal_Int32
>::iterator aEnd
= m_aGroupPositions
.begin() + nRowPos
;
921 for(;aIter
!= aEnd
;++aIter
)
923 if ( *aIter
!= NO_GROUP
)
927 for(sal_Int32 i
=0;i
< aGroups
.getLength();++i
,++nSize
)
929 uno::Sequence
< beans::PropertyValue
> aArgs(2);
930 aArgs
[0].Name
= PROPERTY_GROUP
;
931 aArgs
[0].Value
= aGroups
[i
];
932 aArgs
[1].Name
= PROPERTY_POSITIONY
;
933 aArgs
[1].Value
<<= nGroupPos
;
934 m_pParent
->m_pController
->executeChecked(SID_GROUP_APPEND
,aArgs
);
936 ::std::vector
<sal_Int32
>::iterator aInsertPos
= m_aGroupPositions
.insert(aIter
,nGroupPos
);
939 ::std::vector
<sal_Int32
>::iterator aEnd
= m_aGroupPositions
.end();
940 for(;aInsertPos
!= aEnd
;++aInsertPos
)
941 if ( *aInsertPos
!= NO_GROUP
)
945 m_bIgnoreEvent
= true;
949 RowInserted( nRow
, nSize
, true );
952 Size
OFieldExpressionControl::GetOptimalSize() const
954 return LogicToPixel(Size(106, 75), MAP_APPFONT
);
957 // class OGroupsSortingDialog
958 OGroupsSortingDialog::OGroupsSortingDialog(vcl::Window
* _pParent
, bool _bReadOnly
,
959 OReportController
* _pController
)
960 : FloatingWindow(_pParent
, "FloatingSort", "modules/dbreport/ui/floatingsort.ui")
961 , OPropertyChangeListener(m_aMutex
)
962 , m_pController(_pController
)
963 , m_pCurrentGroupListener(NULL
)
964 , m_xGroups(m_pController
->getReportDefinition()->getGroups())
965 , m_bReadOnly(_bReadOnly
)
967 get(m_pToolBox
, "toolbox");
968 m_nMoveUpId
= m_pToolBox
->GetItemId(0);
969 m_nMoveDownId
= m_pToolBox
->GetItemId(1);
970 m_nDeleteId
= m_pToolBox
->GetItemId(2);
971 get(m_pOrderLst
, "sorting");
972 get(m_pHeaderLst
, "header");
973 get(m_pFooterLst
, "footer");
974 get(m_pGroupOnLst
, "group");
975 get(m_pGroupIntervalEd
, "interval");
976 get(m_pKeepTogetherLst
, "keep");
977 get(m_pHelpWindow
, "helptext");
978 m_pHelpWindow
->set_height_request(GetTextHeight() * 4);
979 get(m_pProperties
, "properties");
980 m_pFieldExpression
= VclPtr
<OFieldExpressionControl
>::Create(this, get
<vcl::Window
>("box"));
981 m_pFieldExpression
->set_hexpand(true);
982 m_pFieldExpression
->set_vexpand(true);
984 Control
* pControlsLst
[] = { m_pHeaderLst
, m_pFooterLst
, m_pGroupOnLst
, m_pKeepTogetherLst
, m_pOrderLst
, m_pGroupIntervalEd
};
985 for (size_t i
= 0; i
< sizeof (pControlsLst
) / sizeof (pControlsLst
[0]); ++i
)
987 pControlsLst
[i
]->SetGetFocusHdl(LINK(this, OGroupsSortingDialog
, OnControlFocusGot
));
988 pControlsLst
[i
]->SetLoseFocusHdl(LINK(this, OGroupsSortingDialog
, OnControlFocusLost
));
989 pControlsLst
[i
]->Show(true);
992 for (size_t i
= 0; i
< (sizeof (pControlsLst
) / sizeof (pControlsLst
[0])) - 1; ++i
)
993 static_cast<ListBox
*>(pControlsLst
[i
])->SetSelectHdl(LINK(this,OGroupsSortingDialog
,LBChangeHdl
));
995 m_pReportListener
= new OPropertyChangeMultiplexer(this,m_pController
->getReportDefinition().get());
996 m_pReportListener
->addProperty(PROPERTY_COMMAND
);
997 m_pReportListener
->addProperty(PROPERTY_COMMANDTYPE
);
999 m_pFieldExpression
->lateInit();
1001 m_pFieldExpression
->Show();
1003 m_pHelpWindow
->SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
1005 m_pToolBox
->SetStyle(m_pToolBox
->GetStyle()|WB_LINESPACING
);
1006 m_pToolBox
->SetSelectHdl(LINK(this, OGroupsSortingDialog
, OnFormatAction
));
1013 OGroupsSortingDialog::~OGroupsSortingDialog()
1018 void OGroupsSortingDialog::dispose()
1021 m_pReportListener
->dispose();
1022 if ( m_pCurrentGroupListener
.is() )
1023 m_pCurrentGroupListener
->dispose();
1025 m_pProperties
.clear();
1026 m_pOrderLst
.clear();
1027 m_pHeaderLst
.clear();
1028 m_pFooterLst
.clear();
1029 m_pGroupOnLst
.clear();
1030 m_pGroupIntervalEd
.clear();
1031 m_pKeepTogetherLst
.clear();
1032 m_pHelpWindow
.clear();
1033 m_pFieldExpression
.disposeAndClear();
1034 FloatingWindow::dispose();
1037 void OGroupsSortingDialog::UpdateData( )
1039 m_pFieldExpression
->Invalidate();
1040 long nCurRow
= m_pFieldExpression
->GetCurRow();
1041 m_pFieldExpression
->DeactivateCell();
1042 m_pFieldExpression
->ActivateCell(nCurRow
, m_pFieldExpression
->GetCurColumnId());
1043 DisplayData(nCurRow
);
1046 void OGroupsSortingDialog::DisplayData( sal_Int32 _nRow
)
1048 sal_Int32 nGroupPos
= m_pFieldExpression
->getGroupPosition(_nRow
);
1049 bool bEmpty
= nGroupPos
== NO_GROUP
;
1050 m_pProperties
->Enable(!bEmpty
);
1052 checkButtons(_nRow
);
1054 if ( m_pCurrentGroupListener
.is() )
1055 m_pCurrentGroupListener
->dispose();
1056 m_pCurrentGroupListener
= NULL
;
1057 if ( !bEmpty
&& nGroupPos
!= NO_GROUP
)
1059 uno::Reference
< report::XGroup
> xGroup
= getGroup(nGroupPos
);
1061 m_pCurrentGroupListener
= new OPropertyChangeMultiplexer(this,xGroup
.get());
1062 m_pCurrentGroupListener
->addProperty(PROPERTY_HEADERON
);
1063 m_pCurrentGroupListener
->addProperty(PROPERTY_FOOTERON
);
1065 displayGroup(xGroup
);
1069 void OGroupsSortingDialog::SaveData( sal_Int32 _nRow
)
1071 sal_Int32 nGroupPos
= m_pFieldExpression
->getGroupPosition(_nRow
);
1072 if ( nGroupPos
== NO_GROUP
)
1075 uno::Reference
< report::XGroup
> xGroup
= getGroup(nGroupPos
);
1076 if ( m_pHeaderLst
->IsValueChangedFromSaved() )
1077 xGroup
->setHeaderOn( m_pHeaderLst
->GetSelectEntryPos() == 0 );
1078 if ( m_pFooterLst
->IsValueChangedFromSaved() )
1079 xGroup
->setFooterOn( m_pFooterLst
->GetSelectEntryPos() == 0 );
1080 if ( m_pKeepTogetherLst
->IsValueChangedFromSaved() )
1081 xGroup
->setKeepTogether( m_pKeepTogetherLst
->GetSelectEntryPos() );
1082 if ( m_pGroupOnLst
->IsValueChangedFromSaved() )
1084 sal_Int16 nGroupOn
= static_cast<sal_Int16
>(reinterpret_cast<sal_IntPtr
>(m_pGroupOnLst
->GetSelectEntryData()));
1085 xGroup
->setGroupOn( nGroupOn
);
1087 if ( m_pGroupIntervalEd
->IsValueChangedFromSaved() )
1089 xGroup
->setGroupInterval( static_cast<sal_Int32
>(m_pGroupIntervalEd
->GetValue()) );
1090 m_pGroupIntervalEd
->SaveValue();
1092 if ( m_pOrderLst
->IsValueChangedFromSaved() )
1093 xGroup
->setSortAscending( m_pOrderLst
->GetSelectEntryPos() == 0 );
1095 ListBox
* pControls
[] = { m_pHeaderLst
, m_pFooterLst
, m_pGroupOnLst
, m_pKeepTogetherLst
, m_pOrderLst
};
1096 for (size_t i
= 0; i
< sizeof(pControls
)/sizeof(pControls
[0]); ++i
)
1097 pControls
[i
]->SaveValue();
1101 sal_Int32
OGroupsSortingDialog::getColumnDataType(const OUString
& _sColumnName
)
1103 sal_Int32 nDataType
= sdbc::DataType::VARCHAR
;
1106 if ( !m_xColumns
.is() )
1108 if ( m_xColumns
.is() && m_xColumns
->hasByName(_sColumnName
) )
1110 uno::Reference
< beans::XPropertySet
> xColumn(m_xColumns
->getByName(_sColumnName
),uno::UNO_QUERY
);
1112 xColumn
->getPropertyValue(PROPERTY_TYPE
) >>= nDataType
;
1115 catch(uno::Exception
&)
1117 OSL_FAIL("Exception caught while getting the type of a column");
1123 IMPL_LINK(OGroupsSortingDialog
, OnControlFocusGot
, Control
*, pControl
)
1125 if ( m_pFieldExpression
&& m_pFieldExpression
->getExpressionControl() )
1127 Control
* pControls
[] = { m_pFieldExpression
->getExpressionControl(), m_pHeaderLst
, m_pFooterLst
, m_pGroupOnLst
, m_pGroupIntervalEd
, m_pKeepTogetherLst
, m_pOrderLst
};
1128 for (size_t i
= 0; i
< sizeof(pControls
)/sizeof(pControls
[0]); ++i
)
1130 if ( pControl
== pControls
[i
] )
1132 ListBox
* pListBox
= dynamic_cast< ListBox
* >( pControl
);
1134 pListBox
->SaveValue();
1135 NumericField
* pNumericField
= dynamic_cast< NumericField
* >( pControl
);
1136 if ( pNumericField
)
1137 pNumericField
->SaveValue();
1138 showHelpText(static_cast<sal_uInt16
>(i
+STR_RPT_HELP_FIELD
));
1146 IMPL_LINK(OGroupsSortingDialog
, OnControlFocusLost
, Control
*, pControl
)
1148 if (m_pFieldExpression
&& pControl
== m_pGroupIntervalEd
)
1150 if ( m_pGroupIntervalEd
->IsModified() )
1151 SaveData(m_pFieldExpression
->GetCurRow());
1156 IMPL_LINK_NOARG_TYPED( OGroupsSortingDialog
, OnFormatAction
, ToolBox
*, void )
1159 sal_uInt16 nCommand
= m_pToolBox
->GetCurItemId();
1161 if ( m_pFieldExpression
)
1163 long nIndex
= m_pFieldExpression
->GetCurrRow();
1164 sal_Int32 nGroupPos
= m_pFieldExpression
->getGroupPosition(nIndex
);
1165 uno::Sequence
<uno::Any
> aClipboardList
;
1166 if ( nIndex
>= 0 && nGroupPos
!= NO_GROUP
)
1168 aClipboardList
.realloc(1);
1169 aClipboardList
[0] = m_xGroups
->getByIndex(nGroupPos
);
1171 if ( nCommand
== m_nMoveUpId
)
1175 if ( nCommand
== m_nMoveDownId
)
1179 if ( nCommand
== m_nDeleteId
)
1181 Application::PostUserEvent( LINK(m_pFieldExpression
, OFieldExpressionControl
, DelayedDelete
), NULL
, true );
1185 if ( nIndex
>= 0 && aClipboardList
.getLength() )
1187 m_pFieldExpression
->SetNoSelection();
1188 m_pFieldExpression
->moveGroups(aClipboardList
,nIndex
,false);
1189 m_pFieldExpression
->DeactivateCell();
1190 m_pFieldExpression
->GoToRow(nIndex
);
1191 m_pFieldExpression
->ActivateCell(nIndex
, m_pFieldExpression
->GetCurColumnId());
1192 DisplayData(nIndex
);
1198 IMPL_LINK( OGroupsSortingDialog
, LBChangeHdl
, ListBox
*, pListBox
)
1200 if ( pListBox
->IsValueChangedFromSaved() )
1202 sal_Int32 nRow
= m_pFieldExpression
->GetCurRow();
1203 sal_Int32 nGroupPos
= m_pFieldExpression
->getGroupPosition(nRow
);
1204 if (pListBox
!= m_pHeaderLst
&& pListBox
!= m_pFooterLst
)
1206 if ( pListBox
->IsValueChangedFromSaved() )
1208 if ( pListBox
== m_pGroupOnLst
)
1209 m_pGroupIntervalEd
->Enable( pListBox
->GetSelectEntryPos() != 0 );
1211 else if ( nGroupPos
!= NO_GROUP
)
1213 uno::Reference
< report::XGroup
> xGroup
= getGroup(nGroupPos
);
1214 uno::Sequence
< beans::PropertyValue
> aArgs(2);
1215 aArgs
[1].Name
= PROPERTY_GROUP
;
1216 aArgs
[1].Value
<<= xGroup
;
1218 if ( m_pHeaderLst
== pListBox
)
1219 aArgs
[0].Name
= PROPERTY_HEADERON
;
1221 aArgs
[0].Name
= PROPERTY_FOOTERON
;
1223 aArgs
[0].Value
<<= pListBox
->GetSelectEntryPos() == 0;
1224 m_pController
->executeChecked(m_pHeaderLst
== pListBox
? SID_GROUPHEADER
: SID_GROUPFOOTER
,aArgs
);
1225 m_pFieldExpression
->InvalidateHandleColumn();
1231 void OGroupsSortingDialog::showHelpText(sal_uInt16 _nResId
)
1233 m_pHelpWindow
->SetText(OUString(ModuleRes(_nResId
)));
1236 void OGroupsSortingDialog::_propertyChanged(const beans::PropertyChangeEvent
& _rEvent
) throw(uno::RuntimeException
, std::exception
)
1238 uno::Reference
< report::XGroup
> xGroup(_rEvent
.Source
,uno::UNO_QUERY
);
1240 displayGroup(xGroup
);
1245 void OGroupsSortingDialog::fillColumns()
1247 m_xColumns
= m_pController
->getColumns();
1248 m_pFieldExpression
->fillColumns(m_xColumns
);
1251 void OGroupsSortingDialog::displayGroup(const uno::Reference
<report::XGroup
>& _xGroup
)
1253 m_pHeaderLst
->SelectEntryPos(_xGroup
->getHeaderOn() ? 0 : 1 );
1254 m_pFooterLst
->SelectEntryPos(_xGroup
->getFooterOn() ? 0 : 1 );
1255 sal_Int32 nDataType
= getColumnDataType(_xGroup
->getExpression());
1257 // first clear whole group on list
1258 while(m_pGroupOnLst
->GetEntryCount() > 1 )
1260 m_pGroupOnLst
->RemoveEntry(1);
1265 case sdbc::DataType::LONGVARCHAR
:
1266 case sdbc::DataType::VARCHAR
:
1267 case sdbc::DataType::CHAR
:
1268 m_pGroupOnLst
->InsertEntry(OUString(ModuleRes(STR_RPT_PREFIXCHARS
)));
1269 m_pGroupOnLst
->SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::PREFIX_CHARACTERS
));
1271 case sdbc::DataType::DATE
:
1272 case sdbc::DataType::TIME
:
1273 case sdbc::DataType::TIMESTAMP
:
1275 sal_uInt16 nIds
[] = { STR_RPT_YEAR
, STR_RPT_QUARTER
,STR_RPT_MONTH
,STR_RPT_WEEK
,STR_RPT_DAY
,STR_RPT_HOUR
,STR_RPT_MINUTE
};
1276 for (sal_uInt16 i
= 0; i
< sizeof (nIds
) / sizeof (nIds
[0]); ++i
)
1278 m_pGroupOnLst
->InsertEntry(OUString(ModuleRes(nIds
[i
])));
1279 m_pGroupOnLst
->SetEntryData(i
+1,reinterpret_cast<void*>(i
+2));
1284 m_pGroupOnLst
->InsertEntry(OUString(ModuleRes(STR_RPT_INTERVAL
)));
1285 m_pGroupOnLst
->SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::INTERVAL
));
1289 switch(_xGroup
->getGroupOn())
1291 case report::GroupOn::DEFAULT
:
1294 case report::GroupOn::PREFIX_CHARACTERS
:
1297 case report::GroupOn::YEAR
:
1300 case report::GroupOn::QUARTAL
:
1303 case report::GroupOn::MONTH
:
1306 case report::GroupOn::WEEK
:
1309 case report::GroupOn::DAY
:
1312 case report::GroupOn::HOUR
:
1315 case report::GroupOn::MINUTE
:
1318 case report::GroupOn::INTERVAL
:
1324 m_pGroupOnLst
->SelectEntryPos(nPos
);
1325 m_pGroupIntervalEd
->SetText(OUString::number(_xGroup
->getGroupInterval()));
1326 m_pGroupIntervalEd
->SaveValue();
1327 m_pGroupIntervalEd
->Enable( nPos
!= 0 );
1328 m_pKeepTogetherLst
->SelectEntryPos(_xGroup
->getKeepTogether());
1329 m_pOrderLst
->SelectEntryPos(_xGroup
->getSortAscending() ? 0 : 1);
1331 ListBox
* pControls
[] = { m_pHeaderLst
, m_pFooterLst
, m_pGroupOnLst
, m_pKeepTogetherLst
, m_pOrderLst
};
1332 for (size_t i
= 0; i
< sizeof(pControls
)/sizeof(pControls
[0]); ++i
)
1333 pControls
[i
]->SaveValue();
1335 ListBox
* pControlsLst2
[] = { m_pHeaderLst
, m_pFooterLst
, m_pGroupOnLst
, m_pKeepTogetherLst
, m_pOrderLst
};
1336 bool bReadOnly
= !m_pController
->isEditable();
1337 for (size_t i
= 0; i
< sizeof(pControlsLst2
)/sizeof(pControlsLst2
[0]); ++i
)
1338 pControlsLst2
[i
]->SetReadOnly(bReadOnly
);
1339 m_pGroupIntervalEd
->SetReadOnly(bReadOnly
);
1342 void OGroupsSortingDialog::checkButtons(sal_Int32 _nRow
)
1344 sal_Int32 nGroupCount
= m_xGroups
->getCount();
1345 sal_Int32 nRowCount
= m_pFieldExpression
->GetRowCount();
1346 bool bEnabled
= nGroupCount
> 1;
1348 if (bEnabled
&& _nRow
> 0 )
1350 m_pToolBox
->EnableItem(m_nMoveUpId
, true);
1354 m_pToolBox
->EnableItem(m_nMoveUpId
, false);
1356 if (bEnabled
&& _nRow
< (nRowCount
- 1) )
1358 m_pToolBox
->EnableItem(m_nMoveDownId
, true);
1362 m_pToolBox
->EnableItem(m_nMoveDownId
, false);
1365 sal_Int32 nGroupPos
= m_pFieldExpression
->getGroupPosition(_nRow
);
1366 if ( nGroupPos
!= NO_GROUP
)
1368 bool bEnableDelete
= nGroupCount
> 0;
1369 m_pToolBox
->EnableItem(m_nDeleteId
, bEnableDelete
);
1373 m_pToolBox
->EnableItem(m_nDeleteId
, false);
1379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */