sync master with lastest vba changes
[ooovba.git] / reportdesign / source / ui / dlg / GroupsSorting.cxx
blob2dfcd75fc470dcb85b4ee112098b84962d9bf774
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: GroupsSorting.cxx,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "GroupsSorting.hxx"
32 #include "GroupsSorting.hrc"
33 #include <connectivity/dbtools.hxx>
34 #include <svtools/editbrowsebox.hxx>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/container/XContainerListener.hpp>
37 #include <com/sun/star/report/GroupOn.hpp>
38 #include <com/sun/star/sdbc/DataType.hpp>
40 #include <tools/debug.hxx>
41 #include "RptResId.hrc"
42 #include "rptui_slotid.hrc"
43 #include "ModuleHelper.hxx"
44 #include "helpids.hrc"
46 #include <svx/globlmn.hrc>
47 #include <svx/svxids.hrc>
49 #include "GroupExchange.hxx"
50 #include "UITools.hxx"
51 #include "UndoActions.hxx"
52 #include "uistrings.hrc"
53 #include "ReportController.hxx"
55 #include <cppuhelper/implbase1.hxx>
56 #include <comphelper/property.hxx>
57 #include <vcl/mnemonic.hxx>
58 #include <vcl/msgbox.hxx>
59 #include <algorithm>
60 #include <boost/bind.hpp>
62 #define HANDLE_ID 0
63 #define FIELD_EXPRESSION 1
64 #define GROUPS_START_LEN 5
65 #define NO_GROUP -1
67 namespace rptui
69 using namespace ::com::sun::star;
70 using namespace svt;
71 using namespace ::comphelper;
73 typedef ::svt::EditBrowseBox OFieldExpressionControl_Base;
74 typedef ::cppu::WeakImplHelper1< container::XContainerListener > TContainerListenerBase;
75 class OFieldExpressionControl : public TContainerListenerBase
76 ,public OFieldExpressionControl_Base
78 ::osl::Mutex m_aMutex;
79 ::std::vector<sal_Int32> m_aGroupPositions;
80 ::svt::ComboBoxControl* m_pComboCell;
81 sal_Int32 m_nDataPos;
82 sal_Int32 m_nCurrentPos;
83 ULONG m_nPasteEvent;
84 ULONG m_nDeleteEvent;
85 OGroupsSortingDialog* m_pParent;
86 bool m_bIgnoreEvent;
89 void fillListBox(const uno::Reference< beans::XPropertySet>& _xDest,long nRow,USHORT nColumnId);
90 BOOL SaveModified(bool _bAppend);
92 OFieldExpressionControl(const OFieldExpressionControl&);
93 void operator =(const OFieldExpressionControl&);
94 public:
95 OFieldExpressionControl( OGroupsSortingDialog* _pParent,const ResId& _rResId);
96 virtual ~OFieldExpressionControl();
98 // XEventListener
99 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
100 // XContainerListener
101 virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
102 virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
103 virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
105 void fillColumns(const uno::Reference< container::XNameAccess>& _xColumns);
106 void lateInit();
107 sal_Bool IsDeleteAllowed( );
108 void DeleteRows();
109 void cut();
110 void copy();
111 void paste();
113 inline sal_Int32 getGroupPosition(sal_Int32 _nRow) const { return _nRow != BROWSER_ENDOFSELECTION ? m_aGroupPositions[_nRow] : sal_Int32(NO_GROUP); }
115 inline ::svt::ComboBoxControl* getExpressionControl() const { return m_pComboCell; }
118 /** returns the sequence with the selected groups
120 uno::Sequence<uno::Any> fillSelectedGroups();
122 /** move groups given by _aGroups
124 void moveGroups(const uno::Sequence<uno::Any>& _aGroups,sal_Int32 _nRow,sal_Bool _bSelect = sal_True);
126 virtual BOOL CursorMoving(long nNewRow, USHORT nNewCol);
127 using OFieldExpressionControl_Base::GetRowCount;
128 protected:
129 virtual BOOL IsTabAllowed(BOOL bForward) const;
132 virtual void InitController( ::svt::CellControllerRef& rController, long nRow, USHORT nCol );
133 virtual ::svt::CellController* GetController( long nRow, USHORT nCol );
134 virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColId ) const;
135 virtual BOOL SeekRow( long nRow );
136 virtual BOOL SaveModified();
137 virtual String GetCellText( long nRow, USHORT nColId ) const;
138 virtual RowStatus GetRowStatus(long nRow) const;
140 virtual void KeyInput(const KeyEvent& rEvt);
141 virtual void Command( const CommandEvent& rEvt );
143 // D&D
144 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel );
145 virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt );
146 virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt );
148 using BrowseBox::AcceptDrop;
149 using BrowseBox::ExecuteDrop;
151 private:
153 DECL_LINK( AsynchActivate, void* );
154 DECL_LINK( AsynchDeactivate, void* );
155 DECL_LINK( DelayedPaste, void* );
156 DECL_LINK( DelayedDelete, void* );
157 DECL_LINK( CBChangeHdl,ComboBox*);
159 void InsertRows( long nRow );
161 //========================================================================
162 // class OFieldExpressionControl
163 //========================================================================
164 DBG_NAME( rpt_OFieldExpressionControl )
165 //------------------------------------------------------------------------
166 OFieldExpressionControl::OFieldExpressionControl( OGroupsSortingDialog* _pParent,const ResId& _rResId )
167 :EditBrowseBox( _pParent, _rResId,EBBF_NONE, WB_TABSTOP | BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_AUTOSIZE_LASTCOL |
168 BROWSER_KEEPSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL)
169 ,m_aGroupPositions(GROUPS_START_LEN,-1)
170 ,m_pComboCell(NULL)
171 ,m_nDataPos(-1)
172 ,m_nCurrentPos(-1)
173 ,m_nPasteEvent(0)
174 ,m_nDeleteEvent(0)
175 ,m_pParent(_pParent)
176 ,m_bIgnoreEvent(false)
178 DBG_CTOR( rpt_OFieldExpressionControl,NULL);
179 SetBorderStyle(WINDOW_BORDER_MONO);
182 //------------------------------------------------------------------------
183 OFieldExpressionControl::~OFieldExpressionControl()
185 acquire();
186 uno::Reference< report::XGroups > xGroups = m_pParent->getGroups();
187 xGroups->removeContainerListener(this);
188 //////////////////////////////////////////////////////////////////////
189 // delete events from queue
190 if( m_nPasteEvent )
191 Application::RemoveUserEvent( m_nPasteEvent );
192 if( m_nDeleteEvent )
193 Application::RemoveUserEvent( m_nDeleteEvent );
195 delete m_pComboCell;
196 DBG_DTOR( rpt_OFieldExpressionControl,NULL);
198 //------------------------------------------------------------------------------
199 uno::Sequence<uno::Any> OFieldExpressionControl::fillSelectedGroups()
201 uno::Sequence<uno::Any> aList;
202 ::std::vector<uno::Any> vClipboardList;
203 vClipboardList.reserve(GetSelectRowCount());
205 uno::Reference<report::XGroups> xGroups = m_pParent->getGroups();
206 sal_Int32 nCount = xGroups->getCount();
207 if ( nCount >= 1 )
209 for( long nIndex=FirstSelectedRow(); nIndex >= 0 ; nIndex=NextSelectedRow() )
213 if ( m_aGroupPositions[nIndex] != NO_GROUP )
215 uno::Reference< report::XGroup> xOrgGroup(xGroups->getByIndex(m_aGroupPositions[nIndex]),uno::UNO_QUERY);
216 /*uno::Reference< report::XGroup> xCopy = xGroups->createGroup();
217 ::comphelper::copyProperties(xOrgGroup.get(),xCopy.get());*/
218 vClipboardList.push_back( uno::makeAny(xOrgGroup) );
221 catch(uno::Exception&)
223 OSL_ENSURE(0,"Can not access group!");
226 if ( !vClipboardList.empty() )
227 aList = uno::Sequence< uno::Any >(&vClipboardList[0], vClipboardList.size());
228 } // if ( nCount > 1 )
229 return aList;
231 //------------------------------------------------------------------------------
232 void OFieldExpressionControl::StartDrag( sal_Int8 /*_nAction*/ , const Point& /*_rPosPixel*/ )
234 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
235 if ( m_pParent && !m_pParent->isReadOnly( ) )
237 uno::Sequence<uno::Any> aClipboardList = fillSelectedGroups();
239 if( aClipboardList.getLength() )
241 OGroupExchange* pData = new OGroupExchange(aClipboardList);
242 uno::Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
243 pData->StartDrag(this, DND_ACTION_MOVE );
244 } // if(!vClipboardList.empty())
247 //------------------------------------------------------------------------------
248 sal_Int8 OFieldExpressionControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
250 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
251 sal_Int8 nAction = DND_ACTION_NONE;
252 if ( IsEditing() )
254 USHORT nPos = m_pComboCell->GetSelectEntryPos();
255 if ( COMBOBOX_ENTRY_NOTFOUND != nPos || m_pComboCell->GetText().Len() )
256 SaveModified();
257 DeactivateCell();
259 if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) && m_pParent->getGroups()->getCount() > 1 && rEvt.GetWindow() == &GetDataWindow() )
261 nAction = DND_ACTION_MOVE;
263 return nAction;
265 //------------------------------------------------------------------------------
266 sal_Int8 OFieldExpressionControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
268 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
269 sal_Int8 nAction = DND_ACTION_NONE;
270 if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) )
272 sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
273 SetNoSelection();
275 TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
276 uno::Any aDrop = aDropped.GetAny(OGroupExchange::getReportGroupId());
277 uno::Sequence< uno::Any > aGroups;
278 aDrop >>= aGroups;
279 if ( aGroups.getLength() )
281 moveGroups(aGroups,nRow);
282 nAction = DND_ACTION_MOVE;
285 return nAction;
287 //------------------------------------------------------------------------------
288 void OFieldExpressionControl::moveGroups(const uno::Sequence<uno::Any>& _aGroups,sal_Int32 _nRow,sal_Bool _bSelect)
290 if ( _aGroups.getLength() )
292 m_bIgnoreEvent = true;
294 sal_Int32 nRow = _nRow;
295 String sUndoAction(ModuleRes(RID_STR_UNDO_MOVE_GROUP));
296 UndoManagerListAction aListAction(*m_pParent->m_pController->getUndoMgr(),sUndoAction);
298 uno::Reference< report::XGroups> xGroups = m_pParent->getGroups();
299 const uno::Any* pIter = _aGroups.getConstArray();
300 const uno::Any* pEnd = pIter + _aGroups.getLength();
301 for(;pIter != pEnd;++pIter)
303 uno::Reference< report::XGroup> xGroup(*pIter,uno::UNO_QUERY);
304 if ( xGroup.is() )
306 uno::Sequence< beans::PropertyValue > aArgs(1);
307 aArgs[0].Name = PROPERTY_GROUP;
308 aArgs[0].Value <<= xGroup;
309 // we use this way to create undo actions
310 m_pParent->m_pController->executeChecked(SID_GROUP_REMOVE,aArgs);
311 aArgs.realloc(2);
312 if ( nRow > xGroups->getCount() )
313 nRow = xGroups->getCount();
314 if ( _bSelect )
315 SelectRow(nRow);
316 aArgs[1].Name = PROPERTY_POSITIONY;
317 aArgs[1].Value <<= nRow;
318 m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
319 ++nRow;
321 } // for(;pIter != pEnd;++pIter)
323 m_bIgnoreEvent = false;
324 Invalidate();
325 } // if ( _aGroups.getLength() )
327 // -----------------------------------------------------------------------------
328 void OFieldExpressionControl::fillColumns(const uno::Reference< container::XNameAccess>& _xColumns)
330 m_pComboCell->Clear();
331 if ( _xColumns.is() )
333 uno::Sequence< ::rtl::OUString> aColumnNames = _xColumns->getElementNames();
334 const ::rtl::OUString* pIter = aColumnNames.getConstArray();
335 const ::rtl::OUString* pEnd = pIter + aColumnNames.getLength();
336 for(;pIter != pEnd;++pIter)
337 m_pComboCell->InsertEntry(*pIter);
338 } // if ( _xColumns.is() )
340 //------------------------------------------------------------------------------
341 void OFieldExpressionControl::lateInit()
343 uno::Reference< report::XGroups > xGroups = m_pParent->getGroups();
344 sal_Int32 nGroupsCount = xGroups->getCount();
345 m_aGroupPositions.resize(::std::max<sal_Int32>(nGroupsCount,sal_Int32(GROUPS_START_LEN)),NO_GROUP);
346 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
347 for (sal_Int32 i = 0; i < nGroupsCount; ++i,++aIter)
348 *aIter = i;
350 if ( ColCount() == 0 )
352 Font aFont( GetDataWindow().GetFont() );
353 aFont.SetWeight( WEIGHT_NORMAL );
354 GetDataWindow().SetFont( aFont );
356 // Font fuer die Ueberschriften auf Light setzen
357 aFont = GetFont();
358 aFont.SetWeight( WEIGHT_LIGHT );
359 SetFont(aFont);
361 InsertHandleColumn(static_cast<USHORT>(GetTextWidth('0') * 4)/*, TRUE */);
362 InsertDataColumn( FIELD_EXPRESSION, String(ModuleRes(STR_RPT_EXPRESSION)), 100);
364 m_pComboCell = new ComboBoxControl( &GetDataWindow() );
365 m_pComboCell->SetSelectHdl(LINK(this,OFieldExpressionControl,CBChangeHdl));
366 m_pComboCell->SetHelpId(HID_RPT_FIELDEXPRESSION);
368 Control* pControls[] = {m_pComboCell};
369 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
371 pControls[i]->SetGetFocusHdl(LINK(m_pParent, OGroupsSortingDialog, OnControlFocusGot));
372 pControls[i]->SetLoseFocusHdl(LINK(m_pParent, OGroupsSortingDialog, OnControlFocusLost));
375 //////////////////////////////////////////////////////////////////////
376 // set browse mode
377 BrowserMode nMode(BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_KEEPSELECTION |
378 BROWSER_HLINESFULL | BROWSER_VLINESFULL | BROWSER_AUTOSIZE_LASTCOL | BROWSER_AUTO_VSCROLL | BROWSER_AUTO_HSCROLL);
379 if( m_pParent->isReadOnly() )
380 nMode |= BROWSER_HIDECURSOR;
381 SetMode(nMode);
382 xGroups->addContainerListener(this);
384 else
385 // not the first call
386 RowRemoved(0, GetRowCount());
388 RowInserted(0, m_aGroupPositions.size(), TRUE);
390 // -----------------------------------------------------------------------------
391 // -----------------------------------------------------------------------------
392 IMPL_LINK( OFieldExpressionControl, CBChangeHdl, ComboBox*, /*pComboBox*/ )
394 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
396 SaveModified();
397 return 0L;
399 //------------------------------------------------------------------------------
400 IMPL_LINK(OFieldExpressionControl, AsynchActivate, void*, EMPTYARG)
402 ActivateCell();
403 return 0L;
406 //------------------------------------------------------------------------------
407 IMPL_LINK(OFieldExpressionControl, AsynchDeactivate, void*, EMPTYARG)
409 DeactivateCell();
410 return 0L;
413 //------------------------------------------------------------------------------
414 BOOL OFieldExpressionControl::IsTabAllowed(BOOL /*bForward*/) const
416 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
417 return FALSE;
420 //------------------------------------------------------------------------------
421 BOOL OFieldExpressionControl::SaveModified()
423 return SaveModified(true);
425 //------------------------------------------------------------------------------
426 BOOL OFieldExpressionControl::SaveModified(bool _bAppendRow)
428 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
429 sal_Int32 nRow = GetCurRow();
430 if ( nRow != BROWSER_ENDOFSELECTION )
432 sal_Bool bAppend = sal_False;
435 uno::Reference< report::XGroup> xGroup;
436 if ( m_aGroupPositions[nRow] == NO_GROUP )
438 bAppend = sal_True;
439 String sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP));
440 m_pParent->m_pController->getUndoMgr()->EnterListAction( sUndoAction, String() );
441 xGroup = m_pParent->getGroups()->createGroup();
442 xGroup->setHeaderOn(sal_True);
444 uno::Sequence< beans::PropertyValue > aArgs(2);
445 aArgs[0].Name = PROPERTY_GROUP;
446 aArgs[0].Value <<= xGroup;
447 // find position where to insert the new group
448 sal_Int32 nGroupPos = 0;
449 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
450 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.begin() + nRow;
451 for(;aIter != aEnd;++aIter)
452 if ( *aIter != NO_GROUP )
453 nGroupPos = *aIter + 1;
454 aArgs[1].Name = PROPERTY_POSITIONY;
455 aArgs[1].Value <<= nGroupPos;
456 m_bIgnoreEvent = true;
457 m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
458 m_bIgnoreEvent = false;
459 OSL_ENSURE(*aIter == NO_GROUP ,"Illegal iterator!");
460 *aIter++ = nGroupPos;
462 aEnd = m_aGroupPositions.end();
463 for(;aIter != aEnd;++aIter)
464 if ( *aIter != NO_GROUP )
465 ++*aIter;
467 else
468 xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
469 if ( xGroup.is() )
471 USHORT nPos = m_pComboCell->GetSelectEntryPos();
472 ::rtl::OUString sExpression;
473 if ( COMBOBOX_ENTRY_NOTFOUND == nPos )
474 sExpression = m_pComboCell->GetText();
475 else
477 sExpression = m_pComboCell->GetEntry(nPos);
479 xGroup->setExpression( sExpression );
481 ::rptui::adjustSectionName(xGroup,nPos);
483 if ( bAppend )
484 m_pParent->m_pController->getUndoMgr()->LeaveListAction();
487 if ( Controller() )
488 Controller()->ClearModified();
489 if ( _bAppendRow && GetRowCount() == m_pParent->getGroups()->getCount() )
491 RowInserted( GetRowCount()-1);
492 m_aGroupPositions.push_back(NO_GROUP);
495 GoToRow(nRow);
496 m_pParent->DisplayData(nRow);
498 catch(uno::Exception&)
500 OSL_ENSURE(0,"OFieldExpressionControl::SaveModified: Exception caught!");
504 return TRUE;
506 //------------------------------------------------------------------------------
507 String OFieldExpressionControl::GetCellText( long nRow, USHORT /*nColId*/ ) const
509 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
510 String sText;
511 if ( nRow != BROWSER_ENDOFSELECTION && m_aGroupPositions[nRow] != NO_GROUP )
515 uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
516 sText = xGroup->getExpression();
518 catch(uno::Exception&)
520 OSL_ENSURE(0,"Exception caught while getting expression value from the group");
522 } // if ( nRow != BROWSER_ENDOFSELECTION && nRow < m_pParent->getGroups()->getCount() )
523 return sText;
526 //------------------------------------------------------------------------------
527 void OFieldExpressionControl::InitController( CellControllerRef& /*rController*/, long nRow, USHORT nColumnId )
529 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
531 m_pComboCell->SetText( GetCellText( nRow, nColumnId ) );
533 //------------------------------------------------------------------------------
534 sal_Bool OFieldExpressionControl::CursorMoving(long nNewRow, sal_uInt16 nNewCol)
536 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
538 if (!EditBrowseBox::CursorMoving(nNewRow, nNewCol))
539 return sal_False;
540 m_nDataPos = nNewRow;
541 long nOldDataPos = GetCurRow();
542 InvalidateStatusCell( m_nDataPos );
543 InvalidateStatusCell( nOldDataPos );
545 m_pParent->SaveData( nOldDataPos );
546 m_pParent->DisplayData( m_nDataPos );
547 return sal_True;
549 //------------------------------------------------------------------------------
550 CellController* OFieldExpressionControl::GetController( long /*nRow*/, USHORT /*nColumnId*/ )
552 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
553 ComboBoxCellController* pCellController = new ComboBoxCellController( m_pComboCell );
554 pCellController->GetComboBox().SetReadOnly(!m_pParent->m_pController->isEditable());
555 return pCellController;
558 //------------------------------------------------------------------------------
559 BOOL OFieldExpressionControl::SeekRow( long _nRow )
561 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
562 // die Basisklasse braucht den Aufruf, da sie sich dort merkt, welche Zeile gepainted wird
563 EditBrowseBox::SeekRow(_nRow);
564 m_nCurrentPos = _nRow;
565 return TRUE;
568 //------------------------------------------------------------------------------
569 void OFieldExpressionControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColumnId ) const
571 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
572 String aText =const_cast< OFieldExpressionControl*>(this)->GetCellText( m_nCurrentPos, nColumnId );
574 Point aPos( rRect.TopLeft() );
575 Size aTextSize( GetDataWindow().GetTextHeight(),GetDataWindow().GetTextWidth( aText ));
577 if( aPos.X() < rRect.Right() || aPos.X() + aTextSize.Width() > rRect.Right() ||
578 aPos.Y() < rRect.Top() || aPos.Y() + aTextSize.Height() > rRect.Bottom() )
579 rDev.SetClipRegion( rRect );
581 rDev.DrawText( aPos, aText );
583 if( rDev.IsClipRegion() )
584 rDev.SetClipRegion();
586 //------------------------------------------------------------------------------
587 EditBrowseBox::RowStatus OFieldExpressionControl::GetRowStatus(long nRow) const
589 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
590 if (nRow >= 0 && nRow == m_nDataPos)
591 return EditBrowseBox::CURRENT;
592 if ( nRow != BROWSER_ENDOFSELECTION && nRow < static_cast<long>(m_aGroupPositions.size()) && m_aGroupPositions[nRow] != NO_GROUP )
596 uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
597 return (xGroup->getHeaderOn() || xGroup->getFooterOn())? EditBrowseBox::HEADERFOOTER : EditBrowseBox::CLEAN;
599 catch(uno::Exception&)
601 OSL_ENSURE(0,"Exception cathced while try to get a group!");
604 return EditBrowseBox::CLEAN;
606 // XEventListener
607 //------------------------------------------------------------------------------
608 void SAL_CALL OFieldExpressionControl::disposing(const lang::EventObject& /*e*/) throw( uno::RuntimeException )
611 //------------------------------------------------------------------------------
612 // XContainerListener
613 //------------------------------------------------------------------------------
614 void SAL_CALL OFieldExpressionControl::elementInserted(const container::ContainerEvent& evt) throw(uno::RuntimeException)
616 if ( m_bIgnoreEvent )
617 return;
618 ::vos::OClearableGuard aSolarGuard( Application::GetSolarMutex() );
619 ::osl::MutexGuard aGuard( m_aMutex );
620 sal_Int32 nGroupPos = 0;
621 if ( evt.Accessor >>= nGroupPos )
623 if ( nGroupPos >= GetRowCount() )
625 sal_Int32 nAddedRows = nGroupPos - GetRowCount();
626 RowInserted(nAddedRows);
627 for (sal_Int32 i = 0; i < nAddedRows; ++i)
628 m_aGroupPositions.push_back(NO_GROUP);
629 m_aGroupPositions[nGroupPos] = nGroupPos;
631 else
633 ::std::vector<sal_Int32>::iterator aFind = m_aGroupPositions.begin()+ nGroupPos;
634 if ( aFind == m_aGroupPositions.end() )
635 aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),NO_GROUP);
637 if ( aFind != m_aGroupPositions.end() )
639 if ( *aFind != NO_GROUP )
640 aFind = m_aGroupPositions.insert(aFind,nGroupPos);
641 else
642 *aFind = nGroupPos;
644 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
645 for(++aFind;aFind != aEnd;++aFind)
646 if ( *aFind != NO_GROUP )
647 ++*aFind;
649 //::std::vector<sal_Int32>::reverse_iterator aRIter = m_aGroupPositions.rbegin();
650 //::std::vector<sal_Int32>::reverse_iterator aREnd = m_aGroupPositions.rend();
651 //for (; aRIter != aREnd && *aRIter != NO_GROUP; ++aRIter)
652 // continue;
653 //if ( aRIter != aREnd )
654 // m_aGroupPositions.erase(m_aGroupPositions.begin() + (m_aGroupPositions.size() - 1 - (aRIter - m_aGroupPositions.rbegin())));
657 Invalidate();
660 //------------------------------------------------------------------------------
661 void SAL_CALL OFieldExpressionControl::elementReplaced(const container::ContainerEvent& /*evt*/) throw(uno::RuntimeException)
664 //------------------------------------------------------------------------------
665 void SAL_CALL OFieldExpressionControl::elementRemoved(const container::ContainerEvent& evt) throw(uno::RuntimeException)
667 ::vos::OClearableGuard aSolarGuard( Application::GetSolarMutex() );
668 ::osl::MutexGuard aGuard( m_aMutex );
670 if ( m_bIgnoreEvent )
671 return;
673 sal_Int32 nGroupPos = 0;
674 if ( evt.Accessor >>= nGroupPos )
676 ::std::vector<sal_Int32>::iterator aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),nGroupPos);
677 if ( aFind != m_aGroupPositions.end() )
679 *aFind = NO_GROUP;
680 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
681 for(++aFind;aFind != aEnd;++aFind)
682 if ( *aFind != NO_GROUP )
683 --*aFind;
684 //PaintCell(*this,GetFieldRect(FIELD_EXPRESSION),FIELD_EXPRESSION);
685 Invalidate();
689 //------------------------------------------------------------------------------
690 sal_Bool OFieldExpressionControl::IsDeleteAllowed( )
692 return !m_pParent->isReadOnly() && GetSelectRowCount() > 0;
694 //------------------------------------------------------------------------
695 void OFieldExpressionControl::KeyInput( const KeyEvent& rEvt )
697 if (IsDeleteAllowed())
699 if (rEvt.GetKeyCode().GetCode() == KEY_DELETE && // Delete rows
700 !rEvt.GetKeyCode().IsShift() &&
701 !rEvt.GetKeyCode().IsMod1())
703 DeleteRows();
704 return;
707 EditBrowseBox::KeyInput(rEvt);
709 //------------------------------------------------------------------------
710 void OFieldExpressionControl::Command(const CommandEvent& rEvt)
712 switch (rEvt.GetCommand())
714 case COMMAND_CONTEXTMENU:
716 if (!rEvt.IsMouseEvent())
718 EditBrowseBox::Command(rEvt);
719 return;
722 USHORT nColId = GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X());
724 if ( nColId == HANDLE_ID )
726 //long nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
727 PopupMenu aContextMenu(ModuleRes(RID_GROUPSROWPOPUPMENU));
728 sal_Bool bEnable = sal_False;
729 long nIndex = FirstSelectedRow();
730 while( nIndex >= 0 && !bEnable )
732 if ( m_aGroupPositions[nIndex] != NO_GROUP )
733 bEnable = sal_True;
734 nIndex = NextSelectedRow();
736 //aContextMenu.EnableItem( SID_CUT, IsDeleteAllowed() && bEnable);
737 //aContextMenu.EnableItem( SID_COPY, bEnable);
738 //TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
739 //aContextMenu.EnableItem( SID_PASTE, aTransferData.HasFormat(SOT_FORMATSTR_ID_RPT_GRPED) );
740 aContextMenu.EnableItem( SID_DELETE, IsDeleteAllowed() && bEnable );
741 switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
743 case SID_CUT:
744 cut();
745 break;
746 case SID_COPY:
747 copy();
748 break;
749 case SID_PASTE:
750 paste();
751 break;
753 case SID_DELETE:
754 if( m_nDeleteEvent )
755 Application::RemoveUserEvent( m_nDeleteEvent );
756 m_nDeleteEvent = Application::PostUserEvent( LINK(this, OFieldExpressionControl, DelayedDelete) );
757 break;
758 default:
759 break;
761 } // if ( nColId == HANDLE_ID )
762 // run through
764 default:
765 EditBrowseBox::Command(rEvt);
769 //------------------------------------------------------------------------------
770 void OFieldExpressionControl::DeleteRows()
772 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
774 long nIndex = FirstSelectedRow();
775 bool bFirstTime = true;
777 long nOldDataPos = nIndex;
778 uno::Sequence< beans::PropertyValue > aArgs(1);
779 aArgs[0].Name = PROPERTY_GROUP;
780 m_bIgnoreEvent = true;
781 while( nIndex >= 0 )
783 if ( m_aGroupPositions[nIndex] != NO_GROUP )
785 if ( bFirstTime )
787 bFirstTime = false;
788 String sUndoAction(ModuleRes(RID_STR_UNDO_REMOVE_SELECTION));
789 m_pParent->m_pController->getUndoMgr()->EnterListAction( sUndoAction, String() );
792 sal_Int32 nGroupPos = m_aGroupPositions[nIndex];
793 uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(nGroupPos);
794 aArgs[0].Value <<= xGroup;
795 // we use this way to create undo actions
796 m_pParent->m_pController->executeChecked(SID_GROUP_REMOVE,aArgs);
798 ::std::vector<sal_Int32>::iterator aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),nGroupPos);
799 *aFind = NO_GROUP;
800 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
801 for(++aFind;aFind != aEnd;++aFind)
802 if ( *aFind != NO_GROUP )
803 --*aFind;
805 nIndex = NextSelectedRow();
806 } // while( nIndex >= 0 )
808 if ( !bFirstTime )
809 m_pParent->m_pController->getUndoMgr()->LeaveListAction();
811 m_nDataPos = GetCurRow();
812 InvalidateStatusCell( nOldDataPos );
813 InvalidateStatusCell( m_nDataPos );
814 ActivateCell();
815 m_pParent->DisplayData( m_nDataPos );
816 m_bIgnoreEvent = false;
817 Invalidate();
819 //------------------------------------------------------------------------------
820 //------------------------------------------------------------------------------
821 void OFieldExpressionControl::cut()
823 copy();
824 DeleteRows();
827 //------------------------------------------------------------------------------
828 void OFieldExpressionControl::copy()
830 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
831 //////////////////////////////////////////////////////////////////////
832 // set to the right row and save it
833 m_pParent->SaveData( m_nDataPos );
835 uno::Sequence<uno::Any> aClipboardList = fillSelectedGroups();
837 if( aClipboardList.getLength() )
839 OGroupExchange* pData = new OGroupExchange(aClipboardList);
840 uno::Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
841 pData->CopyToClipboard(GetParent());
845 //------------------------------------------------------------------------------
846 void OFieldExpressionControl::paste()
848 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
849 if(aTransferData.HasFormat(OGroupExchange::getReportGroupId()))
851 if( m_nPasteEvent )
852 Application::RemoveUserEvent( m_nPasteEvent );
853 m_nPasteEvent = Application::PostUserEvent( LINK(this, OFieldExpressionControl, DelayedPaste) );
856 //------------------------------------------------------------------------------
857 IMPL_LINK( OFieldExpressionControl, DelayedPaste, void*, )
859 m_nPasteEvent = 0;
861 sal_Int32 nPastePosition = GetSelectRowCount() ? FirstSelectedRow() : GetCurRow();
863 InsertRows( nPastePosition );
864 SetNoSelection();
865 GoToRow( nPastePosition );
867 return 0;
869 //------------------------------------------------------------------------------
870 IMPL_LINK( OFieldExpressionControl, DelayedDelete, void*, )
872 m_nDeleteEvent = 0;
873 DeleteRows();
874 return 0;
876 //------------------------------------------------------------------------------
877 void OFieldExpressionControl::InsertRows( long nRow )
879 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
881 sal_Int32 nSize = 0;
882 //////////////////////////////////////////////////////////////////////
883 // get rows from clipboard
884 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
885 if(aTransferData.HasFormat(OGroupExchange::getReportGroupId()))
887 datatransfer::DataFlavor aFlavor;
888 SotExchange::GetFormatDataFlavor(OGroupExchange::getReportGroupId(), aFlavor);
889 uno::Sequence< uno::Any > aGroups;
891 if( (aTransferData.GetAny(aFlavor) >>= aGroups) && aGroups.getLength() )
893 m_bIgnoreEvent = false;
895 String sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP));
896 UndoManagerListAction aListAction(*m_pParent->m_pController->getUndoMgr(),sUndoAction);
898 uno::Reference<report::XGroups> xGroups = m_pParent->getGroups();
899 sal_Int32 nGroupPos = 0;
900 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
901 ::std::vector<sal_Int32>::size_type nRowPos = static_cast< ::std::vector<sal_Int32>::size_type >(nRow);
902 if ( nRowPos < m_aGroupPositions.size() )
904 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.begin() + nRowPos;
905 for(;aIter != aEnd;++aIter)
907 if ( *aIter != NO_GROUP )
908 nGroupPos = *aIter;
911 for(sal_Int32 i=0;i < aGroups.getLength();++i,++nSize)
913 uno::Sequence< beans::PropertyValue > aArgs(2);
914 aArgs[0].Name = PROPERTY_GROUP;
915 aArgs[0].Value = aGroups[i];
916 aArgs[1].Name = PROPERTY_POSITIONY;
917 aArgs[1].Value <<= nGroupPos;
918 m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
920 ::std::vector<sal_Int32>::iterator aInsertPos = m_aGroupPositions.insert(aIter,nGroupPos);
921 ++aInsertPos;
922 aIter = aInsertPos;
923 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
924 for(;aInsertPos != aEnd;++aInsertPos)
925 if ( *aInsertPos != NO_GROUP )
926 ++*aInsertPos;
929 m_bIgnoreEvent = true;
933 RowInserted( nRow,nSize,sal_True );
935 //------------------------------------------------------------------------------
937 DBG_NAME( rpt_OGroupsSortingDialog )
938 //========================================================================
939 // class OGroupsSortingDialog
940 //========================================================================
941 OGroupsSortingDialog::OGroupsSortingDialog( Window* _pParent
942 ,sal_Bool _bReadOnly
943 ,OReportController* _pController)
944 : FloatingWindow( _pParent, ModuleRes(RID_GROUPS_SORTING) )
945 ,OPropertyChangeListener(m_aMutex)
946 ,m_aFL2(this, ModuleRes(FL_SEPARATOR2) )
947 ,m_aMove(this, ModuleRes(FT_MOVELABEL) )
948 ,m_aUp(this, ModuleRes(PB_UP) )
949 ,m_aDown(this, ModuleRes(PB_DOWN) )
950 ,m_aFL3(this, ModuleRes(FL_SEPARATOR3) )
951 ,m_aOrder(this, ModuleRes(FT_ORDER) )
952 ,m_aOrderLst(this, ModuleRes(LST_ORDER) )
953 ,m_aHeader(this, ModuleRes(FT_HEADER) )
954 ,m_aHeaderLst(this, ModuleRes(LST_HEADERLST) )
955 ,m_aFooter(this, ModuleRes(FT_FOOTER) )
956 ,m_aFooterLst(this, ModuleRes(LST_FOOTERLST) )
957 ,m_aGroupOn(this, ModuleRes(FT_GROUPON) )
958 ,m_aGroupOnLst(this, ModuleRes(LST_GROUPONLST) )
959 ,m_aGroupInterval(this, ModuleRes(FT_GROUPINTERVAL) )
960 ,m_aGroupIntervalEd(this, ModuleRes(ED_GROUPINTERVALLST) )
961 ,m_aKeepTogether(this, ModuleRes(FT_KEEPTOGETHER) )
962 ,m_aKeepTogetherLst(this, ModuleRes(LST_KEEPTOGETHERLST) )
963 ,m_aFL(this, ModuleRes(FL_SEPARATOR1) )
964 ,m_aHelpWindow(this, ModuleRes(HELP_FIELD) )
965 ,m_pFieldExpression( new OFieldExpressionControl(this,ModuleRes(WND_CONTROL)))
966 ,m_pController(_pController)
967 ,m_pCurrentGroupListener(NULL)
968 ,m_xGroups(m_pController->getReportDefinition()->getGroups())
969 ,m_bReadOnly(_bReadOnly)
971 DBG_CTOR( rpt_OGroupsSortingDialog,NULL);
974 Control* pControlsLst[] = { &m_aHeaderLst, &m_aFooterLst, &m_aGroupOnLst, &m_aKeepTogetherLst, &m_aOrderLst, &m_aGroupIntervalEd};
975 for (size_t i = 0; i < sizeof(pControlsLst)/sizeof(pControlsLst[0]); ++i)
977 pControlsLst[i]->SetGetFocusHdl(LINK(this, OGroupsSortingDialog, OnControlFocusGot));
978 pControlsLst[i]->SetLoseFocusHdl(LINK(this, OGroupsSortingDialog, OnControlFocusLost));
979 pControlsLst[i]->Show(TRUE);
980 } // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
982 for (size_t i = 0; i < (sizeof(pControlsLst)/sizeof(pControlsLst[0]))-1; ++i)
983 static_cast<ListBox*>(pControlsLst[i])->SetSelectHdl(LINK(this,OGroupsSortingDialog,LBChangeHdl));
985 Control* pControls[] = { &m_aHeader, &m_aFooter, &m_aGroupOn, &m_aGroupInterval, &m_aKeepTogether, &m_aOrder
986 , &m_aMove,&m_aFL2};
987 sal_Int32 nMaxTextWidth = 0;
988 MnemonicGenerator aMnemonicGenerator;
989 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
990 aMnemonicGenerator.RegisterMnemonic( pControls[i]->GetText() );
992 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
994 pControls[i]->Show(TRUE);
995 String sText = pControls[i]->GetText();
996 if ( aMnemonicGenerator.CreateMnemonic(sText) )
997 pControls[i]->SetText(sText);
998 sal_Int32 nTextWidth = GetTextWidth(sText);
999 nMaxTextWidth = ::std::max<sal_Int32>(nTextWidth,nMaxTextWidth);
1002 Size aSpace = LogicToPixel( Size( UNRELATED_CONTROLS, PAGE_HEIGHT), MAP_APPFONT );
1003 Size aOutSize(nMaxTextWidth + m_aHeader.GetSizePixel().Width() + 3*aSpace.Width(),aSpace.Height());
1004 SetMinOutputSizePixel(aOutSize);
1005 SetOutputSizePixel(aOutSize);
1006 Resize();
1008 m_pReportListener = new OPropertyChangeMultiplexer(this,m_pController->getReportDefinition().get());
1009 m_pReportListener->addProperty(PROPERTY_COMMAND);
1010 m_pReportListener->addProperty(PROPERTY_COMMANDTYPE);
1012 m_pFieldExpression->lateInit();
1013 fillColumns();
1014 m_pFieldExpression->Show();
1016 //m_aHelpWindow.SetReadOnly();
1017 m_aHelpWindow.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
1018 m_aUp.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1019 m_aDown.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1021 m_pFieldExpression->SetZOrder(&m_aFL2, WINDOW_ZORDER_BEHIND);
1023 m_aMove.SetZOrder(m_pFieldExpression, WINDOW_ZORDER_BEHIND);
1024 m_aUp.SetZOrder(&m_aMove, WINDOW_ZORDER_BEHIND);
1025 m_aDown.SetZOrder(&m_aUp, WINDOW_ZORDER_BEHIND);
1026 // set Hi contrast bitmaps
1027 m_aUp.SetModeImage( ModuleRes(IMG_UP_H),BMP_COLOR_HIGHCONTRAST);
1028 m_aDown.SetModeImage( ModuleRes(IMG_DOWN_H),BMP_COLOR_HIGHCONTRAST);
1030 checkButtons(0);
1032 FreeResource();
1035 //------------------------------------------------------------------------
1036 OGroupsSortingDialog::~OGroupsSortingDialog()
1038 DBG_DTOR( rpt_OGroupsSortingDialog,NULL);
1039 delete m_pFieldExpression;
1040 m_xColumns.clear();
1041 m_pReportListener->dispose();
1042 if ( m_pCurrentGroupListener.is() )
1043 m_pCurrentGroupListener->dispose();
1045 // -----------------------------------------------------------------------------
1046 sal_Bool OGroupsSortingDialog::isReadOnly( ) const
1048 return m_bReadOnly;
1050 //------------------------------------------------------------------------------
1051 void OGroupsSortingDialog::UpdateData( )
1053 m_pFieldExpression->Invalidate();
1054 long nCurRow = m_pFieldExpression->GetCurRow();
1055 m_pFieldExpression->DeactivateCell();
1056 m_pFieldExpression->ActivateCell(nCurRow, m_pFieldExpression->GetCurColumnId());
1057 DisplayData(nCurRow);
1059 //------------------------------------------------------------------------------
1060 void OGroupsSortingDialog::DisplayData( sal_Int32 _nRow )
1062 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1063 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1064 sal_Bool bEmpty = nGroupPos == NO_GROUP;
1065 m_aHeaderLst.Enable(!bEmpty);
1066 m_aFooterLst.Enable(!bEmpty);
1067 m_aGroupOnLst.Enable(!bEmpty);
1068 m_aGroupIntervalEd.Enable(!bEmpty);
1069 m_aKeepTogetherLst.Enable(!bEmpty);
1070 m_aOrderLst.Enable(!bEmpty);
1072 m_aFL3.Enable(!bEmpty);
1073 m_aHeader.Enable(!bEmpty);
1074 m_aFooter.Enable(!bEmpty);
1075 m_aGroupOn.Enable(!bEmpty);
1076 m_aGroupInterval.Enable(!bEmpty);
1077 m_aKeepTogether.Enable(!bEmpty);
1078 m_aOrder.Enable(!bEmpty);
1080 checkButtons(_nRow);
1082 if ( m_pCurrentGroupListener.is() )
1083 m_pCurrentGroupListener->dispose();
1084 m_pCurrentGroupListener = NULL;
1085 if ( !bEmpty && nGroupPos != NO_GROUP )
1087 uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1089 m_pCurrentGroupListener = new OPropertyChangeMultiplexer(this,xGroup.get());
1090 m_pCurrentGroupListener->addProperty(PROPERTY_HEADERON);
1091 m_pCurrentGroupListener->addProperty(PROPERTY_FOOTERON);
1093 displayGroup(xGroup);
1096 //------------------------------------------------------------------------------
1097 void OGroupsSortingDialog::SaveData( sal_Int32 _nRow)
1099 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1100 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1101 if ( nGroupPos == NO_GROUP )
1102 return;
1104 uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1105 if ( m_aHeaderLst.GetSavedValue() != m_aHeaderLst.GetSelectEntryPos() )
1106 xGroup->setHeaderOn( m_aHeaderLst.GetSelectEntryPos() == 0 );
1107 if ( m_aFooterLst.GetSavedValue() != m_aFooterLst.GetSelectEntryPos() )
1108 xGroup->setFooterOn( m_aFooterLst.GetSelectEntryPos() == 0 );
1109 if ( m_aKeepTogetherLst.GetSavedValue() != m_aKeepTogetherLst.GetSelectEntryPos() )
1110 xGroup->setKeepTogether( m_aKeepTogetherLst.GetSelectEntryPos() );
1111 if ( m_aGroupOnLst.GetSavedValue() != m_aGroupOnLst.GetSelectEntryPos() )
1113 sal_Int16 nGroupOn = static_cast<sal_Int16>(reinterpret_cast<sal_IntPtr>(m_aGroupOnLst.GetEntryData(m_aGroupOnLst.GetSelectEntryPos())));
1114 xGroup->setGroupOn( nGroupOn );
1116 if ( m_aGroupIntervalEd.GetSavedValue().ToInt32() != m_aGroupIntervalEd.GetValue() )
1118 xGroup->setGroupInterval( static_cast<sal_Int32>(m_aGroupIntervalEd.GetValue()) );
1119 m_aGroupIntervalEd.SaveValue();
1121 if ( m_aOrderLst.GetSavedValue() != m_aOrderLst.GetSelectEntryPos() )
1122 xGroup->setSortAscending( m_aOrderLst.GetSelectEntryPos() == 0 );
1124 ListBox* pControls[] = { &m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aKeepTogetherLst,&m_aOrderLst};
1125 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1126 pControls[i]->SaveValue();
1129 // -----------------------------------------------------------------------------
1130 sal_Int32 OGroupsSortingDialog::getColumnDataType(const ::rtl::OUString& _sColumnName)
1132 sal_Int32 nDataType = sdbc::DataType::VARCHAR;
1135 if ( !m_xColumns.is() )
1136 fillColumns();
1137 if ( m_xColumns.is() && m_xColumns->hasByName(_sColumnName) )
1139 uno::Reference< beans::XPropertySet> xColumn(m_xColumns->getByName(_sColumnName),uno::UNO_QUERY);
1140 if ( xColumn.is() )
1141 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
1144 catch(uno::Exception&)
1146 OSL_ENSURE(0,"Eception caught while getting the type of a column");
1149 return nDataType;
1151 //------------------------------------------------------------------------------
1152 IMPL_LINK(OGroupsSortingDialog, OnControlFocusGot, Control*, pControl )
1154 if ( m_pFieldExpression && m_pFieldExpression->getExpressionControl() )
1156 Control* pControls[] = { m_pFieldExpression->getExpressionControl(),&m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aGroupIntervalEd,&m_aKeepTogetherLst,&m_aOrderLst};
1157 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1159 if ( pControl == pControls[i] )
1161 ListBox* pListBox = dynamic_cast< ListBox* >( pControl );
1162 if ( pListBox )
1163 pListBox->SaveValue();
1164 NumericField* pNumericField = dynamic_cast< NumericField* >( pControl );
1165 if ( pNumericField )
1166 pNumericField->SaveValue();
1167 showHelpText(static_cast<USHORT>(i+STR_RPT_HELP_FIELD));
1168 break;
1172 return 0L;
1174 //------------------------------------------------------------------------------
1175 IMPL_LINK(OGroupsSortingDialog, OnControlFocusLost, Control*, pControl )
1177 if ( m_pFieldExpression && pControl == &m_aGroupIntervalEd )
1179 if ( m_aGroupIntervalEd.IsModified() )
1180 SaveData(m_pFieldExpression->GetCurRow());
1182 return 0L;
1184 // -----------------------------------------------------------------------------
1185 IMPL_LINK( OGroupsSortingDialog, ClickHdl, ImageButton*, _pButton )
1187 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1188 if ( m_pFieldExpression )
1190 long nIndex = m_pFieldExpression->GetCurrRow();
1191 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(nIndex);
1192 uno::Sequence<uno::Any> aClipboardList;
1193 if ( nIndex >= 0 && nGroupPos != NO_GROUP )
1195 aClipboardList.realloc(1);
1196 aClipboardList[0] = m_xGroups->getByIndex(nGroupPos);
1198 if ( _pButton == &m_aUp )
1199 --nIndex;
1200 else
1201 ++nIndex;
1203 if ( nIndex >= 0 && aClipboardList.getLength() )
1205 m_pFieldExpression->SetNoSelection();
1206 m_pFieldExpression->moveGroups(aClipboardList,nIndex,sal_False);
1207 m_pFieldExpression->DeactivateCell();
1208 m_pFieldExpression->GoToRow(nIndex);
1209 //long nCurRow = m_pFieldExpression->GetCurRow();
1210 m_pFieldExpression->ActivateCell(nIndex, m_pFieldExpression->GetCurColumnId());
1211 DisplayData(nIndex);
1214 return 1L;
1216 // -----------------------------------------------------------------------------
1217 IMPL_LINK( OGroupsSortingDialog, LBChangeHdl, ListBox*, pListBox )
1219 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1220 if ( pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
1222 sal_Int32 nRow = m_pFieldExpression->GetCurRow();
1223 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(nRow);
1224 if ( pListBox != &m_aHeaderLst && pListBox != &m_aFooterLst)
1226 if ( pListBox && pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
1227 SaveData(nRow);
1228 if ( pListBox == &m_aGroupOnLst )
1229 m_aGroupIntervalEd.Enable( pListBox->GetSelectEntryPos() != 0 );
1231 else if ( nGroupPos != NO_GROUP )
1233 uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1234 uno::Sequence< beans::PropertyValue > aArgs(2);
1235 aArgs[1].Name = PROPERTY_GROUP;
1236 aArgs[1].Value <<= xGroup;
1238 if ( &m_aHeaderLst == pListBox )
1239 aArgs[0].Name = PROPERTY_HEADERON;
1240 else
1241 aArgs[0].Name = PROPERTY_FOOTERON;
1243 aArgs[0].Value <<= pListBox->GetSelectEntryPos() == 0;
1244 m_pController->executeChecked(&m_aHeaderLst == pListBox ? SID_GROUPHEADER : SID_GROUPFOOTER,aArgs);
1245 if ( m_pFieldExpression )
1246 m_pFieldExpression->InvalidateHandleColumn();
1249 return 1L;
1251 // -----------------------------------------------------------------------------
1252 void OGroupsSortingDialog::showHelpText(USHORT _nResId)
1254 m_aHelpWindow.SetText(String(ModuleRes(_nResId)));
1256 // -----------------------------------------------------------------------------
1257 void OGroupsSortingDialog::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
1259 uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
1260 if ( xGroup.is() )
1261 displayGroup(xGroup);
1262 else
1263 fillColumns();
1265 // -----------------------------------------------------------------------------
1266 void OGroupsSortingDialog::fillColumns()
1268 m_xColumns.clear();
1269 uno::Reference< report::XReportDefinition> xReport = m_pController->getReportDefinition();
1270 if ( xReport->getCommand().getLength() )
1271 m_xColumns = dbtools::getFieldsByCommandDescriptor(m_pController->getConnection(),xReport->getCommandType(),xReport->getCommand(),m_xHoldAlive);
1272 m_pFieldExpression->fillColumns(m_xColumns);
1274 // -----------------------------------------------------------------------------
1275 void OGroupsSortingDialog::displayGroup(const uno::Reference<report::XGroup>& _xGroup)
1277 m_aHeaderLst.SelectEntryPos(_xGroup->getHeaderOn() ? 0 : 1 );
1278 m_aFooterLst.SelectEntryPos(_xGroup->getFooterOn() ? 0 : 1 );
1279 sal_Int32 nDataType = getColumnDataType(_xGroup->getExpression());
1281 // first clear whole group on list
1282 while(m_aGroupOnLst.GetEntryCount() > 1 )
1284 m_aGroupOnLst.RemoveEntry(1);
1287 switch(nDataType)
1289 case sdbc::DataType::LONGVARCHAR:
1290 case sdbc::DataType::VARCHAR:
1291 case sdbc::DataType::CHAR:
1292 m_aGroupOnLst.InsertEntry(String(ModuleRes(STR_RPT_PREFIXCHARS)));
1293 m_aGroupOnLst.SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::PREFIX_CHARACTERS));
1294 break;
1295 case sdbc::DataType::DATE:
1296 case sdbc::DataType::TIME:
1297 case sdbc::DataType::TIMESTAMP:
1299 USHORT nIds[] = { STR_RPT_YEAR, STR_RPT_QUARTER,STR_RPT_MONTH,STR_RPT_WEEK,STR_RPT_DAY,STR_RPT_HOUR,STR_RPT_MINUTE };
1300 for (USHORT i = 0; i < sizeof(nIds)/sizeof(nIds[0]); ++i)
1302 m_aGroupOnLst.InsertEntry(String(ModuleRes(nIds[i])));
1303 m_aGroupOnLst.SetEntryData(i+1,reinterpret_cast<void*>(i+2));
1306 break;
1307 default:
1308 m_aGroupOnLst.InsertEntry(String(ModuleRes(STR_RPT_INTERVAL)));
1309 m_aGroupOnLst.SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::INTERVAL));
1310 break;
1311 } // switch(nDataType)
1312 USHORT nPos = 0;
1313 switch(_xGroup->getGroupOn())
1315 case report::GroupOn::DEFAULT:
1316 nPos = 0;
1317 break;
1318 case report::GroupOn::PREFIX_CHARACTERS:
1319 nPos = 1;
1320 break;
1321 case report::GroupOn::YEAR:
1322 nPos = 1;
1323 break;
1324 case report::GroupOn::QUARTAL:
1325 nPos = 2;
1326 break;
1327 case report::GroupOn::MONTH:
1328 nPos = 3;
1329 break;
1330 case report::GroupOn::WEEK:
1331 nPos = 4;
1332 break;
1333 case report::GroupOn::DAY:
1334 nPos = 5;
1335 break;
1336 case report::GroupOn::HOUR:
1337 nPos = 6;
1338 break;
1339 case report::GroupOn::MINUTE:
1340 nPos = 7;
1341 break;
1342 case report::GroupOn::INTERVAL:
1343 nPos = 1;
1344 break;
1345 default:
1346 nPos = 0;
1348 m_aGroupOnLst.SelectEntryPos(nPos);
1349 m_aGroupIntervalEd.SetText(String::CreateFromInt32(_xGroup->getGroupInterval()));
1350 m_aGroupIntervalEd.SaveValue();
1351 m_aGroupIntervalEd.Enable( nPos != 0 );
1352 m_aKeepTogetherLst.SelectEntryPos(_xGroup->getKeepTogether());
1353 m_aOrderLst.SelectEntryPos(_xGroup->getSortAscending() ? 0 : 1);
1355 ListBox* pControls[] = { &m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aKeepTogetherLst,&m_aOrderLst};
1356 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1357 pControls[i]->SaveValue();
1359 ListBox* pControlsLst2[] = { &m_aHeaderLst, &m_aFooterLst, &m_aGroupOnLst, &m_aKeepTogetherLst,&m_aOrderLst};
1360 sal_Bool bReadOnly = !m_pController->isEditable();
1361 for (size_t i = 0; i < sizeof(pControlsLst2)/sizeof(pControlsLst2[0]); ++i)
1362 pControlsLst2[i]->SetReadOnly(bReadOnly);
1363 m_aGroupIntervalEd.SetReadOnly(bReadOnly);
1365 //------------------------------------------------------------------------------
1366 void OGroupsSortingDialog::Resize()
1368 Window::Resize();
1369 Size aTotalOutputSize = GetOutputSizePixel();
1370 Size aSpace = LogicToPixel( Size( UNRELATED_CONTROLS, UNRELATED_CONTROLS ), MAP_APPFONT );
1371 m_pFieldExpression->SetSizePixel(Size(aTotalOutputSize.Width() - 2*aSpace.Width(),m_pFieldExpression->GetSizePixel().Height()));
1373 Control* pControlsLst[] = { &m_aHeaderLst, &m_aFooterLst, &m_aGroupOnLst, &m_aGroupIntervalEd,&m_aKeepTogetherLst,&m_aOrderLst};
1374 Control* pControls[] = { &m_aHeader, &m_aFooter, &m_aGroupOn, &m_aGroupInterval, &m_aKeepTogether, &m_aOrder};
1375 sal_Int32 nMaxTextWidth = 0;
1376 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1378 nMaxTextWidth = ::std::max<sal_Int32>(static_cast<sal_Int32>(GetTextWidth(pControls[i]->GetText())),nMaxTextWidth);
1379 } // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1381 // aTotalOutputSize.Width() - m_aHeaderLst.GetSizePixel().Width() - 3*aSpace.Width()
1382 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1384 pControls[i]->SetSizePixel(Size(nMaxTextWidth,pControls[i]->GetSizePixel().Height()));
1385 Point aPos = pControls[i]->GetPosPixel();
1386 aPos.X() += nMaxTextWidth + aSpace.Width();
1387 aPos.Y() = pControlsLst[i]->GetPosPixel().Y();
1389 pControlsLst[i]->SetPosSizePixel(aPos,Size(aTotalOutputSize.Width() - aPos.X() - aSpace.Width(),pControlsLst[i]->GetSizePixel().Height()));
1390 } // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1392 m_aFL.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL.GetSizePixel().Height()));
1393 m_aFL2.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL2.GetSizePixel().Height()));
1394 m_aFL3.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL3.GetSizePixel().Height()));
1396 sal_Int32 nPos = aTotalOutputSize.Width() - aSpace.Width() - m_aUp.GetSizePixel().Width();
1397 m_aDown.SetPosPixel(Point(nPos,m_aDown.GetPosPixel().Y()));
1398 nPos -= (m_aUp.GetSizePixel().Width() + LogicToPixel( Size( RELATED_CONTROLS, 0 ), MAP_APPFONT ).Width());
1399 m_aUp.SetPosPixel(Point(nPos,m_aUp.GetPosPixel().Y()));
1400 Point aHelpPos = m_aHelpWindow.GetPosPixel();
1401 m_aHelpWindow.SetSizePixel(Size(aTotalOutputSize.Width() - aHelpPos.X(),aTotalOutputSize.Height() - aHelpPos.Y()));
1403 //------------------------------------------------------------------------------
1404 void OGroupsSortingDialog::checkButtons(sal_Int32 _nRow)
1406 sal_Int32 nGroupCount = m_xGroups->getCount();
1407 sal_Bool bEnable = nGroupCount > 1;
1408 m_aUp.Enable(bEnable && _nRow > 0 );
1409 m_aDown.Enable(bEnable && _nRow < (m_pFieldExpression->GetRowCount()-1) );
1411 // =============================================================================
1412 } // rptui
1413 // =============================================================================