update dev300-m58
[ooovba.git] / reportdesign / source / ui / dlg / GroupsSorting.cxx
blob453b853078cf8e2c1d5ca3493286df701daa3746
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>
48 #include <svtools/imgdef.hxx>
50 #include "GroupExchange.hxx"
51 #include "UITools.hxx"
52 #include "UndoActions.hxx"
53 #include "uistrings.hrc"
54 #include "ReportController.hxx"
56 #include <cppuhelper/implbase1.hxx>
57 #include <comphelper/property.hxx>
58 #include <vcl/mnemonic.hxx>
59 #include <vcl/msgbox.hxx>
60 #include <algorithm>
61 #include <boost/bind.hpp>
63 #include <cppuhelper/bootstrap.hxx>
65 #define HANDLE_ID 0
66 #define FIELD_EXPRESSION 1
67 #define GROUPS_START_LEN 5
68 #define NO_GROUP -1
70 namespace rptui
72 using namespace ::com::sun::star;
73 using namespace svt;
74 using namespace ::comphelper;
76 typedef ::svt::EditBrowseBox OFieldExpressionControl_Base;
77 typedef ::cppu::WeakImplHelper1< container::XContainerListener > TContainerListenerBase;
78 class OFieldExpressionControl : public TContainerListenerBase
79 ,public OFieldExpressionControl_Base
81 ::osl::Mutex m_aMutex;
82 ::std::vector<sal_Int32> m_aGroupPositions;
83 ::svt::ComboBoxControl* m_pComboCell;
84 sal_Int32 m_nDataPos;
85 sal_Int32 m_nCurrentPos;
86 ULONG m_nPasteEvent;
87 ULONG m_nDeleteEvent;
88 OGroupsSortingDialog* m_pParent;
89 bool m_bIgnoreEvent;
92 void fillListBox(const uno::Reference< beans::XPropertySet>& _xDest,long nRow,USHORT nColumnId);
93 BOOL SaveModified(bool _bAppend);
95 OFieldExpressionControl(const OFieldExpressionControl&); // NO COPY
96 void operator =(const OFieldExpressionControl&); // NO ASSIGN
97 public:
98 OFieldExpressionControl( OGroupsSortingDialog* _pParent,const ResId& _rResId);
99 virtual ~OFieldExpressionControl();
101 // XEventListener
102 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
103 // XContainerListener
104 virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
105 virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
106 virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
108 void fillColumns(const uno::Reference< container::XNameAccess>& _xColumns);
109 void lateInit();
110 sal_Bool IsDeleteAllowed( );
111 void DeleteRows();
112 void cut();
113 void copy();
114 void paste();
116 inline sal_Int32 getGroupPosition(sal_Int32 _nRow) const { return _nRow != BROWSER_ENDOFSELECTION ? m_aGroupPositions[_nRow] : sal_Int32(NO_GROUP); }
118 inline ::svt::ComboBoxControl* getExpressionControl() const { return m_pComboCell; }
121 /** returns the sequence with the selected groups
123 uno::Sequence<uno::Any> fillSelectedGroups();
125 /** move groups given by _aGroups
127 void moveGroups(const uno::Sequence<uno::Any>& _aGroups,sal_Int32 _nRow,sal_Bool _bSelect = sal_True);
129 virtual BOOL CursorMoving(long nNewRow, USHORT nNewCol);
130 using OFieldExpressionControl_Base::GetRowCount;
131 protected:
132 virtual BOOL IsTabAllowed(BOOL bForward) const;
135 virtual void InitController( ::svt::CellControllerRef& rController, long nRow, USHORT nCol );
136 virtual ::svt::CellController* GetController( long nRow, USHORT nCol );
137 virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColId ) const;
138 virtual BOOL SeekRow( long nRow );
139 virtual BOOL SaveModified();
140 virtual String GetCellText( long nRow, USHORT nColId ) const;
141 virtual RowStatus GetRowStatus(long nRow) const;
143 virtual void KeyInput(const KeyEvent& rEvt);
144 virtual void Command( const CommandEvent& rEvt );
146 // D&D
147 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel );
148 virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt );
149 virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt );
151 using BrowseBox::AcceptDrop;
152 using BrowseBox::ExecuteDrop;
154 private:
156 DECL_LINK( AsynchActivate, void* );
157 DECL_LINK( AsynchDeactivate, void* );
158 DECL_LINK( DelayedPaste, void* );
159 DECL_LINK( CBChangeHdl,ComboBox*);
161 void InsertRows( long nRow );
163 public:
164 DECL_LINK( DelayedDelete, void* );
167 //========================================================================
168 // class OFieldExpressionControl
169 //========================================================================
170 DBG_NAME( rpt_OFieldExpressionControl )
171 //------------------------------------------------------------------------
172 OFieldExpressionControl::OFieldExpressionControl( OGroupsSortingDialog* _pParent,const ResId& _rResId )
173 :EditBrowseBox( _pParent, _rResId,EBBF_NONE, WB_TABSTOP | BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_AUTOSIZE_LASTCOL |
174 BROWSER_KEEPSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL)
175 ,m_aGroupPositions(GROUPS_START_LEN,-1)
176 ,m_pComboCell(NULL)
177 ,m_nDataPos(-1)
178 ,m_nCurrentPos(-1)
179 ,m_nPasteEvent(0)
180 ,m_nDeleteEvent(0)
181 ,m_pParent(_pParent)
182 ,m_bIgnoreEvent(false)
184 DBG_CTOR( rpt_OFieldExpressionControl,NULL);
185 SetBorderStyle(WINDOW_BORDER_MONO);
188 //------------------------------------------------------------------------
189 OFieldExpressionControl::~OFieldExpressionControl()
191 acquire();
192 uno::Reference< report::XGroups > xGroups = m_pParent->getGroups();
193 xGroups->removeContainerListener(this);
194 //////////////////////////////////////////////////////////////////////
195 // delete events from queue
196 if( m_nPasteEvent )
197 Application::RemoveUserEvent( m_nPasteEvent );
198 if( m_nDeleteEvent )
199 Application::RemoveUserEvent( m_nDeleteEvent );
201 delete m_pComboCell;
202 DBG_DTOR( rpt_OFieldExpressionControl,NULL);
204 //------------------------------------------------------------------------------
205 uno::Sequence<uno::Any> OFieldExpressionControl::fillSelectedGroups()
207 uno::Sequence<uno::Any> aList;
208 ::std::vector<uno::Any> vClipboardList;
209 vClipboardList.reserve(GetSelectRowCount());
211 uno::Reference<report::XGroups> xGroups = m_pParent->getGroups();
212 sal_Int32 nCount = xGroups->getCount();
213 if ( nCount >= 1 )
215 for( long nIndex=FirstSelectedRow(); nIndex >= 0 ; nIndex=NextSelectedRow() )
219 if ( m_aGroupPositions[nIndex] != NO_GROUP )
221 uno::Reference< report::XGroup> xOrgGroup(xGroups->getByIndex(m_aGroupPositions[nIndex]),uno::UNO_QUERY);
222 /*uno::Reference< report::XGroup> xCopy = xGroups->createGroup();
223 ::comphelper::copyProperties(xOrgGroup.get(),xCopy.get());*/
224 vClipboardList.push_back( uno::makeAny(xOrgGroup) );
227 catch(uno::Exception&)
229 OSL_ENSURE(0,"Can not access group!");
232 if ( !vClipboardList.empty() )
233 aList = uno::Sequence< uno::Any >(&vClipboardList[0], vClipboardList.size());
234 } // if ( nCount > 1 )
235 return aList;
237 //------------------------------------------------------------------------------
238 void OFieldExpressionControl::StartDrag( sal_Int8 /*_nAction*/ , const Point& /*_rPosPixel*/ )
240 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
241 if ( m_pParent && !m_pParent->isReadOnly( ) )
243 uno::Sequence<uno::Any> aClipboardList = fillSelectedGroups();
245 if( aClipboardList.getLength() )
247 OGroupExchange* pData = new OGroupExchange(aClipboardList);
248 uno::Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
249 pData->StartDrag(this, DND_ACTION_MOVE );
250 } // if(!vClipboardList.empty())
253 //------------------------------------------------------------------------------
254 sal_Int8 OFieldExpressionControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
256 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
257 sal_Int8 nAction = DND_ACTION_NONE;
258 if ( IsEditing() )
260 USHORT nPos = m_pComboCell->GetSelectEntryPos();
261 if ( COMBOBOX_ENTRY_NOTFOUND != nPos || m_pComboCell->GetText().Len() )
262 SaveModified();
263 DeactivateCell();
265 if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) && m_pParent->getGroups()->getCount() > 1 && rEvt.GetWindow() == &GetDataWindow() )
267 nAction = DND_ACTION_MOVE;
269 return nAction;
271 //------------------------------------------------------------------------------
272 sal_Int8 OFieldExpressionControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
274 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
275 sal_Int8 nAction = DND_ACTION_NONE;
276 if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) )
278 sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
279 SetNoSelection();
281 TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
282 uno::Any aDrop = aDropped.GetAny(OGroupExchange::getReportGroupId());
283 uno::Sequence< uno::Any > aGroups;
284 aDrop >>= aGroups;
285 if ( aGroups.getLength() )
287 moveGroups(aGroups,nRow);
288 nAction = DND_ACTION_MOVE;
291 return nAction;
293 //------------------------------------------------------------------------------
294 void OFieldExpressionControl::moveGroups(const uno::Sequence<uno::Any>& _aGroups,sal_Int32 _nRow,sal_Bool _bSelect)
296 if ( _aGroups.getLength() )
298 m_bIgnoreEvent = true;
300 sal_Int32 nRow = _nRow;
301 String sUndoAction(ModuleRes(RID_STR_UNDO_MOVE_GROUP));
302 UndoManagerListAction aListAction(*m_pParent->m_pController->getUndoMgr(),sUndoAction);
304 uno::Reference< report::XGroups> xGroups = m_pParent->getGroups();
305 const uno::Any* pIter = _aGroups.getConstArray();
306 const uno::Any* pEnd = pIter + _aGroups.getLength();
307 for(;pIter != pEnd;++pIter)
309 uno::Reference< report::XGroup> xGroup(*pIter,uno::UNO_QUERY);
310 if ( xGroup.is() )
312 uno::Sequence< beans::PropertyValue > aArgs(1);
313 aArgs[0].Name = PROPERTY_GROUP;
314 aArgs[0].Value <<= xGroup;
315 // we use this way to create undo actions
316 m_pParent->m_pController->executeChecked(SID_GROUP_REMOVE,aArgs);
317 aArgs.realloc(2);
318 if ( nRow > xGroups->getCount() )
319 nRow = xGroups->getCount();
320 if ( _bSelect )
321 SelectRow(nRow);
322 aArgs[1].Name = PROPERTY_POSITIONY;
323 aArgs[1].Value <<= nRow;
324 m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
325 ++nRow;
327 } // for(;pIter != pEnd;++pIter)
329 m_bIgnoreEvent = false;
330 Invalidate();
331 } // if ( _aGroups.getLength() )
333 // -----------------------------------------------------------------------------
334 void OFieldExpressionControl::fillColumns(const uno::Reference< container::XNameAccess>& _xColumns)
336 m_pComboCell->Clear();
337 if ( _xColumns.is() )
339 uno::Sequence< ::rtl::OUString> aColumnNames = _xColumns->getElementNames();
340 const ::rtl::OUString* pIter = aColumnNames.getConstArray();
341 const ::rtl::OUString* pEnd = pIter + aColumnNames.getLength();
342 for(;pIter != pEnd;++pIter)
343 m_pComboCell->InsertEntry(*pIter);
344 } // if ( _xColumns.is() )
346 //------------------------------------------------------------------------------
347 void OFieldExpressionControl::lateInit()
349 uno::Reference< report::XGroups > xGroups = m_pParent->getGroups();
350 sal_Int32 nGroupsCount = xGroups->getCount();
351 m_aGroupPositions.resize(::std::max<sal_Int32>(nGroupsCount,sal_Int32(GROUPS_START_LEN)),NO_GROUP);
352 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
353 for (sal_Int32 i = 0; i < nGroupsCount; ++i,++aIter)
354 *aIter = i;
356 if ( ColCount() == 0 )
358 Font aFont( GetDataWindow().GetFont() );
359 aFont.SetWeight( WEIGHT_NORMAL );
360 GetDataWindow().SetFont( aFont );
362 // Font fuer die Ueberschriften auf Light setzen
363 aFont = GetFont();
364 aFont.SetWeight( WEIGHT_LIGHT );
365 SetFont(aFont);
367 InsertHandleColumn(static_cast<USHORT>(GetTextWidth('0') * 4)/*, TRUE */);
368 InsertDataColumn( FIELD_EXPRESSION, String(ModuleRes(STR_RPT_EXPRESSION)), 100);
370 m_pComboCell = new ComboBoxControl( &GetDataWindow() );
371 m_pComboCell->SetSelectHdl(LINK(this,OFieldExpressionControl,CBChangeHdl));
372 m_pComboCell->SetHelpId(HID_RPT_FIELDEXPRESSION);
374 Control* pControls[] = {m_pComboCell};
375 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
377 pControls[i]->SetGetFocusHdl(LINK(m_pParent, OGroupsSortingDialog, OnControlFocusGot));
378 pControls[i]->SetLoseFocusHdl(LINK(m_pParent, OGroupsSortingDialog, OnControlFocusLost));
381 //////////////////////////////////////////////////////////////////////
382 // set browse mode
383 BrowserMode nMode(BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_KEEPSELECTION |
384 BROWSER_HLINESFULL | BROWSER_VLINESFULL | BROWSER_AUTOSIZE_LASTCOL | BROWSER_AUTO_VSCROLL | BROWSER_AUTO_HSCROLL);
385 if( m_pParent->isReadOnly() )
386 nMode |= BROWSER_HIDECURSOR;
387 SetMode(nMode);
388 xGroups->addContainerListener(this);
390 else
391 // not the first call
392 RowRemoved(0, GetRowCount());
394 RowInserted(0, m_aGroupPositions.size(), TRUE);
396 // -----------------------------------------------------------------------------
397 // -----------------------------------------------------------------------------
398 IMPL_LINK( OFieldExpressionControl, CBChangeHdl, ComboBox*, /*pComboBox*/ )
400 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
402 SaveModified();
403 return 0L;
405 //------------------------------------------------------------------------------
406 IMPL_LINK(OFieldExpressionControl, AsynchActivate, void*, EMPTYARG)
408 ActivateCell();
409 return 0L;
412 //------------------------------------------------------------------------------
413 IMPL_LINK(OFieldExpressionControl, AsynchDeactivate, void*, EMPTYARG)
415 DeactivateCell();
416 return 0L;
419 //------------------------------------------------------------------------------
420 BOOL OFieldExpressionControl::IsTabAllowed(BOOL /*bForward*/) const
422 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
423 return FALSE;
426 //------------------------------------------------------------------------------
427 BOOL OFieldExpressionControl::SaveModified()
429 return SaveModified(true);
431 //------------------------------------------------------------------------------
432 BOOL OFieldExpressionControl::SaveModified(bool _bAppendRow)
434 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
435 sal_Int32 nRow = GetCurRow();
436 if ( nRow != BROWSER_ENDOFSELECTION )
438 sal_Bool bAppend = sal_False;
441 uno::Reference< report::XGroup> xGroup;
442 if ( m_aGroupPositions[nRow] == NO_GROUP )
444 bAppend = sal_True;
445 String sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP));
446 m_pParent->m_pController->getUndoMgr()->EnterListAction( sUndoAction, String() );
447 xGroup = m_pParent->getGroups()->createGroup();
448 xGroup->setHeaderOn(sal_True);
450 uno::Sequence< beans::PropertyValue > aArgs(2);
451 aArgs[0].Name = PROPERTY_GROUP;
452 aArgs[0].Value <<= xGroup;
453 // find position where to insert the new group
454 sal_Int32 nGroupPos = 0;
455 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
456 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.begin() + nRow;
457 for(;aIter != aEnd;++aIter)
458 if ( *aIter != NO_GROUP )
459 nGroupPos = *aIter + 1;
460 aArgs[1].Name = PROPERTY_POSITIONY;
461 aArgs[1].Value <<= nGroupPos;
462 m_bIgnoreEvent = true;
463 m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
464 m_bIgnoreEvent = false;
465 OSL_ENSURE(*aIter == NO_GROUP ,"Illegal iterator!");
466 *aIter++ = nGroupPos;
468 aEnd = m_aGroupPositions.end();
469 for(;aIter != aEnd;++aIter)
470 if ( *aIter != NO_GROUP )
471 ++*aIter;
473 else
474 xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
475 if ( xGroup.is() )
477 USHORT nPos = m_pComboCell->GetSelectEntryPos();
478 ::rtl::OUString sExpression;
479 if ( COMBOBOX_ENTRY_NOTFOUND == nPos )
480 sExpression = m_pComboCell->GetText();
481 else
483 sExpression = m_pComboCell->GetEntry(nPos);
485 xGroup->setExpression( sExpression );
487 ::rptui::adjustSectionName(xGroup,nPos);
489 if ( bAppend )
490 m_pParent->m_pController->getUndoMgr()->LeaveListAction();
493 if ( Controller() )
494 Controller()->ClearModified();
495 if ( _bAppendRow && GetRowCount() == m_pParent->getGroups()->getCount() )
497 RowInserted( GetRowCount()-1);
498 m_aGroupPositions.push_back(NO_GROUP);
501 GoToRow(nRow);
502 m_pParent->DisplayData(nRow);
504 catch(uno::Exception&)
506 OSL_ENSURE(0,"OFieldExpressionControl::SaveModified: Exception caught!");
510 return TRUE;
512 //------------------------------------------------------------------------------
513 String OFieldExpressionControl::GetCellText( long nRow, USHORT /*nColId*/ ) const
515 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
516 String sText;
517 if ( nRow != BROWSER_ENDOFSELECTION && m_aGroupPositions[nRow] != NO_GROUP )
521 uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
522 sText = xGroup->getExpression();
524 catch(uno::Exception&)
526 OSL_ENSURE(0,"Exception caught while getting expression value from the group");
528 } // if ( nRow != BROWSER_ENDOFSELECTION && nRow < m_pParent->getGroups()->getCount() )
529 return sText;
532 //------------------------------------------------------------------------------
533 void OFieldExpressionControl::InitController( CellControllerRef& /*rController*/, long nRow, USHORT nColumnId )
535 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
537 m_pComboCell->SetText( GetCellText( nRow, nColumnId ) );
539 //------------------------------------------------------------------------------
540 sal_Bool OFieldExpressionControl::CursorMoving(long nNewRow, sal_uInt16 nNewCol)
542 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
544 if (!EditBrowseBox::CursorMoving(nNewRow, nNewCol))
545 return sal_False;
546 m_nDataPos = nNewRow;
547 long nOldDataPos = GetCurRow();
548 InvalidateStatusCell( m_nDataPos );
549 InvalidateStatusCell( nOldDataPos );
551 m_pParent->SaveData( nOldDataPos );
552 m_pParent->DisplayData( m_nDataPos );
553 return sal_True;
555 //------------------------------------------------------------------------------
556 CellController* OFieldExpressionControl::GetController( long /*nRow*/, USHORT /*nColumnId*/ )
558 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
559 ComboBoxCellController* pCellController = new ComboBoxCellController( m_pComboCell );
560 pCellController->GetComboBox().SetReadOnly(!m_pParent->m_pController->isEditable());
561 return pCellController;
564 //------------------------------------------------------------------------------
565 BOOL OFieldExpressionControl::SeekRow( long _nRow )
567 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
568 // die Basisklasse braucht den Aufruf, da sie sich dort merkt, welche Zeile gepainted wird
569 EditBrowseBox::SeekRow(_nRow);
570 m_nCurrentPos = _nRow;
571 return TRUE;
574 //------------------------------------------------------------------------------
575 void OFieldExpressionControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, USHORT nColumnId ) const
577 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
578 String aText =const_cast< OFieldExpressionControl*>(this)->GetCellText( m_nCurrentPos, nColumnId );
580 Point aPos( rRect.TopLeft() );
581 Size aTextSize( GetDataWindow().GetTextHeight(),GetDataWindow().GetTextWidth( aText ));
583 if( aPos.X() < rRect.Right() || aPos.X() + aTextSize.Width() > rRect.Right() ||
584 aPos.Y() < rRect.Top() || aPos.Y() + aTextSize.Height() > rRect.Bottom() )
585 rDev.SetClipRegion( rRect );
587 rDev.DrawText( aPos, aText );
589 if( rDev.IsClipRegion() )
590 rDev.SetClipRegion();
592 //------------------------------------------------------------------------------
593 EditBrowseBox::RowStatus OFieldExpressionControl::GetRowStatus(long nRow) const
595 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
596 if (nRow >= 0 && nRow == m_nDataPos)
597 return EditBrowseBox::CURRENT;
598 if ( nRow != BROWSER_ENDOFSELECTION && nRow < static_cast<long>(m_aGroupPositions.size()) && m_aGroupPositions[nRow] != NO_GROUP )
602 uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
603 return (xGroup->getHeaderOn() || xGroup->getFooterOn())? EditBrowseBox::HEADERFOOTER : EditBrowseBox::CLEAN;
605 catch(uno::Exception&)
607 OSL_ENSURE(0,"Exception cathced while try to get a group!");
610 return EditBrowseBox::CLEAN;
612 // XEventListener
613 //------------------------------------------------------------------------------
614 void SAL_CALL OFieldExpressionControl::disposing(const lang::EventObject& /*e*/) throw( uno::RuntimeException )
617 //------------------------------------------------------------------------------
618 // XContainerListener
619 //------------------------------------------------------------------------------
620 void SAL_CALL OFieldExpressionControl::elementInserted(const container::ContainerEvent& evt) throw(uno::RuntimeException)
622 if ( m_bIgnoreEvent )
623 return;
624 ::vos::OClearableGuard aSolarGuard( Application::GetSolarMutex() );
625 ::osl::MutexGuard aGuard( m_aMutex );
626 sal_Int32 nGroupPos = 0;
627 if ( evt.Accessor >>= nGroupPos )
629 if ( nGroupPos >= GetRowCount() )
631 sal_Int32 nAddedRows = nGroupPos - GetRowCount();
632 RowInserted(nAddedRows);
633 for (sal_Int32 i = 0; i < nAddedRows; ++i)
634 m_aGroupPositions.push_back(NO_GROUP);
635 m_aGroupPositions[nGroupPos] = nGroupPos;
637 else
639 ::std::vector<sal_Int32>::iterator aFind = m_aGroupPositions.begin()+ nGroupPos;
640 if ( aFind == m_aGroupPositions.end() )
641 aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),NO_GROUP);
643 if ( aFind != m_aGroupPositions.end() )
645 if ( *aFind != NO_GROUP )
646 aFind = m_aGroupPositions.insert(aFind,nGroupPos);
647 else
648 *aFind = nGroupPos;
650 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
651 for(++aFind;aFind != aEnd;++aFind)
652 if ( *aFind != NO_GROUP )
653 ++*aFind;
655 //::std::vector<sal_Int32>::reverse_iterator aRIter = m_aGroupPositions.rbegin();
656 //::std::vector<sal_Int32>::reverse_iterator aREnd = m_aGroupPositions.rend();
657 //for (; aRIter != aREnd && *aRIter != NO_GROUP; ++aRIter)
658 // continue;
659 //if ( aRIter != aREnd )
660 // m_aGroupPositions.erase(m_aGroupPositions.begin() + (m_aGroupPositions.size() - 1 - (aRIter - m_aGroupPositions.rbegin())));
663 Invalidate();
666 //------------------------------------------------------------------------------
667 void SAL_CALL OFieldExpressionControl::elementReplaced(const container::ContainerEvent& /*evt*/) throw(uno::RuntimeException)
670 //------------------------------------------------------------------------------
671 void SAL_CALL OFieldExpressionControl::elementRemoved(const container::ContainerEvent& evt) throw(uno::RuntimeException)
673 ::vos::OClearableGuard aSolarGuard( Application::GetSolarMutex() );
674 ::osl::MutexGuard aGuard( m_aMutex );
676 if ( m_bIgnoreEvent )
677 return;
679 sal_Int32 nGroupPos = 0;
680 if ( evt.Accessor >>= nGroupPos )
682 ::std::vector<sal_Int32>::iterator aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),nGroupPos);
683 if ( aFind != m_aGroupPositions.end() )
685 *aFind = NO_GROUP;
686 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
687 for(++aFind;aFind != aEnd;++aFind)
688 if ( *aFind != NO_GROUP )
689 --*aFind;
690 //PaintCell(*this,GetFieldRect(FIELD_EXPRESSION),FIELD_EXPRESSION);
691 Invalidate();
695 //------------------------------------------------------------------------------
696 sal_Bool OFieldExpressionControl::IsDeleteAllowed( )
698 return !m_pParent->isReadOnly() && GetSelectRowCount() > 0;
700 //------------------------------------------------------------------------
701 void OFieldExpressionControl::KeyInput( const KeyEvent& rEvt )
703 if (IsDeleteAllowed())
705 if (rEvt.GetKeyCode().GetCode() == KEY_DELETE && // Delete rows
706 !rEvt.GetKeyCode().IsShift() &&
707 !rEvt.GetKeyCode().IsMod1())
709 DeleteRows();
710 return;
713 EditBrowseBox::KeyInput(rEvt);
715 //------------------------------------------------------------------------
716 void OFieldExpressionControl::Command(const CommandEvent& rEvt)
718 switch (rEvt.GetCommand())
720 case COMMAND_CONTEXTMENU:
722 if (!rEvt.IsMouseEvent())
724 EditBrowseBox::Command(rEvt);
725 return;
728 USHORT nColId = GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X());
730 if ( nColId == HANDLE_ID )
732 //long nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
733 PopupMenu aContextMenu(ModuleRes(RID_GROUPSROWPOPUPMENU));
734 sal_Bool bEnable = sal_False;
735 long nIndex = FirstSelectedRow();
736 while( nIndex >= 0 && !bEnable )
738 if ( m_aGroupPositions[nIndex] != NO_GROUP )
739 bEnable = sal_True;
740 nIndex = NextSelectedRow();
742 //aContextMenu.EnableItem( SID_CUT, IsDeleteAllowed() && bEnable);
743 //aContextMenu.EnableItem( SID_COPY, bEnable);
744 //TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
745 //aContextMenu.EnableItem( SID_PASTE, aTransferData.HasFormat(SOT_FORMATSTR_ID_RPT_GRPED) );
746 aContextMenu.EnableItem( SID_DELETE, IsDeleteAllowed() && bEnable );
747 switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
749 case SID_CUT:
750 cut();
751 break;
752 case SID_COPY:
753 copy();
754 break;
755 case SID_PASTE:
756 paste();
757 break;
759 case SID_DELETE:
760 if( m_nDeleteEvent )
761 Application::RemoveUserEvent( m_nDeleteEvent );
762 m_nDeleteEvent = Application::PostUserEvent( LINK(this, OFieldExpressionControl, DelayedDelete) );
763 break;
764 default:
765 break;
767 } // if ( nColId == HANDLE_ID )
768 // run through
770 default:
771 EditBrowseBox::Command(rEvt);
775 //------------------------------------------------------------------------------
776 void OFieldExpressionControl::DeleteRows()
778 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
780 sal_Bool bIsEditing = IsEditing();
781 if (bIsEditing)
783 DeactivateCell();
785 long nIndex = FirstSelectedRow();
786 if (nIndex == -1)
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;
796 while( nIndex >= 0 )
798 if ( m_aGroupPositions[nIndex] != NO_GROUP )
800 if ( bFirstTime )
802 bFirstTime = false;
803 String sUndoAction(ModuleRes(RID_STR_UNDO_REMOVE_SELECTION));
804 m_pParent->m_pController->getUndoMgr()->EnterListAction( sUndoAction, String() );
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 *aFind = NO_GROUP;
815 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
816 for(++aFind;aFind != aEnd;++aFind)
817 if ( *aFind != NO_GROUP )
818 --*aFind;
820 nIndex = NextSelectedRow();
821 } // while( nIndex >= 0 )
823 if ( !bFirstTime )
824 m_pParent->m_pController->getUndoMgr()->LeaveListAction();
826 m_nDataPos = GetCurRow();
827 InvalidateStatusCell( nOldDataPos );
828 InvalidateStatusCell( m_nDataPos );
829 ActivateCell();
830 m_pParent->DisplayData( m_nDataPos );
831 m_bIgnoreEvent = false;
832 Invalidate();
834 //------------------------------------------------------------------------------
835 //------------------------------------------------------------------------------
836 void OFieldExpressionControl::cut()
838 copy();
839 DeleteRows();
842 //------------------------------------------------------------------------------
843 void OFieldExpressionControl::copy()
845 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
846 //////////////////////////////////////////////////////////////////////
847 // set to the right row and save it
848 m_pParent->SaveData( m_nDataPos );
850 uno::Sequence<uno::Any> aClipboardList = fillSelectedGroups();
852 if( aClipboardList.getLength() )
854 OGroupExchange* pData = new OGroupExchange(aClipboardList);
855 uno::Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
856 pData->CopyToClipboard(GetParent());
860 //------------------------------------------------------------------------------
861 void OFieldExpressionControl::paste()
863 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
864 if(aTransferData.HasFormat(OGroupExchange::getReportGroupId()))
866 if( m_nPasteEvent )
867 Application::RemoveUserEvent( m_nPasteEvent );
868 m_nPasteEvent = Application::PostUserEvent( LINK(this, OFieldExpressionControl, DelayedPaste) );
871 //------------------------------------------------------------------------------
872 IMPL_LINK( OFieldExpressionControl, DelayedPaste, void*, )
874 m_nPasteEvent = 0;
876 sal_Int32 nPastePosition = GetSelectRowCount() ? FirstSelectedRow() : GetCurRow();
878 InsertRows( nPastePosition );
879 SetNoSelection();
880 GoToRow( nPastePosition );
882 return 0;
884 //------------------------------------------------------------------------------
885 IMPL_LINK( OFieldExpressionControl, DelayedDelete, void*, )
887 m_nDeleteEvent = 0;
888 DeleteRows();
889 return 0;
891 //------------------------------------------------------------------------------
892 void OFieldExpressionControl::InsertRows( long nRow )
894 DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
896 sal_Int32 nSize = 0;
897 //////////////////////////////////////////////////////////////////////
898 // get rows from clipboard
899 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
900 if(aTransferData.HasFormat(OGroupExchange::getReportGroupId()))
902 datatransfer::DataFlavor aFlavor;
903 SotExchange::GetFormatDataFlavor(OGroupExchange::getReportGroupId(), aFlavor);
904 uno::Sequence< uno::Any > aGroups;
906 if( (aTransferData.GetAny(aFlavor) >>= aGroups) && aGroups.getLength() )
908 m_bIgnoreEvent = false;
910 String sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP));
911 UndoManagerListAction aListAction(*m_pParent->m_pController->getUndoMgr(),sUndoAction);
913 uno::Reference<report::XGroups> xGroups = m_pParent->getGroups();
914 sal_Int32 nGroupPos = 0;
915 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
916 ::std::vector<sal_Int32>::size_type nRowPos = static_cast< ::std::vector<sal_Int32>::size_type >(nRow);
917 if ( nRowPos < m_aGroupPositions.size() )
919 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.begin() + nRowPos;
920 for(;aIter != aEnd;++aIter)
922 if ( *aIter != NO_GROUP )
923 nGroupPos = *aIter;
926 for(sal_Int32 i=0;i < aGroups.getLength();++i,++nSize)
928 uno::Sequence< beans::PropertyValue > aArgs(2);
929 aArgs[0].Name = PROPERTY_GROUP;
930 aArgs[0].Value = aGroups[i];
931 aArgs[1].Name = PROPERTY_POSITIONY;
932 aArgs[1].Value <<= nGroupPos;
933 m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
935 ::std::vector<sal_Int32>::iterator aInsertPos = m_aGroupPositions.insert(aIter,nGroupPos);
936 ++aInsertPos;
937 aIter = aInsertPos;
938 ::std::vector<sal_Int32>::iterator aEnd = m_aGroupPositions.end();
939 for(;aInsertPos != aEnd;++aInsertPos)
940 if ( *aInsertPos != NO_GROUP )
941 ++*aInsertPos;
944 m_bIgnoreEvent = true;
948 RowInserted( nRow,nSize,sal_True );
950 //------------------------------------------------------------------------------
952 DBG_NAME( rpt_OGroupsSortingDialog )
953 //========================================================================
954 // class OGroupsSortingDialog
955 //========================================================================
956 OGroupsSortingDialog::OGroupsSortingDialog( Window* _pParent
957 ,sal_Bool _bReadOnly
958 ,OReportController* _pController)
959 : FloatingWindow( _pParent, ModuleRes(RID_GROUPS_SORTING) )
960 ,OPropertyChangeListener(m_aMutex)
961 ,m_aFL2(this, ModuleRes(FL_SEPARATOR2) )
962 ,m_aMove(this, ModuleRes(FT_MOVELABEL) )
964 ,m_aPB_Up(this, ModuleRes(PB_UP) )
965 ,m_aPB_Down(this, ModuleRes(PB_DOWN) )
966 ,m_aPB_Delete(this, ModuleRes(PB_DELETE) )
968 ,m_aToolBox(this, ModuleRes(TB_TOOLBOX) )
970 ,m_aFL3(this, ModuleRes(FL_SEPARATOR3) )
971 ,m_aOrder(this, ModuleRes(FT_ORDER) )
972 ,m_aOrderLst(this, ModuleRes(LST_ORDER) )
973 ,m_aHeader(this, ModuleRes(FT_HEADER) )
974 ,m_aHeaderLst(this, ModuleRes(LST_HEADERLST) )
975 ,m_aFooter(this, ModuleRes(FT_FOOTER) )
976 ,m_aFooterLst(this, ModuleRes(LST_FOOTERLST) )
977 ,m_aGroupOn(this, ModuleRes(FT_GROUPON) )
978 ,m_aGroupOnLst(this, ModuleRes(LST_GROUPONLST) )
979 ,m_aGroupInterval(this, ModuleRes(FT_GROUPINTERVAL) )
980 ,m_aGroupIntervalEd(this, ModuleRes(ED_GROUPINTERVALLST) )
981 ,m_aKeepTogether(this, ModuleRes(FT_KEEPTOGETHER) )
982 ,m_aKeepTogetherLst(this, ModuleRes(LST_KEEPTOGETHERLST) )
983 ,m_aFL(this, ModuleRes(FL_SEPARATOR1) )
984 ,m_aHelpWindow(this, ModuleRes(HELP_FIELD) )
985 ,m_pFieldExpression( new OFieldExpressionControl(this,ModuleRes(WND_CONTROL)))
986 ,m_pController(_pController)
987 ,m_pCurrentGroupListener(NULL)
988 ,m_xGroups(m_pController->getReportDefinition()->getGroups())
989 ,m_bReadOnly(_bReadOnly)
991 DBG_CTOR( rpt_OGroupsSortingDialog,NULL);
994 Control* pControlsLst[] = { &m_aHeaderLst, &m_aFooterLst, &m_aGroupOnLst, &m_aKeepTogetherLst, &m_aOrderLst, &m_aGroupIntervalEd};
995 for (size_t i = 0; i < sizeof(pControlsLst)/sizeof(pControlsLst[0]); ++i)
997 pControlsLst[i]->SetGetFocusHdl(LINK(this, OGroupsSortingDialog, OnControlFocusGot));
998 pControlsLst[i]->SetLoseFocusHdl(LINK(this, OGroupsSortingDialog, OnControlFocusLost));
999 pControlsLst[i]->Show(TRUE);
1000 } // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1002 for (size_t i = 0; i < (sizeof(pControlsLst)/sizeof(pControlsLst[0]))-1; ++i)
1003 static_cast<ListBox*>(pControlsLst[i])->SetSelectHdl(LINK(this,OGroupsSortingDialog,LBChangeHdl));
1005 Control* pControls[] = { &m_aHeader, &m_aFooter, &m_aGroupOn, &m_aGroupInterval, &m_aKeepTogether, &m_aOrder
1006 , &m_aMove,&m_aFL2};
1007 sal_Int32 nMaxTextWidth = 0;
1008 MnemonicGenerator aMnemonicGenerator;
1009 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1010 aMnemonicGenerator.RegisterMnemonic( pControls[i]->GetText() );
1012 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1014 pControls[i]->Show(TRUE);
1015 String sText = pControls[i]->GetText();
1016 if ( aMnemonicGenerator.CreateMnemonic(sText) )
1017 pControls[i]->SetText(sText);
1018 sal_Int32 nTextWidth = GetTextWidth(sText);
1019 nMaxTextWidth = ::std::max<sal_Int32>(nTextWidth,nMaxTextWidth);
1022 Size aSize(UNRELATED_CONTROLS, PAGE_HEIGHT);
1023 Size aSpace = LogicToPixel( aSize, MAP_APPFONT );
1024 Size aOutSize(nMaxTextWidth + m_aHeader.GetSizePixel().Width() + 3*aSpace.Width(),aSpace.Height());
1025 SetMinOutputSizePixel(aOutSize);
1026 SetOutputSizePixel(aOutSize);
1027 // Resize();
1029 m_pReportListener = new OPropertyChangeMultiplexer(this,m_pController->getReportDefinition().get());
1030 m_pReportListener->addProperty(PROPERTY_COMMAND);
1031 m_pReportListener->addProperty(PROPERTY_COMMANDTYPE);
1033 m_pFieldExpression->lateInit();
1034 fillColumns();
1035 m_pFieldExpression->Show();
1037 //m_aHelpWindow.SetReadOnly();
1038 m_aHelpWindow.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
1039 //BTN m_aPB_Up.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1040 //BTN m_aPB_Down.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1041 //BTN m_aPB_Delete.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1043 m_pFieldExpression->SetZOrder(&m_aFL2, WINDOW_ZORDER_BEHIND);
1045 m_aMove.SetZOrder(m_pFieldExpression, WINDOW_ZORDER_BEHIND);
1046 //BTN m_aPB_Up.SetZOrder(&m_aMove, WINDOW_ZORDER_BEHIND);
1047 //BTN m_aPB_Down.SetZOrder(&m_aPB_Up, WINDOW_ZORDER_BEHIND);
1048 // set Hi contrast bitmaps
1049 //BTN m_aPB_Up.SetModeImage( ModuleRes(IMG_UP_H),BMP_COLOR_HIGHCONTRAST);
1050 //BTN m_aPB_Down.SetModeImage( ModuleRes(IMG_DOWN_H),BMP_COLOR_HIGHCONTRAST);
1051 m_aToolBox.SetStyle(m_aToolBox.GetStyle()|WB_LINESPACING);
1052 m_aToolBox.SetSelectHdl(LINK(this, OGroupsSortingDialog, OnFormatAction));
1053 m_aToolBox.SetImageListProvider(this);
1054 setToolBox(&m_aToolBox);
1056 checkButtons(0);
1057 Resize();
1059 FreeResource();
1062 //------------------------------------------------------------------------
1063 OGroupsSortingDialog::~OGroupsSortingDialog()
1065 DBG_DTOR( rpt_OGroupsSortingDialog,NULL);
1066 delete m_pFieldExpression;
1067 m_xColumns.clear();
1068 m_pReportListener->dispose();
1069 if ( m_pCurrentGroupListener.is() )
1070 m_pCurrentGroupListener->dispose();
1072 // -----------------------------------------------------------------------------
1073 sal_Bool OGroupsSortingDialog::isReadOnly( ) const
1075 return m_bReadOnly;
1077 //------------------------------------------------------------------------------
1078 void OGroupsSortingDialog::UpdateData( )
1080 m_pFieldExpression->Invalidate();
1081 long nCurRow = m_pFieldExpression->GetCurRow();
1082 m_pFieldExpression->DeactivateCell();
1083 m_pFieldExpression->ActivateCell(nCurRow, m_pFieldExpression->GetCurColumnId());
1084 DisplayData(nCurRow);
1086 //------------------------------------------------------------------------------
1087 void OGroupsSortingDialog::DisplayData( sal_Int32 _nRow )
1089 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1090 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1091 sal_Bool bEmpty = nGroupPos == NO_GROUP;
1092 m_aHeaderLst.Enable(!bEmpty);
1093 m_aFooterLst.Enable(!bEmpty);
1094 m_aGroupOnLst.Enable(!bEmpty);
1095 m_aGroupIntervalEd.Enable(!bEmpty);
1096 m_aKeepTogetherLst.Enable(!bEmpty);
1097 m_aOrderLst.Enable(!bEmpty);
1099 m_aFL3.Enable(!bEmpty);
1100 m_aHeader.Enable(!bEmpty);
1101 m_aFooter.Enable(!bEmpty);
1102 m_aGroupOn.Enable(!bEmpty);
1103 m_aGroupInterval.Enable(!bEmpty);
1104 m_aKeepTogether.Enable(!bEmpty);
1105 m_aOrder.Enable(!bEmpty);
1107 checkButtons(_nRow);
1109 if ( m_pCurrentGroupListener.is() )
1110 m_pCurrentGroupListener->dispose();
1111 m_pCurrentGroupListener = NULL;
1112 if ( !bEmpty && nGroupPos != NO_GROUP )
1114 uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1116 m_pCurrentGroupListener = new OPropertyChangeMultiplexer(this,xGroup.get());
1117 m_pCurrentGroupListener->addProperty(PROPERTY_HEADERON);
1118 m_pCurrentGroupListener->addProperty(PROPERTY_FOOTERON);
1120 displayGroup(xGroup);
1123 //------------------------------------------------------------------------------
1124 void OGroupsSortingDialog::SaveData( sal_Int32 _nRow)
1126 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1127 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1128 if ( nGroupPos == NO_GROUP )
1129 return;
1131 uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1132 if ( m_aHeaderLst.GetSavedValue() != m_aHeaderLst.GetSelectEntryPos() )
1133 xGroup->setHeaderOn( m_aHeaderLst.GetSelectEntryPos() == 0 );
1134 if ( m_aFooterLst.GetSavedValue() != m_aFooterLst.GetSelectEntryPos() )
1135 xGroup->setFooterOn( m_aFooterLst.GetSelectEntryPos() == 0 );
1136 if ( m_aKeepTogetherLst.GetSavedValue() != m_aKeepTogetherLst.GetSelectEntryPos() )
1137 xGroup->setKeepTogether( m_aKeepTogetherLst.GetSelectEntryPos() );
1138 if ( m_aGroupOnLst.GetSavedValue() != m_aGroupOnLst.GetSelectEntryPos() )
1140 sal_Int16 nGroupOn = static_cast<sal_Int16>(reinterpret_cast<sal_IntPtr>(m_aGroupOnLst.GetEntryData(m_aGroupOnLst.GetSelectEntryPos())));
1141 xGroup->setGroupOn( nGroupOn );
1143 if ( m_aGroupIntervalEd.GetSavedValue().ToInt32() != m_aGroupIntervalEd.GetValue() )
1145 xGroup->setGroupInterval( static_cast<sal_Int32>(m_aGroupIntervalEd.GetValue()) );
1146 m_aGroupIntervalEd.SaveValue();
1148 if ( m_aOrderLst.GetSavedValue() != m_aOrderLst.GetSelectEntryPos() )
1149 xGroup->setSortAscending( m_aOrderLst.GetSelectEntryPos() == 0 );
1151 ListBox* pControls[] = { &m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aKeepTogetherLst,&m_aOrderLst};
1152 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1153 pControls[i]->SaveValue();
1156 // -----------------------------------------------------------------------------
1157 sal_Int32 OGroupsSortingDialog::getColumnDataType(const ::rtl::OUString& _sColumnName)
1159 sal_Int32 nDataType = sdbc::DataType::VARCHAR;
1162 if ( !m_xColumns.is() )
1163 fillColumns();
1164 if ( m_xColumns.is() && m_xColumns->hasByName(_sColumnName) )
1166 uno::Reference< beans::XPropertySet> xColumn(m_xColumns->getByName(_sColumnName),uno::UNO_QUERY);
1167 if ( xColumn.is() )
1168 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
1171 catch(uno::Exception&)
1173 OSL_ENSURE(0,"Eception caught while getting the type of a column");
1176 return nDataType;
1178 //------------------------------------------------------------------------------
1179 IMPL_LINK(OGroupsSortingDialog, OnControlFocusGot, Control*, pControl )
1181 if ( m_pFieldExpression && m_pFieldExpression->getExpressionControl() )
1183 Control* pControls[] = { m_pFieldExpression->getExpressionControl(),&m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aGroupIntervalEd,&m_aKeepTogetherLst,&m_aOrderLst};
1184 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1186 if ( pControl == pControls[i] )
1188 ListBox* pListBox = dynamic_cast< ListBox* >( pControl );
1189 if ( pListBox )
1190 pListBox->SaveValue();
1191 NumericField* pNumericField = dynamic_cast< NumericField* >( pControl );
1192 if ( pNumericField )
1193 pNumericField->SaveValue();
1194 showHelpText(static_cast<USHORT>(i+STR_RPT_HELP_FIELD));
1195 break;
1199 return 0L;
1201 //------------------------------------------------------------------------------
1202 IMPL_LINK(OGroupsSortingDialog, OnControlFocusLost, Control*, pControl )
1204 if ( m_pFieldExpression && pControl == &m_aGroupIntervalEd )
1206 if ( m_aGroupIntervalEd.IsModified() )
1207 SaveData(m_pFieldExpression->GetCurRow());
1209 return 0L;
1211 // -----------------------------------------------------------------------------
1212 IMPL_LINK( OGroupsSortingDialog, OnFormatAction, ToolBox*, /*NOTINTERESTEDIN*/ )
1213 // IMPL_LINK( OGroupsSortingDialog, ClickHdl, ImageButton*, _pButton )
1215 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1217 USHORT nCommand = m_aToolBox.GetCurItemId();
1219 if ( m_pFieldExpression )
1221 long nIndex = m_pFieldExpression->GetCurrRow();
1222 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(nIndex);
1223 uno::Sequence<uno::Any> aClipboardList;
1224 if ( nIndex >= 0 && nGroupPos != NO_GROUP )
1226 aClipboardList.realloc(1);
1227 aClipboardList[0] = m_xGroups->getByIndex(nGroupPos);
1229 //BTN if ( _pButton == &m_aPB_Up )
1230 if ( nCommand == SID_RPT_GROUPSORT_MOVE_UP )
1232 --nIndex;
1234 //BTN if ( _pButton == &m_aPB_Down )
1235 if ( nCommand == SID_RPT_GROUPSORT_MOVE_DOWN )
1237 ++nIndex;
1239 //BTN if ( _pButton == &m_aPB_Delete )
1240 if ( nCommand == SID_RPT_GROUPSORT_DELETE )
1242 // m_pFieldExpression->DeleteCurrentRow();
1243 Application::PostUserEvent( LINK(m_pFieldExpression, OFieldExpressionControl, DelayedDelete) );
1244 // UpdateData( );
1246 else
1248 if ( nIndex >= 0 && aClipboardList.getLength() )
1250 m_pFieldExpression->SetNoSelection();
1251 m_pFieldExpression->moveGroups(aClipboardList,nIndex,sal_False);
1252 m_pFieldExpression->DeactivateCell();
1253 m_pFieldExpression->GoToRow(nIndex);
1254 //long nCurRow = m_pFieldExpression->GetCurRow();
1255 m_pFieldExpression->ActivateCell(nIndex, m_pFieldExpression->GetCurColumnId());
1256 DisplayData(nIndex);
1260 return 1L;
1262 // -----------------------------------------------------------------------------
1263 IMPL_LINK( OGroupsSortingDialog, LBChangeHdl, ListBox*, pListBox )
1265 DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1266 if ( pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
1268 sal_Int32 nRow = m_pFieldExpression->GetCurRow();
1269 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(nRow);
1270 if ( pListBox != &m_aHeaderLst && pListBox != &m_aFooterLst)
1272 if ( pListBox && pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
1273 SaveData(nRow);
1274 if ( pListBox == &m_aGroupOnLst )
1275 m_aGroupIntervalEd.Enable( pListBox->GetSelectEntryPos() != 0 );
1277 else if ( nGroupPos != NO_GROUP )
1279 uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1280 uno::Sequence< beans::PropertyValue > aArgs(2);
1281 aArgs[1].Name = PROPERTY_GROUP;
1282 aArgs[1].Value <<= xGroup;
1284 if ( &m_aHeaderLst == pListBox )
1285 aArgs[0].Name = PROPERTY_HEADERON;
1286 else
1287 aArgs[0].Name = PROPERTY_FOOTERON;
1289 aArgs[0].Value <<= pListBox->GetSelectEntryPos() == 0;
1290 m_pController->executeChecked(&m_aHeaderLst == pListBox ? SID_GROUPHEADER : SID_GROUPFOOTER,aArgs);
1291 if ( m_pFieldExpression )
1292 m_pFieldExpression->InvalidateHandleColumn();
1295 return 1L;
1297 // -----------------------------------------------------------------------------
1298 void OGroupsSortingDialog::showHelpText(USHORT _nResId)
1300 m_aHelpWindow.SetText(String(ModuleRes(_nResId)));
1302 // -----------------------------------------------------------------------------
1303 void OGroupsSortingDialog::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
1305 uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
1306 if ( xGroup.is() )
1307 displayGroup(xGroup);
1308 else
1309 fillColumns();
1311 // -----------------------------------------------------------------------------
1312 void OGroupsSortingDialog::fillColumns()
1314 m_xColumns.clear();
1315 uno::Reference< report::XReportDefinition> xReport = m_pController->getReportDefinition();
1316 if ( xReport->getCommand().getLength() )
1317 m_xColumns = dbtools::getFieldsByCommandDescriptor(m_pController->getConnection(),xReport->getCommandType(),xReport->getCommand(),m_xHoldAlive);
1318 m_pFieldExpression->fillColumns(m_xColumns);
1320 // -----------------------------------------------------------------------------
1321 void OGroupsSortingDialog::displayGroup(const uno::Reference<report::XGroup>& _xGroup)
1323 m_aHeaderLst.SelectEntryPos(_xGroup->getHeaderOn() ? 0 : 1 );
1324 m_aFooterLst.SelectEntryPos(_xGroup->getFooterOn() ? 0 : 1 );
1325 sal_Int32 nDataType = getColumnDataType(_xGroup->getExpression());
1327 // first clear whole group on list
1328 while(m_aGroupOnLst.GetEntryCount() > 1 )
1330 m_aGroupOnLst.RemoveEntry(1);
1333 switch(nDataType)
1335 case sdbc::DataType::LONGVARCHAR:
1336 case sdbc::DataType::VARCHAR:
1337 case sdbc::DataType::CHAR:
1338 m_aGroupOnLst.InsertEntry(String(ModuleRes(STR_RPT_PREFIXCHARS)));
1339 m_aGroupOnLst.SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::PREFIX_CHARACTERS));
1340 break;
1341 case sdbc::DataType::DATE:
1342 case sdbc::DataType::TIME:
1343 case sdbc::DataType::TIMESTAMP:
1345 USHORT nIds[] = { STR_RPT_YEAR, STR_RPT_QUARTER,STR_RPT_MONTH,STR_RPT_WEEK,STR_RPT_DAY,STR_RPT_HOUR,STR_RPT_MINUTE };
1346 for (USHORT i = 0; i < sizeof(nIds)/sizeof(nIds[0]); ++i)
1348 m_aGroupOnLst.InsertEntry(String(ModuleRes(nIds[i])));
1349 m_aGroupOnLst.SetEntryData(i+1,reinterpret_cast<void*>(i+2));
1352 break;
1353 default:
1354 m_aGroupOnLst.InsertEntry(String(ModuleRes(STR_RPT_INTERVAL)));
1355 m_aGroupOnLst.SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::INTERVAL));
1356 break;
1357 } // switch(nDataType)
1358 USHORT nPos = 0;
1359 switch(_xGroup->getGroupOn())
1361 case report::GroupOn::DEFAULT:
1362 nPos = 0;
1363 break;
1364 case report::GroupOn::PREFIX_CHARACTERS:
1365 nPos = 1;
1366 break;
1367 case report::GroupOn::YEAR:
1368 nPos = 1;
1369 break;
1370 case report::GroupOn::QUARTAL:
1371 nPos = 2;
1372 break;
1373 case report::GroupOn::MONTH:
1374 nPos = 3;
1375 break;
1376 case report::GroupOn::WEEK:
1377 nPos = 4;
1378 break;
1379 case report::GroupOn::DAY:
1380 nPos = 5;
1381 break;
1382 case report::GroupOn::HOUR:
1383 nPos = 6;
1384 break;
1385 case report::GroupOn::MINUTE:
1386 nPos = 7;
1387 break;
1388 case report::GroupOn::INTERVAL:
1389 nPos = 1;
1390 break;
1391 default:
1392 nPos = 0;
1394 m_aGroupOnLst.SelectEntryPos(nPos);
1395 m_aGroupIntervalEd.SetText(String::CreateFromInt32(_xGroup->getGroupInterval()));
1396 m_aGroupIntervalEd.SaveValue();
1397 m_aGroupIntervalEd.Enable( nPos != 0 );
1398 m_aKeepTogetherLst.SelectEntryPos(_xGroup->getKeepTogether());
1399 m_aOrderLst.SelectEntryPos(_xGroup->getSortAscending() ? 0 : 1);
1401 ListBox* pControls[] = { &m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aKeepTogetherLst,&m_aOrderLst};
1402 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1403 pControls[i]->SaveValue();
1405 ListBox* pControlsLst2[] = { &m_aHeaderLst, &m_aFooterLst, &m_aGroupOnLst, &m_aKeepTogetherLst,&m_aOrderLst};
1406 sal_Bool bReadOnly = !m_pController->isEditable();
1407 for (size_t i = 0; i < sizeof(pControlsLst2)/sizeof(pControlsLst2[0]); ++i)
1408 pControlsLst2[i]->SetReadOnly(bReadOnly);
1409 m_aGroupIntervalEd.SetReadOnly(bReadOnly);
1411 //------------------------------------------------------------------------------
1412 void OGroupsSortingDialog::Resize()
1414 Window::Resize();
1415 Size aTotalOutputSize = GetOutputSizePixel();
1416 Size aSpace = LogicToPixel( Size( UNRELATED_CONTROLS, UNRELATED_CONTROLS ), MAP_APPFONT );
1417 m_pFieldExpression->SetSizePixel(Size(aTotalOutputSize.Width() - 2*aSpace.Width(),m_pFieldExpression->GetSizePixel().Height()));
1419 Control* pControlsLst[] = { &m_aHeaderLst, &m_aFooterLst, &m_aGroupOnLst, &m_aGroupIntervalEd,&m_aKeepTogetherLst,&m_aOrderLst};
1420 Control* pControls[] = { &m_aHeader, &m_aFooter, &m_aGroupOn, &m_aGroupInterval, &m_aKeepTogether, &m_aOrder};
1421 sal_Int32 nMaxTextWidth = 0;
1422 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1424 nMaxTextWidth = ::std::max<sal_Int32>(static_cast<sal_Int32>(GetTextWidth(pControls[i]->GetText())),nMaxTextWidth);
1425 } // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1427 // aTotalOutputSize.Width() - m_aHeaderLst.GetSizePixel().Width() - 3*aSpace.Width()
1428 for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1430 pControls[i]->SetSizePixel(Size(nMaxTextWidth,pControls[i]->GetSizePixel().Height()));
1431 Point aPos = pControls[i]->GetPosPixel();
1432 aPos.X() += nMaxTextWidth + aSpace.Width();
1433 aPos.Y() = pControlsLst[i]->GetPosPixel().Y();
1435 pControlsLst[i]->SetPosSizePixel(aPos,Size(aTotalOutputSize.Width() - aPos.X() - aSpace.Width(),pControlsLst[i]->GetSizePixel().Height()));
1436 } // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1438 m_aFL.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL.GetSizePixel().Height()));
1439 m_aFL2.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL2.GetSizePixel().Height()));
1440 m_aFL3.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL3.GetSizePixel().Height()));
1442 //BTN sal_Int32 nPos = aTotalOutputSize.Width() - aSpace.Width() - m_aPB_Up.GetSizePixel().Width();
1443 //BTN m_aPB_Delete.SetPosPixel(Point(nPos,m_aPB_Delete.GetPosPixel().Y()));
1444 //BTN
1445 //BTN nPos -= (m_aPB_Up.GetSizePixel().Width() + LogicToPixel( Size( UNRELATED_CONTROLS, 0 ), MAP_APPFONT ).Width());
1446 //BTN m_aPB_Down.SetPosPixel(Point(nPos,m_aPB_Down.GetPosPixel().Y()));
1447 //BTN
1448 //BTN nPos -= (m_aPB_Up.GetSizePixel().Width() + LogicToPixel( Size( RELATED_CONTROLS, 0 ), MAP_APPFONT ).Width());
1449 //BTN m_aPB_Up.SetPosPixel(Point(nPos,m_aPB_Up.GetPosPixel().Y()));
1450 sal_Int32 nPos = aTotalOutputSize.Width() - aSpace.Width() - m_aToolBox.GetSizePixel().Width();
1451 m_aToolBox.SetPosPixel(Point(nPos,m_aToolBox.GetPosPixel().Y()));
1453 Point aHelpPos = m_aHelpWindow.GetPosPixel();
1454 m_aHelpWindow.SetSizePixel(Size(aTotalOutputSize.Width() - aHelpPos.X(),aTotalOutputSize.Height() - aHelpPos.Y()));
1456 //------------------------------------------------------------------------------
1457 void OGroupsSortingDialog::checkButtons(sal_Int32 _nRow)
1459 sal_Int32 nGroupCount = m_xGroups->getCount();
1460 sal_Int32 nRowCount = m_pFieldExpression->GetRowCount();
1461 sal_Bool bEnabled = nGroupCount > 1;
1463 if (bEnabled && _nRow > 0 /* && _nRow < nGroupCount */ )
1465 m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_UP, sal_True);
1467 else
1469 m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_UP, sal_False);
1471 if (bEnabled && _nRow < (nRowCount - 1) /* && _nRow < (nGroupCount - 1) */ )
1473 m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_DOWN, sal_True);
1475 else
1477 m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_DOWN, sal_False);
1479 //BTN m_aPB_Up.Enable(bEnable && _nRow > 0 );
1480 //BTN m_aPB_Down.Enable(bEnable && _nRow < (m_pFieldExpression->GetRowCount()-1) );
1481 // m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_DOWN, bEnable && _nRow < (-1) );
1483 sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1484 if ( nGroupPos != NO_GROUP )
1486 sal_Bool bEnableDelete = nGroupCount > 0;
1487 //BTN m_aPB_Delete.Enable(bEnableDelete );
1488 m_aToolBox.EnableItem(SID_RPT_GROUPSORT_DELETE, bEnableDelete);
1490 else
1492 //BTN m_aPB_Delete.Enable( sal_False );
1493 m_aToolBox.EnableItem(SID_RPT_GROUPSORT_DELETE, sal_False);
1497 ImageList OGroupsSortingDialog::getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
1499 sal_Int16 nN = IMG_CONDFORMAT_DLG_SC;
1500 sal_Int16 nH = IMG_CONDFORMAT_DLG_SCH;
1501 if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
1503 nN = IMG_CONDFORMAT_DLG_LC;
1504 nH = IMG_CONDFORMAT_DLG_LCH;
1506 return ImageList(ModuleRes( _bHiContast ? nH : nN ));
1509 //------------------------------------------------------------------
1510 void OGroupsSortingDialog::resizeControls(const Size& _rDiff)
1512 // we use large images so we must change them
1513 if ( _rDiff.Width() || _rDiff.Height() )
1515 Point aPos = LogicToPixel( Point( 2*RELATED_CONTROLS , 0), MAP_APPFONT );
1516 Invalidate();
1520 //------------------------------------------------------------------
1521 // load the images
1522 ImageList OGroupsSortingDialog::getImageList(vcl::ImageListType _eType) SAL_THROW (( com::sun::star::lang::IllegalArgumentException ))
1524 if (_eType == vcl::HIGHCONTRAST_NO)
1526 return ImageList(ModuleRes(IMGLST_GROUPSORT_DLG_SC));
1528 else if (_eType == vcl::HIGHCONTRAST_YES)
1530 return ImageList(ModuleRes(IMGLST_GROUPSORT_DLG_SCH));
1532 else
1534 throw com::sun::star::lang::IllegalArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("High contrast parameter is wrong.")), NULL, 0);
1540 // =============================================================================
1541 } // rptui
1542 // =============================================================================