1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "precompiled_reportdesign.hxx"
28 #include "GroupsSorting.hxx"
29 #include "GroupsSorting.hrc"
30 #include <connectivity/dbtools.hxx>
31 #include <svtools/editbrowsebox.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/container/XContainerListener.hpp>
34 #include <com/sun/star/report/GroupOn.hpp>
35 #include <com/sun/star/sdbc/DataType.hpp>
36 
37 #include <tools/debug.hxx>
38 #include "RptResId.hrc"
39 #include "rptui_slotid.hrc"
40 #include "ModuleHelper.hxx"
41 #include "helpids.hrc"
42 
43 #include <svx/globlmn.hrc>
44 #include <svx/svxids.hrc>
45 #include <svtools/imgdef.hxx>
46 
47 #include "GroupExchange.hxx"
48 #include "UITools.hxx"
49 #include "UndoActions.hxx"
50 #include "uistrings.hrc"
51 #include "ReportController.hxx"
52 #include "ColumnInfo.hxx"
53 
54 #include <cppuhelper/implbase1.hxx>
55 #include <comphelper/property.hxx>
56 #include <vcl/mnemonic.hxx>
57 #include <vcl/msgbox.hxx>
58 #include <algorithm>
59 #include <boost/bind.hpp>
60 
61 #include <cppuhelper/bootstrap.hxx>
62 
63 #define HANDLE_ID			0
64 #define FIELD_EXPRESSION	1
65 #define GROUPS_START_LEN	5
66 #define NO_GROUP            -1
67 
68 namespace rptui
69 {
70 using namespace ::com::sun::star;
71 using namespace svt;
72 using namespace ::comphelper;
73 
74     void lcl_addToList_throw( ComboBoxControl& _rListBox, ::std::vector<ColumnInfo>& o_aColumnList,const uno::Reference< container::XNameAccess>& i_xColumns )
75     {
76         uno::Sequence< ::rtl::OUString > aEntries = i_xColumns->getElementNames();
77 		const ::rtl::OUString* pEntries = aEntries.getConstArray();
78 		sal_Int32 nEntries = aEntries.getLength();
79 		for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
80         {
81             uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(*pEntries),uno::UNO_QUERY_THROW);
82             ::rtl::OUString sLabel;
83             if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
84                 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
85             o_aColumnList.push_back( ColumnInfo(*pEntries,sLabel) );
86             if ( sLabel.getLength() )
87 			    _rListBox.InsertEntry( sLabel );
88             else
89                 _rListBox.InsertEntry( *pEntries );
90         }
91     }
92 
93 typedef ::svt::EditBrowseBox OFieldExpressionControl_Base;
94 typedef ::cppu::WeakImplHelper1< container::XContainerListener > TContainerListenerBase;
95 class OFieldExpressionControl : public TContainerListenerBase
96                                ,public OFieldExpressionControl_Base
97 {
98     ::osl::Mutex                    m_aMutex;
99     ::std::vector<sal_Int32>        m_aGroupPositions;
100     ::std::vector<ColumnInfo>       m_aColumnInfo;
101 	::svt::ComboBoxControl*			m_pComboCell;
102 	sal_Int32						m_nDataPos;
103 	sal_Int32						m_nCurrentPos;
104 	sal_uLong							m_nPasteEvent;
105 	sal_uLong							m_nDeleteEvent;
106 	OGroupsSortingDialog*			m_pParent;
107     bool                            m_bIgnoreEvent;
108 
109 
110 	void fillListBox(const uno::Reference< beans::XPropertySet>& _xDest,long nRow,sal_uInt16 nColumnId);
111     sal_Bool SaveModified(bool _bAppend);
112 
113     OFieldExpressionControl(const OFieldExpressionControl&); // NO COPY
114     void operator =(const OFieldExpressionControl&);         // NO ASSIGN
115 public:
116 	OFieldExpressionControl( OGroupsSortingDialog* _pParent,const ResId& _rResId);
117 	virtual ~OFieldExpressionControl();
118 
119     // XEventListener
120     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
121     // XContainerListener
122 	virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
123 	virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
124 	virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException);
125 
126     void		fillColumns(const uno::Reference< container::XNameAccess>& _xColumns);
127 	void		lateInit();
128 	sal_Bool	IsDeleteAllowed( );
129 	void		DeleteRows();
130 	void		cut();
131 	void		copy();
132 	void		paste();
133 
134     inline sal_Int32   getGroupPosition(sal_Int32 _nRow) const { return _nRow != BROWSER_ENDOFSELECTION ? m_aGroupPositions[_nRow] : sal_Int32(NO_GROUP); }
135 
136 	inline ::svt::ComboBoxControl*	getExpressionControl() const { return m_pComboCell; }
137 
138 
139 	/** returns the sequence with the selected groups
140 	*/
141 	uno::Sequence<uno::Any> fillSelectedGroups();
142 
143 	/** move groups given by _aGroups
144 	*/
145 	void moveGroups(const uno::Sequence<uno::Any>& _aGroups,sal_Int32 _nRow,sal_Bool _bSelect = sal_True);
146 
147 	virtual sal_Bool CursorMoving(long nNewRow, sal_uInt16 nNewCol);
148     using OFieldExpressionControl_Base::GetRowCount;
149 protected:
150 	virtual sal_Bool IsTabAllowed(sal_Bool bForward) const;
151 
152 
153 	virtual void InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol );
154 	virtual ::svt::CellController* GetController( long nRow, sal_uInt16 nCol );
155 	virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColId ) const;
156 	virtual sal_Bool SeekRow( long nRow );
157 	virtual sal_Bool SaveModified();
158 	virtual String GetCellText( long nRow, sal_uInt16 nColId ) const;
159 	virtual RowStatus GetRowStatus(long nRow) const;
160 
161 	virtual void KeyInput(const KeyEvent& rEvt);
162 	virtual void Command( const CommandEvent& rEvt );
163 
164 	// D&D
165 	virtual void	 StartDrag( sal_Int8 nAction, const Point& rPosPixel );
166 	virtual sal_Int8 AcceptDrop( const BrowserAcceptDropEvent& rEvt );
167 	virtual sal_Int8 ExecuteDrop( const BrowserExecuteDropEvent& rEvt );
168 
169     using BrowseBox::AcceptDrop;
170     using BrowseBox::ExecuteDrop;
171 
172 private:
173 
174 	DECL_LINK( AsynchActivate, void* );
175 	DECL_LINK( AsynchDeactivate, void* );
176 	DECL_LINK( DelayedPaste, void* );
177     DECL_LINK( CBChangeHdl,ComboBox*);
178 
179 	void InsertRows( long nRow );
180 
181 public:
182 	DECL_LINK( DelayedDelete, void* );
183 
184 };
185 //========================================================================
186 // class OFieldExpressionControl
187 //========================================================================
188 DBG_NAME( rpt_OFieldExpressionControl )
189 //------------------------------------------------------------------------
190 OFieldExpressionControl::OFieldExpressionControl( OGroupsSortingDialog* _pParent,const ResId& _rResId )
191 	:EditBrowseBox( _pParent, _rResId,EBBF_NONE, WB_TABSTOP | BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_AUTOSIZE_LASTCOL |
192 								  BROWSER_KEEPSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL)
193     ,m_aGroupPositions(GROUPS_START_LEN,-1)
194 	,m_pComboCell(NULL)
195 	,m_nDataPos(-1)
196 	,m_nCurrentPos(-1)
197 	,m_nPasteEvent(0)
198 	,m_nDeleteEvent(0)
199 	,m_pParent(_pParent)
200     ,m_bIgnoreEvent(false)
201 {
202 	DBG_CTOR( rpt_OFieldExpressionControl,NULL);
203     SetBorderStyle(WINDOW_BORDER_MONO);
204 }
205 
206 //------------------------------------------------------------------------
207 OFieldExpressionControl::~OFieldExpressionControl()
208 {
209     acquire();
210     uno::Reference< report::XGroups > xGroups = m_pParent->getGroups();
211     xGroups->removeContainerListener(this);
212 	//////////////////////////////////////////////////////////////////////
213 	// delete events from queue
214 	if( m_nPasteEvent )
215 		Application::RemoveUserEvent( m_nPasteEvent );
216 	if( m_nDeleteEvent )
217 		Application::RemoveUserEvent( m_nDeleteEvent );
218 
219 	delete m_pComboCell;
220     DBG_DTOR( rpt_OFieldExpressionControl,NULL);
221 }
222 //------------------------------------------------------------------------------
223 uno::Sequence<uno::Any> OFieldExpressionControl::fillSelectedGroups()
224 {
225 	uno::Sequence<uno::Any> aList;
226 	::std::vector<uno::Any> vClipboardList;
227 	vClipboardList.reserve(GetSelectRowCount());
228 
229 	uno::Reference<report::XGroups> xGroups = m_pParent->getGroups();
230 	sal_Int32 nCount = xGroups->getCount();
231 	if ( nCount >= 1 )
232 	{
233 		for( long nIndex=FirstSelectedRow(); nIndex >= 0 ; nIndex=NextSelectedRow() )
234 		{
235             try
236             {
237                 if ( m_aGroupPositions[nIndex] != NO_GROUP )
238                 {
239                     uno::Reference< report::XGroup> xOrgGroup(xGroups->getByIndex(m_aGroupPositions[nIndex]),uno::UNO_QUERY);
240                     /*uno::Reference< report::XGroup> xCopy = xGroups->createGroup();
241                     ::comphelper::copyProperties(xOrgGroup.get(),xCopy.get());*/
242                     vClipboardList.push_back( uno::makeAny(xOrgGroup) );
243                 }
244             }
245             catch(uno::Exception&)
246             {
247                 OSL_ENSURE(0,"Can not access group!");
248             }
249 		}
250 		if ( !vClipboardList.empty() )
251 			aList = uno::Sequence< uno::Any >(&vClipboardList[0], vClipboardList.size());
252 	} // if ( nCount > 1 )
253 	return aList;
254 }
255 //------------------------------------------------------------------------------
256 void OFieldExpressionControl::StartDrag( sal_Int8 /*_nAction*/ , const Point& /*_rPosPixel*/ )
257 {
258 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
259 	if ( m_pParent && !m_pParent->isReadOnly( ) )
260 	{
261 		uno::Sequence<uno::Any> aClipboardList = fillSelectedGroups();
262 
263 		if( aClipboardList.getLength() )
264 		{
265 			OGroupExchange* pData = new OGroupExchange(aClipboardList);
266 			uno::Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
267 			pData->StartDrag(this, DND_ACTION_MOVE );
268 		} // if(!vClipboardList.empty())
269 	}
270 }
271 //------------------------------------------------------------------------------
272 sal_Int8 OFieldExpressionControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
273 {
274 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
275 	sal_Int8 nAction = DND_ACTION_NONE;
276     if ( IsEditing() )
277 	{
278         sal_uInt16 nPos = m_pComboCell->GetSelectEntryPos();
279 		if ( COMBOBOX_ENTRY_NOTFOUND != nPos || m_pComboCell->GetText().Len() )
280     		SaveModified();
281 		DeactivateCell();
282 	}
283 	if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) && m_pParent->getGroups()->getCount() > 1 && rEvt.GetWindow() == &GetDataWindow() )
284 	{
285 		nAction = DND_ACTION_MOVE;
286 	}
287 	return nAction;
288 }
289 //------------------------------------------------------------------------------
290 sal_Int8 OFieldExpressionControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
291 {
292 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
293 	sal_Int8 nAction = DND_ACTION_NONE;
294 	if ( IsDropFormatSupported( OGroupExchange::getReportGroupId() ) )
295 	{
296 		sal_Int32	nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
297 		SetNoSelection();
298 
299 		TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
300 		uno::Any aDrop = aDropped.GetAny(OGroupExchange::getReportGroupId());
301 		uno::Sequence< uno::Any > aGroups;
302 		aDrop >>= aGroups;
303 		if ( aGroups.getLength() )
304 		{
305 			moveGroups(aGroups,nRow);
306 			nAction = DND_ACTION_MOVE;
307 		}
308 	}
309 	return nAction;
310 }
311 //------------------------------------------------------------------------------
312 void OFieldExpressionControl::moveGroups(const uno::Sequence<uno::Any>& _aGroups,sal_Int32 _nRow,sal_Bool _bSelect)
313 {
314 	if ( _aGroups.getLength() )
315 	{
316         m_bIgnoreEvent = true;
317         {
318 		    sal_Int32 nRow = _nRow;
319 		    const String sUndoAction(ModuleRes(RID_STR_UNDO_MOVE_GROUP));
320             const UndoContext aUndoContext( m_pParent->m_pController->getUndoManager(), sUndoAction );
321 
322 		    uno::Reference< report::XGroups> xGroups = m_pParent->getGroups();
323 		    const uno::Any* pIter = _aGroups.getConstArray();
324 		    const uno::Any* pEnd  = pIter + _aGroups.getLength();
325 		    for(;pIter != pEnd;++pIter)
326 		    {
327 			    uno::Reference< report::XGroup> xGroup(*pIter,uno::UNO_QUERY);
328 			    if ( xGroup.is() )
329 			    {
330 				    uno::Sequence< beans::PropertyValue > aArgs(1);
331 				    aArgs[0].Name = PROPERTY_GROUP;
332 				    aArgs[0].Value <<= xGroup;
333 				    // we use this way to create undo actions
334 				    m_pParent->m_pController->executeChecked(SID_GROUP_REMOVE,aArgs);
335 				    aArgs.realloc(2);
336 				    if ( nRow > xGroups->getCount() )
337 					    nRow = xGroups->getCount();
338 				    if ( _bSelect )
339 					    SelectRow(nRow);
340 				    aArgs[1].Name = PROPERTY_POSITIONY;
341 				    aArgs[1].Value <<= nRow;
342 				    m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
343 				    ++nRow;
344 			    }
345 		    } // for(;pIter != pEnd;++pIter)
346         }
347         m_bIgnoreEvent = false;
348 		Invalidate();
349 	} // if ( _aGroups.getLength() )
350 }
351 // -----------------------------------------------------------------------------
352 void OFieldExpressionControl::fillColumns(const uno::Reference< container::XNameAccess>& _xColumns)
353 {
354     m_pComboCell->Clear();
355     if ( _xColumns.is() )
356         lcl_addToList_throw(*m_pComboCell,m_aColumnInfo,_xColumns);
357 }
358 //------------------------------------------------------------------------------
359 void OFieldExpressionControl::lateInit()
360 {
361     uno::Reference< report::XGroups > xGroups = m_pParent->getGroups();
362     sal_Int32 nGroupsCount = xGroups->getCount();
363     m_aGroupPositions.resize(::std::max<sal_Int32>(nGroupsCount,sal_Int32(GROUPS_START_LEN)),NO_GROUP);
364     ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
365     for (sal_Int32 i = 0; i < nGroupsCount; ++i,++aIter)
366         *aIter = i;
367 
368 	if ( ColCount() == 0 )
369 	{
370 		Font aFont( GetDataWindow().GetFont() );
371 		aFont.SetWeight( WEIGHT_NORMAL );
372 		GetDataWindow().SetFont( aFont );
373 
374 		// Font fuer die Ueberschriften auf Light setzen
375 		aFont = GetFont();
376 		aFont.SetWeight( WEIGHT_LIGHT );
377 		SetFont(aFont);
378 
379 		InsertHandleColumn(static_cast<sal_uInt16>(GetTextWidth('0') * 4)/*, sal_True */);
380 		InsertDataColumn( FIELD_EXPRESSION, String(ModuleRes(STR_RPT_EXPRESSION)), 100);
381 
382 		m_pComboCell = new ComboBoxControl( &GetDataWindow() );
383         m_pComboCell->SetSelectHdl(LINK(this,OFieldExpressionControl,CBChangeHdl));
384 		m_pComboCell->SetHelpId(HID_RPT_FIELDEXPRESSION);
385 
386 		Control* pControls[] = {m_pComboCell};
387 		for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
388 		{
389 			pControls[i]->SetGetFocusHdl(LINK(m_pParent, OGroupsSortingDialog, OnControlFocusGot));
390 			pControls[i]->SetLoseFocusHdl(LINK(m_pParent, OGroupsSortingDialog, OnControlFocusLost));
391 		}
392 
393 		//////////////////////////////////////////////////////////////////////
394 		// set browse mode
395 		BrowserMode nMode(BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION	| BROWSER_KEEPSELECTION |
396 						  BROWSER_HLINESFULL | BROWSER_VLINESFULL		| BROWSER_AUTOSIZE_LASTCOL | BROWSER_AUTO_VSCROLL | BROWSER_AUTO_HSCROLL);
397 		if( m_pParent->isReadOnly() )
398 			nMode |= BROWSER_HIDECURSOR;
399 		SetMode(nMode);
400         xGroups->addContainerListener(this);
401 	}
402 	else
403 		// not the first call
404 		RowRemoved(0, GetRowCount());
405 
406     RowInserted(0, m_aGroupPositions.size(), sal_True);
407 }
408 // -----------------------------------------------------------------------------
409 // -----------------------------------------------------------------------------
410 IMPL_LINK( OFieldExpressionControl, CBChangeHdl, ComboBox*, /*pComboBox*/ )
411 {
412 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
413 
414     SaveModified();
415     return 0L;
416 }
417 //------------------------------------------------------------------------------
418 IMPL_LINK(OFieldExpressionControl, AsynchActivate, void*, EMPTYARG)
419 {
420 	ActivateCell();
421 	return 0L;
422 }
423 
424 //------------------------------------------------------------------------------
425 IMPL_LINK(OFieldExpressionControl, AsynchDeactivate, void*, EMPTYARG)
426 {
427 	DeactivateCell();
428 	return 0L;
429 }
430 
431 //------------------------------------------------------------------------------
432 sal_Bool OFieldExpressionControl::IsTabAllowed(sal_Bool /*bForward*/) const
433 {
434 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
435 	return sal_False;
436 }
437 
438 //------------------------------------------------------------------------------
439 sal_Bool OFieldExpressionControl::SaveModified()
440 {
441 	return SaveModified(true);
442 }
443 //------------------------------------------------------------------------------
444 sal_Bool OFieldExpressionControl::SaveModified(bool _bAppendRow)
445 {
446 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
447 	sal_Int32 nRow = GetCurRow();
448 	if ( nRow != BROWSER_ENDOFSELECTION )
449 	{
450         sal_Bool bAppend = sal_False;
451         try
452         {
453 		    uno::Reference< report::XGroup> xGroup;
454 		    if ( m_aGroupPositions[nRow] == NO_GROUP )
455 		    {
456                 bAppend = sal_True;
457                 String sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP));
458                 m_pParent->m_pController->getUndoManager().EnterListAction( sUndoAction, String() );
459 			    xGroup = m_pParent->getGroups()->createGroup();
460                 xGroup->setHeaderOn(sal_True);
461 
462 			    uno::Sequence< beans::PropertyValue > aArgs(2);
463 			    aArgs[0].Name = PROPERTY_GROUP;
464 			    aArgs[0].Value <<= xGroup;
465                 // find position where to insert the new group
466                 sal_Int32 nGroupPos = 0;
467                 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
468                 ::std::vector<sal_Int32>::iterator aEnd  = m_aGroupPositions.begin() + nRow;
469                 for(;aIter != aEnd;++aIter)
470                     if ( *aIter != NO_GROUP )
471                         nGroupPos = *aIter + 1;
472                 aArgs[1].Name = PROPERTY_POSITIONY;
473 				aArgs[1].Value <<= nGroupPos;
474                 m_bIgnoreEvent = true;
475 			    m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
476                 m_bIgnoreEvent = false;
477                 OSL_ENSURE(*aIter == NO_GROUP ,"Illegal iterator!");
478                 *aIter++ = nGroupPos;
479 
480                 aEnd  = m_aGroupPositions.end();
481                 for(;aIter != aEnd;++aIter)
482                     if ( *aIter != NO_GROUP )
483                         ++*aIter;
484 		    }
485 		    else
486 			    xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
487 		    if ( xGroup.is() )
488 		    {
489 			    sal_uInt16 nPos = m_pComboCell->GetSelectEntryPos();
490                 ::rtl::OUString sExpression;
491 			    if ( COMBOBOX_ENTRY_NOTFOUND == nPos )
492 				    sExpression = m_pComboCell->GetText();
493 			    else
494                 {
495                     sExpression = m_aColumnInfo[nPos].sColumnName;
496                 }
497                 xGroup->setExpression( sExpression );
498 
499 			    ::rptui::adjustSectionName(xGroup,nPos);
500 
501                 if ( bAppend )
502                     m_pParent->m_pController->getUndoManager().LeaveListAction();
503 		    }
504 
505             if ( Controller() )
506                 Controller()->ClearModified();
507             if ( _bAppendRow && GetRowCount() == m_pParent->getGroups()->getCount() )
508             {
509                 RowInserted( GetRowCount()-1);
510                 m_aGroupPositions.push_back(NO_GROUP);
511             }
512 
513             GoToRow(nRow);
514             m_pParent->DisplayData(nRow);
515         }
516         catch(uno::Exception&)
517         {
518             OSL_ENSURE(0,"OFieldExpressionControl::SaveModified: Exception caught!");
519         }
520 	}
521 
522 	return sal_True;
523 }
524 //------------------------------------------------------------------------------
525 String OFieldExpressionControl::GetCellText( long nRow, sal_uInt16 /*nColId*/ ) const
526 {
527 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
528 	String sText;
529 	if ( nRow != BROWSER_ENDOFSELECTION && m_aGroupPositions[nRow] != NO_GROUP )
530     {
531         try
532         {
533 		    uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
534             ::rtl::OUString sExpression = xGroup->getExpression();
535 
536             for(::std::vector<ColumnInfo>::const_iterator aIter = m_aColumnInfo.begin(); aIter != m_aColumnInfo.end();++aIter)
537             {
538                 if ( aIter->sColumnName == sExpression )
539                 {
540                     if ( aIter->sLabel.getLength() )
541                         sExpression = aIter->sLabel;
542                     break;
543                 }
544             }
545             sText  = sExpression;
546         }
547         catch(uno::Exception&)
548         {
549             OSL_ENSURE(0,"Exception caught while getting expression value from the group");
550         }
551 	} // if ( nRow != BROWSER_ENDOFSELECTION && nRow < m_pParent->getGroups()->getCount() )
552 	return sText;
553 }
554 
555 //------------------------------------------------------------------------------
556 void OFieldExpressionControl::InitController( CellControllerRef& /*rController*/, long nRow, sal_uInt16 nColumnId )
557 {
558 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
559 
560 	m_pComboCell->SetText( GetCellText( nRow, nColumnId ) );
561 }
562 //------------------------------------------------------------------------------
563 sal_Bool OFieldExpressionControl::CursorMoving(long nNewRow, sal_uInt16 nNewCol)
564 {
565 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
566 
567 	if (!EditBrowseBox::CursorMoving(nNewRow, nNewCol))
568 		return sal_False;
569 	m_nDataPos = nNewRow;
570 	long nOldDataPos = GetCurRow();
571 	InvalidateStatusCell( m_nDataPos );
572 	InvalidateStatusCell( nOldDataPos );
573 
574 	m_pParent->SaveData( nOldDataPos );
575 	m_pParent->DisplayData( m_nDataPos );
576 	return sal_True;
577 }
578 //------------------------------------------------------------------------------
579 CellController* OFieldExpressionControl::GetController( long /*nRow*/, sal_uInt16 /*nColumnId*/ )
580 {
581 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
582 	ComboBoxCellController* pCellController = new ComboBoxCellController( m_pComboCell );
583     pCellController->GetComboBox().SetReadOnly(!m_pParent->m_pController->isEditable());
584     return pCellController;
585 }
586 
587 //------------------------------------------------------------------------------
588 sal_Bool OFieldExpressionControl::SeekRow( long _nRow )
589 {
590 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
591 	// die Basisklasse braucht den Aufruf, da sie sich dort merkt, welche Zeile gepainted wird
592 	EditBrowseBox::SeekRow(_nRow);
593 	m_nCurrentPos = _nRow;
594 	return sal_True;
595 }
596 
597 //------------------------------------------------------------------------------
598 void OFieldExpressionControl::PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
599 {
600 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
601 	String aText  =const_cast< OFieldExpressionControl*>(this)->GetCellText( m_nCurrentPos, nColumnId );
602 
603 	Point aPos( rRect.TopLeft() );
604 	Size aTextSize( GetDataWindow().GetTextHeight(),GetDataWindow().GetTextWidth( aText ));
605 
606 	if( aPos.X() < rRect.Right() || aPos.X() + aTextSize.Width() > rRect.Right() ||
607 		aPos.Y() < rRect.Top() || aPos.Y() + aTextSize.Height() > rRect.Bottom() )
608 		rDev.SetClipRegion( rRect );
609 
610 	rDev.DrawText( aPos, aText );
611 
612 	if( rDev.IsClipRegion() )
613 		rDev.SetClipRegion();
614 }
615 //------------------------------------------------------------------------------
616 EditBrowseBox::RowStatus OFieldExpressionControl::GetRowStatus(long nRow) const
617 {
618 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
619 	if (nRow >= 0 && nRow == m_nDataPos)
620 		return EditBrowseBox::CURRENT;
621 	if ( nRow != BROWSER_ENDOFSELECTION && nRow < static_cast<long>(m_aGroupPositions.size()) && m_aGroupPositions[nRow] != NO_GROUP )
622 	{
623         try
624         {
625 		    uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(m_aGroupPositions[nRow]);
626 		    return (xGroup->getHeaderOn() || xGroup->getFooterOn())? EditBrowseBox::HEADERFOOTER : EditBrowseBox::CLEAN;
627         }
628         catch(uno::Exception&)
629         {
630             OSL_ENSURE(0,"Exception cathced while try to get a group!");
631         }
632 	}
633 	return EditBrowseBox::CLEAN;
634 }
635 //	XEventListener
636 //------------------------------------------------------------------------------
637 void SAL_CALL OFieldExpressionControl::disposing(const lang::EventObject& /*e*/) throw( uno::RuntimeException )
638 {
639 }
640 //------------------------------------------------------------------------------
641 // XContainerListener
642 //------------------------------------------------------------------------------
643 void SAL_CALL OFieldExpressionControl::elementInserted(const container::ContainerEvent& evt) throw(uno::RuntimeException)
644 {
645     if ( m_bIgnoreEvent )
646         return;
647 	::vos::OClearableGuard aSolarGuard( Application::GetSolarMutex() );
648     ::osl::MutexGuard aGuard( m_aMutex );
649     sal_Int32 nGroupPos = 0;
650     if ( evt.Accessor >>= nGroupPos )
651     {
652         if ( nGroupPos >= GetRowCount() )
653         {
654             sal_Int32 nAddedRows = nGroupPos - GetRowCount();
655             RowInserted(nAddedRows);
656             for (sal_Int32 i = 0; i < nAddedRows; ++i)
657                 m_aGroupPositions.push_back(NO_GROUP);
658             m_aGroupPositions[nGroupPos] = nGroupPos;
659         }
660         else
661         {
662             ::std::vector<sal_Int32>::iterator aFind = m_aGroupPositions.begin()+ nGroupPos;
663             if ( aFind == m_aGroupPositions.end() )
664                 aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),NO_GROUP);
665 
666             if ( aFind != m_aGroupPositions.end() )
667             {
668                 if ( *aFind != NO_GROUP )
669                     aFind = m_aGroupPositions.insert(aFind,nGroupPos);
670                 else
671                     *aFind = nGroupPos;
672 
673                 ::std::vector<sal_Int32>::iterator aEnd  = m_aGroupPositions.end();
674                 for(++aFind;aFind != aEnd;++aFind)
675                     if ( *aFind != NO_GROUP )
676                         ++*aFind;
677 
678                 //::std::vector<sal_Int32>::reverse_iterator aRIter = m_aGroupPositions.rbegin();
679                 //::std::vector<sal_Int32>::reverse_iterator aREnd = m_aGroupPositions.rend();
680                 //for (; aRIter != aREnd && *aRIter != NO_GROUP; ++aRIter)
681                 //    continue;
682                 //if ( aRIter != aREnd )
683                 //    m_aGroupPositions.erase(m_aGroupPositions.begin() + (m_aGroupPositions.size() - 1 - (aRIter - m_aGroupPositions.rbegin())));
684             }
685         }
686         Invalidate();
687     }
688 }
689 //------------------------------------------------------------------------------
690 void SAL_CALL OFieldExpressionControl::elementReplaced(const container::ContainerEvent& /*evt*/) throw(uno::RuntimeException)
691 {
692 }
693 //------------------------------------------------------------------------------
694 void SAL_CALL OFieldExpressionControl::elementRemoved(const container::ContainerEvent& evt) throw(uno::RuntimeException)
695 {
696 	::vos::OClearableGuard aSolarGuard( Application::GetSolarMutex() );
697     ::osl::MutexGuard aGuard( m_aMutex );
698 
699     if ( m_bIgnoreEvent )
700         return;
701 
702 	sal_Int32 nGroupPos = 0;
703     if ( evt.Accessor >>= nGroupPos )
704     {
705         ::std::vector<sal_Int32>::iterator aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),nGroupPos);
706         if ( aFind != m_aGroupPositions.end() )
707         {
708             *aFind = NO_GROUP;
709             ::std::vector<sal_Int32>::iterator aEnd  = m_aGroupPositions.end();
710             for(++aFind;aFind != aEnd;++aFind)
711                 if ( *aFind != NO_GROUP )
712                     --*aFind;
713             //PaintCell(*this,GetFieldRect(FIELD_EXPRESSION),FIELD_EXPRESSION);
714             Invalidate();
715         }
716     }
717 }
718 //------------------------------------------------------------------------------
719 sal_Bool OFieldExpressionControl::IsDeleteAllowed( )
720 {
721 	return !m_pParent->isReadOnly() && GetSelectRowCount() > 0;
722 }
723 //------------------------------------------------------------------------
724 void OFieldExpressionControl::KeyInput( const KeyEvent& rEvt )
725 {
726 	if (IsDeleteAllowed())
727 	{
728 		if (rEvt.GetKeyCode().GetCode() == KEY_DELETE &&	// Delete rows
729 			!rEvt.GetKeyCode().IsShift() &&
730 			!rEvt.GetKeyCode().IsMod1())
731 		{
732 			DeleteRows();
733 			return;
734 		}
735 	}
736 	EditBrowseBox::KeyInput(rEvt);
737 }
738 //------------------------------------------------------------------------
739 void OFieldExpressionControl::Command(const CommandEvent& rEvt)
740 {
741 	switch (rEvt.GetCommand())
742 	{
743 		case COMMAND_CONTEXTMENU:
744 		{
745 			if (!rEvt.IsMouseEvent())
746 			{
747 				EditBrowseBox::Command(rEvt);
748 				return;
749 			}
750 
751 			sal_uInt16 nColId = GetColumnAtXPosPixel(rEvt.GetMousePosPixel().X());
752 
753 			if ( nColId == HANDLE_ID )
754 			{
755 				//long   nRow = GetRowAtYPosPixel(rEvt.GetMousePosPixel().Y());
756 				PopupMenu aContextMenu(ModuleRes(RID_GROUPSROWPOPUPMENU));
757                 sal_Bool bEnable = sal_False;
758                 long nIndex = FirstSelectedRow();
759 	            while( nIndex >= 0 && !bEnable )
760 	            {
761                     if ( m_aGroupPositions[nIndex] != NO_GROUP )
762                         bEnable = sal_True;
763                     nIndex = NextSelectedRow();
764                 }
765 				//aContextMenu.EnableItem( SID_CUT, IsDeleteAllowed() && bEnable);
766 				//aContextMenu.EnableItem( SID_COPY, bEnable);
767                 //TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
768 				//aContextMenu.EnableItem( SID_PASTE, aTransferData.HasFormat(SOT_FORMATSTR_ID_RPT_GRPED) );
769 				aContextMenu.EnableItem( SID_DELETE, IsDeleteAllowed() && bEnable );
770 				switch (aContextMenu.Execute(this, rEvt.GetMousePosPixel()))
771 				{
772 					case SID_CUT:
773                         cut();
774 						break;
775 					case SID_COPY:
776                         copy();
777 						break;
778 					case SID_PASTE:
779                         paste();
780 						break;
781 
782 					case SID_DELETE:
783 						if( m_nDeleteEvent )
784 							Application::RemoveUserEvent( m_nDeleteEvent );
785 						m_nDeleteEvent = Application::PostUserEvent( LINK(this, OFieldExpressionControl, DelayedDelete) );
786 						break;
787 					default:
788 						break;
789 				}
790 			} // if ( nColId == HANDLE_ID )
791 			// run through
792 		}
793 		default:
794 			EditBrowseBox::Command(rEvt);
795 	}
796 
797 }
798 //------------------------------------------------------------------------------
799 void OFieldExpressionControl::DeleteRows()
800 {
801 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
802 
803     sal_Bool bIsEditing = IsEditing();
804     if (bIsEditing)
805     {
806         DeactivateCell();
807     }
808     long nIndex = FirstSelectedRow();
809     if (nIndex == -1)
810     {
811         nIndex = GetCurRow();
812     }
813     bool bFirstTime = true;
814 
815 	long nOldDataPos = nIndex;
816 	uno::Sequence< beans::PropertyValue > aArgs(1);
817 	aArgs[0].Name = PROPERTY_GROUP;
818     m_bIgnoreEvent = true;
819 	while( nIndex >= 0 )
820 	{
821         if ( m_aGroupPositions[nIndex] != NO_GROUP )
822         {
823             if ( bFirstTime )
824             {
825                 bFirstTime = false;
826                 String sUndoAction(ModuleRes(RID_STR_UNDO_REMOVE_SELECTION));
827                 m_pParent->m_pController->getUndoManager().EnterListAction( sUndoAction, String() );
828             }
829 
830             sal_Int32 nGroupPos = m_aGroupPositions[nIndex];
831 		    uno::Reference< report::XGroup> xGroup = m_pParent->getGroup(nGroupPos);
832 		    aArgs[0].Value <<= xGroup;
833 		    // we use this way to create undo actions
834 		    m_pParent->m_pController->executeChecked(SID_GROUP_REMOVE,aArgs);
835 
836             ::std::vector<sal_Int32>::iterator aFind = ::std::find(m_aGroupPositions.begin(),m_aGroupPositions.end(),nGroupPos);
837             *aFind = NO_GROUP;
838             ::std::vector<sal_Int32>::iterator aEnd  = m_aGroupPositions.end();
839             for(++aFind;aFind != aEnd;++aFind)
840                 if ( *aFind != NO_GROUP )
841                     --*aFind;
842         }
843 		nIndex = NextSelectedRow();
844 	} // while( nIndex >= 0 )
845 
846     if ( !bFirstTime )
847         m_pParent->m_pController->getUndoManager().LeaveListAction();
848 
849 	m_nDataPos = GetCurRow();
850 	InvalidateStatusCell( nOldDataPos );
851 	InvalidateStatusCell( m_nDataPos );
852 	ActivateCell();
853 	m_pParent->DisplayData( m_nDataPos );
854     m_bIgnoreEvent = false;
855     Invalidate();
856 }
857 //------------------------------------------------------------------------------
858 //------------------------------------------------------------------------------
859 void OFieldExpressionControl::cut()
860 {
861 	copy();
862 	DeleteRows();
863 }
864 
865 //------------------------------------------------------------------------------
866 void OFieldExpressionControl::copy()
867 {
868 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
869 	//////////////////////////////////////////////////////////////////////
870 	// set to the right row and save it
871 	m_pParent->SaveData( m_nDataPos );
872 
873 	uno::Sequence<uno::Any> aClipboardList = fillSelectedGroups();
874 
875 	if( aClipboardList.getLength() )
876 	{
877 		OGroupExchange* pData = new OGroupExchange(aClipboardList);
878 		uno::Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
879 		pData->CopyToClipboard(GetParent());
880 	}
881 }
882 
883 //------------------------------------------------------------------------------
884 void OFieldExpressionControl::paste()
885 {
886 	TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
887 	if(aTransferData.HasFormat(OGroupExchange::getReportGroupId()))
888 	{
889 		if( m_nPasteEvent )
890 			Application::RemoveUserEvent( m_nPasteEvent );
891 		m_nPasteEvent = Application::PostUserEvent( LINK(this, OFieldExpressionControl, DelayedPaste) );
892 	}
893 }
894 //------------------------------------------------------------------------------
895 IMPL_LINK( OFieldExpressionControl, DelayedPaste, void*,  )
896 {
897 	m_nPasteEvent = 0;
898 
899 	sal_Int32 nPastePosition = GetSelectRowCount() ? FirstSelectedRow() : GetCurRow();
900 
901 	InsertRows( nPastePosition );
902 	SetNoSelection();
903 	GoToRow( nPastePosition );
904 
905 	return 0;
906 }
907 //------------------------------------------------------------------------------
908 IMPL_LINK( OFieldExpressionControl, DelayedDelete, void*,  )
909 {
910 	m_nDeleteEvent = 0;
911 	DeleteRows();
912 	return 0;
913 }
914 //------------------------------------------------------------------------------
915 void OFieldExpressionControl::InsertRows( long nRow )
916 {
917 	DBG_CHKTHIS( rpt_OFieldExpressionControl,NULL);
918 
919 	sal_Int32 nSize = 0;
920 	//////////////////////////////////////////////////////////////////////
921 	// get rows from clipboard
922 	TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
923 	if(aTransferData.HasFormat(OGroupExchange::getReportGroupId()))
924 	{
925 		datatransfer::DataFlavor aFlavor;
926 		SotExchange::GetFormatDataFlavor(OGroupExchange::getReportGroupId(), aFlavor);
927 		uno::Sequence< uno::Any > aGroups;
928 
929 		if( (aTransferData.GetAny(aFlavor) >>= aGroups) && aGroups.getLength() )
930 		{
931             m_bIgnoreEvent = false;
932             {
933                 const String sUndoAction(ModuleRes(RID_STR_UNDO_APPEND_GROUP));
934                 const UndoContext aUndoContext( m_pParent->m_pController->getUndoManager(), sUndoAction );
935 
936 			    uno::Reference<report::XGroups> xGroups = m_pParent->getGroups();
937                 sal_Int32 nGroupPos = 0;
938                 ::std::vector<sal_Int32>::iterator aIter = m_aGroupPositions.begin();
939                 ::std::vector<sal_Int32>::size_type nRowPos = static_cast< ::std::vector<sal_Int32>::size_type >(nRow);
940                 if ( nRowPos < m_aGroupPositions.size() )
941                 {
942                     ::std::vector<sal_Int32>::iterator aEnd  = m_aGroupPositions.begin() + nRowPos;
943                     for(;aIter != aEnd;++aIter)
944                     {
945                         if ( *aIter != NO_GROUP )
946                             nGroupPos = *aIter;
947                     }
948                 }
949 			    for(sal_Int32 i=0;i < aGroups.getLength();++i,++nSize)
950 			    {
951                     uno::Sequence< beans::PropertyValue > aArgs(2);
952 			        aArgs[0].Name = PROPERTY_GROUP;
953 			        aArgs[0].Value = aGroups[i];
954                     aArgs[1].Name = PROPERTY_POSITIONY;
955 				    aArgs[1].Value <<= nGroupPos;
956 			        m_pParent->m_pController->executeChecked(SID_GROUP_APPEND,aArgs);
957 
958                     ::std::vector<sal_Int32>::iterator aInsertPos = m_aGroupPositions.insert(aIter,nGroupPos);
959                     ++aInsertPos;
960                     aIter = aInsertPos;
961                     ::std::vector<sal_Int32>::iterator aEnd  = m_aGroupPositions.end();
962                     for(;aInsertPos != aEnd;++aInsertPos)
963                         if ( *aInsertPos != NO_GROUP )
964                             ++*aInsertPos;
965 			    }
966             }
967             m_bIgnoreEvent = true;
968 		}
969 	}
970 
971 	RowInserted( nRow,nSize,sal_True );
972 }
973 //------------------------------------------------------------------------------
974 
975 DBG_NAME( rpt_OGroupsSortingDialog )
976 //========================================================================
977 // class OGroupsSortingDialog
978 //========================================================================
979 OGroupsSortingDialog::OGroupsSortingDialog( Window* _pParent
980 										   ,sal_Bool _bReadOnly
981 										   ,OReportController* _pController)
982 	: FloatingWindow( _pParent, ModuleRes(RID_GROUPS_SORTING) )
983 	,OPropertyChangeListener(m_aMutex)
984 	,m_aFL2(this, ModuleRes(FL_SEPARATOR2) )
985 	,m_aMove(this, ModuleRes(FT_MOVELABEL) )
986 /*
987 	,m_aPB_Up(this, ModuleRes(PB_UP) )
988 	,m_aPB_Down(this, ModuleRes(PB_DOWN) )
989 	,m_aPB_Delete(this, ModuleRes(PB_DELETE) )
990 */
991     ,m_aToolBox(this, ModuleRes(TB_TOOLBOX) )
992 
993 	,m_aFL3(this, ModuleRes(FL_SEPARATOR3) )
994 	,m_aOrder(this, ModuleRes(FT_ORDER) )
995 	,m_aOrderLst(this, ModuleRes(LST_ORDER) )
996     ,m_aHeader(this, ModuleRes(FT_HEADER) )
997 	,m_aHeaderLst(this, ModuleRes(LST_HEADERLST) )
998 	,m_aFooter(this, ModuleRes(FT_FOOTER) )
999 	,m_aFooterLst(this, ModuleRes(LST_FOOTERLST) )
1000 	,m_aGroupOn(this, ModuleRes(FT_GROUPON) )
1001 	,m_aGroupOnLst(this, ModuleRes(LST_GROUPONLST) )
1002 	,m_aGroupInterval(this, ModuleRes(FT_GROUPINTERVAL) )
1003 	,m_aGroupIntervalEd(this, ModuleRes(ED_GROUPINTERVALLST) )
1004 	,m_aKeepTogether(this, ModuleRes(FT_KEEPTOGETHER) )
1005 	,m_aKeepTogetherLst(this, ModuleRes(LST_KEEPTOGETHERLST) )
1006 	,m_aFL(this, ModuleRes(FL_SEPARATOR1) )
1007 	,m_aHelpWindow(this, ModuleRes(HELP_FIELD) )
1008 	,m_pFieldExpression( new OFieldExpressionControl(this,ModuleRes(WND_CONTROL)))
1009 	,m_pController(_pController)
1010 	,m_pCurrentGroupListener(NULL)
1011 	,m_xGroups(m_pController->getReportDefinition()->getGroups())
1012 	,m_bReadOnly(_bReadOnly)
1013 {
1014 	DBG_CTOR( rpt_OGroupsSortingDialog,NULL);
1015 
1016 
1017 	Control* pControlsLst[] = { &m_aHeaderLst, &m_aFooterLst, &m_aGroupOnLst, &m_aKeepTogetherLst, &m_aOrderLst, &m_aGroupIntervalEd};
1018 	for (size_t i = 0; i < sizeof(pControlsLst)/sizeof(pControlsLst[0]); ++i)
1019 	{
1020 		pControlsLst[i]->SetGetFocusHdl(LINK(this, OGroupsSortingDialog, OnControlFocusGot));
1021 		pControlsLst[i]->SetLoseFocusHdl(LINK(this, OGroupsSortingDialog, OnControlFocusLost));
1022         pControlsLst[i]->Show(sal_True);
1023 	} // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1024 
1025 	for (size_t i = 0; i < (sizeof(pControlsLst)/sizeof(pControlsLst[0]))-1; ++i)
1026 		static_cast<ListBox*>(pControlsLst[i])->SetSelectHdl(LINK(this,OGroupsSortingDialog,LBChangeHdl));
1027 
1028 	Control* pControls[]	= { &m_aHeader,	&m_aFooter,	&m_aGroupOn, &m_aGroupInterval,	&m_aKeepTogether, &m_aOrder
1029 								, &m_aMove,&m_aFL2};
1030 	sal_Int32 nMaxTextWidth = 0;
1031 	MnemonicGenerator aMnemonicGenerator;
1032 	for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1033 		aMnemonicGenerator.RegisterMnemonic( pControls[i]->GetText() );
1034 
1035 	for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1036 	{
1037         pControls[i]->Show(sal_True);
1038 		String sText = pControls[i]->GetText();
1039 		if ( aMnemonicGenerator.CreateMnemonic(sText) )
1040 			pControls[i]->SetText(sText);
1041         sal_Int32 nTextWidth = GetTextWidth(sText);
1042 		nMaxTextWidth = ::std::max<sal_Int32>(nTextWidth,nMaxTextWidth);
1043 	}
1044 
1045     Size aSize(UNRELATED_CONTROLS, PAGE_HEIGHT);
1046 	Size aSpace = LogicToPixel( aSize, MAP_APPFONT );
1047 	Size aOutSize(nMaxTextWidth + m_aHeader.GetSizePixel().Width() + 3*aSpace.Width(),aSpace.Height());
1048 	SetMinOutputSizePixel(aOutSize);
1049 	SetOutputSizePixel(aOutSize);
1050 //	Resize();
1051 
1052     m_pReportListener = new OPropertyChangeMultiplexer(this,m_pController->getReportDefinition().get());
1053 	m_pReportListener->addProperty(PROPERTY_COMMAND);
1054 	m_pReportListener->addProperty(PROPERTY_COMMANDTYPE);
1055 
1056 	m_pFieldExpression->lateInit();
1057     fillColumns();
1058 	m_pFieldExpression->Show();
1059 
1060 	//m_aHelpWindow.SetReadOnly();
1061 	m_aHelpWindow.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
1062 	//BTN m_aPB_Up.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1063 	//BTN m_aPB_Down.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1064 	//BTN m_aPB_Delete.SetClickHdl(LINK(this,OGroupsSortingDialog,ClickHdl));
1065 
1066 	m_pFieldExpression->SetZOrder(&m_aFL2, WINDOW_ZORDER_BEHIND);
1067 
1068 	m_aMove.SetZOrder(m_pFieldExpression, WINDOW_ZORDER_BEHIND);
1069 	//BTN m_aPB_Up.SetZOrder(&m_aMove, WINDOW_ZORDER_BEHIND);
1070 	//BTN m_aPB_Down.SetZOrder(&m_aPB_Up, WINDOW_ZORDER_BEHIND);
1071 	// set Hi contrast bitmaps
1072 	//BTN m_aPB_Up.SetModeImage(		ModuleRes(IMG_UP_H),BMP_COLOR_HIGHCONTRAST);
1073 	//BTN m_aPB_Down.SetModeImage(	ModuleRes(IMG_DOWN_H),BMP_COLOR_HIGHCONTRAST);
1074     m_aToolBox.SetStyle(m_aToolBox.GetStyle()|WB_LINESPACING);
1075     m_aToolBox.SetSelectHdl(LINK(this, OGroupsSortingDialog, OnFormatAction));
1076     m_aToolBox.SetImageListProvider(this);
1077     setToolBox(&m_aToolBox);
1078 
1079 	checkButtons(0);
1080 	Resize();
1081 
1082 	FreeResource();
1083 }
1084 
1085 //------------------------------------------------------------------------
1086 OGroupsSortingDialog::~OGroupsSortingDialog()
1087 {
1088 	DBG_DTOR( rpt_OGroupsSortingDialog,NULL);
1089 	delete m_pFieldExpression;
1090 	m_xColumns.clear();
1091     m_pReportListener->dispose();
1092 	if ( m_pCurrentGroupListener.is() )
1093 		m_pCurrentGroupListener->dispose();
1094 }
1095 // -----------------------------------------------------------------------------
1096 sal_Bool OGroupsSortingDialog::isReadOnly( ) const
1097 {
1098 	return m_bReadOnly;
1099 }
1100 //------------------------------------------------------------------------------
1101 void OGroupsSortingDialog::UpdateData( )
1102 {
1103 	m_pFieldExpression->Invalidate();
1104     long nCurRow = m_pFieldExpression->GetCurRow();
1105     m_pFieldExpression->DeactivateCell();
1106 	m_pFieldExpression->ActivateCell(nCurRow, m_pFieldExpression->GetCurColumnId());
1107 	DisplayData(nCurRow);
1108 }
1109 //------------------------------------------------------------------------------
1110 void OGroupsSortingDialog::DisplayData( sal_Int32 _nRow )
1111 {
1112 	DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1113     sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1114 	sal_Bool bEmpty = nGroupPos == NO_GROUP;
1115 	m_aHeaderLst.Enable(!bEmpty);
1116 	m_aFooterLst.Enable(!bEmpty);
1117 	m_aGroupOnLst.Enable(!bEmpty);
1118 	m_aGroupIntervalEd.Enable(!bEmpty);
1119 	m_aKeepTogetherLst.Enable(!bEmpty);
1120 	m_aOrderLst.Enable(!bEmpty);
1121 
1122 	m_aFL3.Enable(!bEmpty);
1123 	m_aHeader.Enable(!bEmpty);
1124 	m_aFooter.Enable(!bEmpty);
1125 	m_aGroupOn.Enable(!bEmpty);
1126 	m_aGroupInterval.Enable(!bEmpty);
1127 	m_aKeepTogether.Enable(!bEmpty);
1128 	m_aOrder.Enable(!bEmpty);
1129 
1130 	checkButtons(_nRow);
1131 
1132 	if ( m_pCurrentGroupListener.is() )
1133 		m_pCurrentGroupListener->dispose();
1134 	m_pCurrentGroupListener = NULL;
1135 	if ( !bEmpty && nGroupPos != NO_GROUP )
1136 	{
1137 		uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1138 
1139 		m_pCurrentGroupListener = new OPropertyChangeMultiplexer(this,xGroup.get());
1140 		m_pCurrentGroupListener->addProperty(PROPERTY_HEADERON);
1141 		m_pCurrentGroupListener->addProperty(PROPERTY_FOOTERON);
1142 
1143 		displayGroup(xGroup);
1144 	}
1145 }
1146 //------------------------------------------------------------------------------
1147 void OGroupsSortingDialog::SaveData( sal_Int32 _nRow)
1148 {
1149 	DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1150     sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1151 	if ( nGroupPos == NO_GROUP )
1152 		return;
1153 
1154 	uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1155     if ( m_aHeaderLst.GetSavedValue() != m_aHeaderLst.GetSelectEntryPos() )
1156 	    xGroup->setHeaderOn( m_aHeaderLst.GetSelectEntryPos() == 0 );
1157     if ( m_aFooterLst.GetSavedValue() != m_aFooterLst.GetSelectEntryPos() )
1158 	    xGroup->setFooterOn( m_aFooterLst.GetSelectEntryPos() == 0 );
1159     if ( m_aKeepTogetherLst.GetSavedValue() != m_aKeepTogetherLst.GetSelectEntryPos() )
1160 	    xGroup->setKeepTogether( m_aKeepTogetherLst.GetSelectEntryPos() );
1161     if ( m_aGroupOnLst.GetSavedValue() != m_aGroupOnLst.GetSelectEntryPos() )
1162     {
1163 	    sal_Int16 nGroupOn = static_cast<sal_Int16>(reinterpret_cast<sal_IntPtr>(m_aGroupOnLst.GetEntryData(m_aGroupOnLst.GetSelectEntryPos())));
1164         xGroup->setGroupOn( nGroupOn );
1165     }
1166     if ( m_aGroupIntervalEd.GetSavedValue().ToInt32() != m_aGroupIntervalEd.GetValue() )
1167     {
1168 	    xGroup->setGroupInterval( static_cast<sal_Int32>(m_aGroupIntervalEd.GetValue()) );
1169         m_aGroupIntervalEd.SaveValue();
1170     }
1171     if ( m_aOrderLst.GetSavedValue() != m_aOrderLst.GetSelectEntryPos() )
1172 	    xGroup->setSortAscending( m_aOrderLst.GetSelectEntryPos() == 0 );
1173 
1174     ListBox* pControls[] = { &m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aKeepTogetherLst,&m_aOrderLst};
1175     for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1176         pControls[i]->SaveValue();
1177 }
1178 
1179 // -----------------------------------------------------------------------------
1180 sal_Int32 OGroupsSortingDialog::getColumnDataType(const ::rtl::OUString& _sColumnName)
1181 {
1182 	sal_Int32 nDataType = sdbc::DataType::VARCHAR;
1183     try
1184     {
1185         if ( !m_xColumns.is() )
1186             fillColumns();
1187 	    if ( m_xColumns.is() && m_xColumns->hasByName(_sColumnName) )
1188 	    {
1189 		    uno::Reference< beans::XPropertySet> xColumn(m_xColumns->getByName(_sColumnName),uno::UNO_QUERY);
1190 		    if ( xColumn.is() )
1191 			    xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
1192 	    }
1193     }
1194     catch(uno::Exception&)
1195     {
1196         OSL_ENSURE(0,"Eception caught while getting the type of a column");
1197     }
1198 
1199 	return nDataType;
1200 }
1201 //------------------------------------------------------------------------------
1202 IMPL_LINK(OGroupsSortingDialog, OnControlFocusGot, Control*, pControl )
1203 {
1204 	if ( m_pFieldExpression && m_pFieldExpression->getExpressionControl() )
1205 	{
1206 		Control* pControls[] = { m_pFieldExpression->getExpressionControl(),&m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aGroupIntervalEd,&m_aKeepTogetherLst,&m_aOrderLst};
1207 		for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1208 		{
1209 			if ( pControl == pControls[i] )
1210 			{
1211                 ListBox* pListBox = dynamic_cast< ListBox* >( pControl );
1212                 if ( pListBox )
1213                     pListBox->SaveValue();
1214                 NumericField* pNumericField = dynamic_cast< NumericField* >( pControl );
1215                 if ( pNumericField )
1216                     pNumericField->SaveValue();
1217 				showHelpText(static_cast<sal_uInt16>(i+STR_RPT_HELP_FIELD));
1218 				break;
1219 			}
1220 		}
1221 	}
1222 	return 0L;
1223 }
1224 //------------------------------------------------------------------------------
1225 IMPL_LINK(OGroupsSortingDialog, OnControlFocusLost, Control*, pControl )
1226 {
1227     if ( m_pFieldExpression && pControl == &m_aGroupIntervalEd )
1228 	{
1229 		if ( m_aGroupIntervalEd.IsModified() )
1230             SaveData(m_pFieldExpression->GetCurRow());
1231     }
1232 	return 0L;
1233 }
1234 // -----------------------------------------------------------------------------
1235 IMPL_LINK( OGroupsSortingDialog, OnFormatAction, ToolBox*, /*NOTINTERESTEDIN*/ )
1236 // IMPL_LINK( OGroupsSortingDialog, ClickHdl, ImageButton*, _pButton )
1237 {
1238 	DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1239 
1240     sal_uInt16 nCommand = m_aToolBox.GetCurItemId();
1241 
1242 	if ( m_pFieldExpression )
1243 	{
1244 		long nIndex = m_pFieldExpression->GetCurrRow();
1245         sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(nIndex);
1246 		uno::Sequence<uno::Any> aClipboardList;
1247 		if ( nIndex >= 0 && nGroupPos != NO_GROUP )
1248 		{
1249 			aClipboardList.realloc(1);
1250 			aClipboardList[0] = m_xGroups->getByIndex(nGroupPos);
1251 		}
1252 		//BTN if ( _pButton == &m_aPB_Up )
1253         if ( nCommand == SID_RPT_GROUPSORT_MOVE_UP )
1254         {
1255 			--nIndex;
1256         }
1257         //BTN if ( _pButton == &m_aPB_Down )
1258         if ( nCommand == SID_RPT_GROUPSORT_MOVE_DOWN )
1259         {
1260 			++nIndex;
1261         }
1262         //BTN if ( _pButton == &m_aPB_Delete )
1263         if ( nCommand == SID_RPT_GROUPSORT_DELETE )
1264         {
1265             // m_pFieldExpression->DeleteCurrentRow();
1266             Application::PostUserEvent( LINK(m_pFieldExpression, OFieldExpressionControl, DelayedDelete) );
1267             // UpdateData( );
1268         }
1269         else
1270         {
1271 		    if ( nIndex >= 0 && aClipboardList.getLength() )
1272 		    {
1273 			    m_pFieldExpression->SetNoSelection();
1274 			    m_pFieldExpression->moveGroups(aClipboardList,nIndex,sal_False);
1275 			    m_pFieldExpression->DeactivateCell();
1276                 m_pFieldExpression->GoToRow(nIndex);
1277 			    //long nCurRow = m_pFieldExpression->GetCurRow();
1278 			    m_pFieldExpression->ActivateCell(nIndex, m_pFieldExpression->GetCurColumnId());
1279 			    DisplayData(nIndex);
1280 		    }
1281         }
1282 	}
1283 	return 1L;
1284 }
1285 // -----------------------------------------------------------------------------
1286 IMPL_LINK( OGroupsSortingDialog, LBChangeHdl, ListBox*, pListBox )
1287 {
1288 	DBG_CHKTHIS( rpt_OGroupsSortingDialog,NULL);
1289     if ( pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
1290     {
1291 	    sal_Int32 nRow = m_pFieldExpression->GetCurRow();
1292         sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(nRow);
1293         if ( pListBox != &m_aHeaderLst && pListBox != &m_aFooterLst)
1294         {
1295             if ( pListBox && pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
1296                 SaveData(nRow);
1297             if ( pListBox == &m_aGroupOnLst )
1298                 m_aGroupIntervalEd.Enable( pListBox->GetSelectEntryPos() != 0 );
1299         }
1300 	    else if ( nGroupPos != NO_GROUP )
1301 	    {
1302 		    uno::Reference< report::XGroup> xGroup = getGroup(nGroupPos);
1303 		    uno::Sequence< beans::PropertyValue > aArgs(2);
1304 		    aArgs[1].Name = PROPERTY_GROUP;
1305 		    aArgs[1].Value <<= xGroup;
1306 
1307 		    if ( &m_aHeaderLst  == pListBox )
1308 			    aArgs[0].Name = PROPERTY_HEADERON;
1309 		    else
1310 			    aArgs[0].Name = PROPERTY_FOOTERON;
1311 
1312 		    aArgs[0].Value <<= pListBox->GetSelectEntryPos() == 0;
1313 		    m_pController->executeChecked(&m_aHeaderLst  == pListBox ? SID_GROUPHEADER : SID_GROUPFOOTER,aArgs);
1314 		    if ( m_pFieldExpression )
1315 			    m_pFieldExpression->InvalidateHandleColumn();
1316 	    }
1317     }
1318 	return 1L;
1319 }
1320 // -----------------------------------------------------------------------------
1321 void OGroupsSortingDialog::showHelpText(sal_uInt16 _nResId)
1322 {
1323 	m_aHelpWindow.SetText(String(ModuleRes(_nResId)));
1324 }
1325 // -----------------------------------------------------------------------------
1326 void OGroupsSortingDialog::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
1327 {
1328 	uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
1329 	if ( xGroup.is() )
1330 		displayGroup(xGroup);
1331     else
1332         fillColumns();
1333 }
1334 // -----------------------------------------------------------------------------
1335 void OGroupsSortingDialog::fillColumns()
1336 {
1337     m_xColumns = m_pController->getColumns();
1338     m_pFieldExpression->fillColumns(m_xColumns);
1339 }
1340 // -----------------------------------------------------------------------------
1341 void OGroupsSortingDialog::displayGroup(const uno::Reference<report::XGroup>& _xGroup)
1342 {
1343 	m_aHeaderLst.SelectEntryPos(_xGroup->getHeaderOn() ? 0 : 1 );
1344 	m_aFooterLst.SelectEntryPos(_xGroup->getFooterOn() ? 0 : 1 );
1345 	sal_Int32 nDataType = getColumnDataType(_xGroup->getExpression());
1346 
1347 	// first clear whole group on list
1348 	while(m_aGroupOnLst.GetEntryCount() > 1 )
1349 	{
1350 		m_aGroupOnLst.RemoveEntry(1);
1351 	}
1352 
1353 	switch(nDataType)
1354 	{
1355 		case sdbc::DataType::LONGVARCHAR:
1356 		case sdbc::DataType::VARCHAR:
1357 		case sdbc::DataType::CHAR:
1358 			m_aGroupOnLst.InsertEntry(String(ModuleRes(STR_RPT_PREFIXCHARS)));
1359 			m_aGroupOnLst.SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::PREFIX_CHARACTERS));
1360 			break;
1361 		case sdbc::DataType::DATE:
1362 		case sdbc::DataType::TIME:
1363 		case sdbc::DataType::TIMESTAMP:
1364 			{
1365 				sal_uInt16 nIds[] = { STR_RPT_YEAR, STR_RPT_QUARTER,STR_RPT_MONTH,STR_RPT_WEEK,STR_RPT_DAY,STR_RPT_HOUR,STR_RPT_MINUTE };
1366 				for (sal_uInt16 i = 0; i < sizeof(nIds)/sizeof(nIds[0]); ++i)
1367 				{
1368 					m_aGroupOnLst.InsertEntry(String(ModuleRes(nIds[i])));
1369 					m_aGroupOnLst.SetEntryData(i+1,reinterpret_cast<void*>(i+2));
1370 				}
1371 			}
1372 			break;
1373 		default:
1374 			m_aGroupOnLst.InsertEntry(String(ModuleRes(STR_RPT_INTERVAL)));
1375 			m_aGroupOnLst.SetEntryData(1,reinterpret_cast<void*>(report::GroupOn::INTERVAL));
1376 			break;
1377 	} // switch(nDataType)
1378 	sal_uInt16 nPos = 0;
1379 	switch(_xGroup->getGroupOn())
1380 	{
1381 		case report::GroupOn::DEFAULT:
1382 			nPos = 0;
1383 			break;
1384 		case report::GroupOn::PREFIX_CHARACTERS:
1385 			nPos = 1;
1386 			break;
1387 		case report::GroupOn::YEAR:
1388 			nPos = 1;
1389 			break;
1390 		case report::GroupOn::QUARTAL:
1391 			nPos = 2;
1392 			break;
1393 		case report::GroupOn::MONTH:
1394 			nPos = 3;
1395 			break;
1396 		case report::GroupOn::WEEK:
1397 			nPos = 4;
1398 			break;
1399 		case report::GroupOn::DAY:
1400 			nPos = 5;
1401 			break;
1402 		case report::GroupOn::HOUR:
1403 			nPos = 6;
1404 			break;
1405 		case report::GroupOn::MINUTE:
1406 			nPos = 7;
1407 			break;
1408 		case report::GroupOn::INTERVAL:
1409 			nPos = 1;
1410 			break;
1411 		default:
1412 			nPos = 0;
1413 	}
1414 	m_aGroupOnLst.SelectEntryPos(nPos);
1415 	m_aGroupIntervalEd.SetText(String::CreateFromInt32(_xGroup->getGroupInterval()));
1416     m_aGroupIntervalEd.SaveValue();
1417     m_aGroupIntervalEd.Enable( nPos != 0 );
1418 	m_aKeepTogetherLst.SelectEntryPos(_xGroup->getKeepTogether());
1419 	m_aOrderLst.SelectEntryPos(_xGroup->getSortAscending() ? 0 : 1);
1420 
1421     ListBox* pControls[] = { &m_aHeaderLst,&m_aFooterLst,&m_aGroupOnLst,&m_aKeepTogetherLst,&m_aOrderLst};
1422     for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1423         pControls[i]->SaveValue();
1424 
1425     ListBox* pControlsLst2[] = { &m_aHeaderLst,	&m_aFooterLst,	&m_aGroupOnLst,	&m_aKeepTogetherLst,&m_aOrderLst};
1426 	sal_Bool bReadOnly = !m_pController->isEditable();
1427 	for (size_t i = 0; i < sizeof(pControlsLst2)/sizeof(pControlsLst2[0]); ++i)
1428 		pControlsLst2[i]->SetReadOnly(bReadOnly);
1429     m_aGroupIntervalEd.SetReadOnly(bReadOnly);
1430 }
1431 //------------------------------------------------------------------------------
1432 void OGroupsSortingDialog::Resize()
1433 {
1434 	Window::Resize();
1435 	Size aTotalOutputSize = GetOutputSizePixel();
1436 	Size aSpace = LogicToPixel( Size( UNRELATED_CONTROLS, UNRELATED_CONTROLS ), MAP_APPFONT );
1437 	m_pFieldExpression->SetSizePixel(Size(aTotalOutputSize.Width() - 2*aSpace.Width(),m_pFieldExpression->GetSizePixel().Height()));
1438 
1439 	Control* pControlsLst[] = { &m_aHeaderLst,	&m_aFooterLst,	&m_aGroupOnLst,	&m_aGroupIntervalEd,&m_aKeepTogetherLst,&m_aOrderLst};
1440 	Control* pControls[]	= { &m_aHeader,		&m_aFooter,		&m_aGroupOn,	&m_aGroupInterval,	&m_aKeepTogether,	&m_aOrder};
1441 	sal_Int32 nMaxTextWidth = 0;
1442 	for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1443 	{
1444 		nMaxTextWidth = ::std::max<sal_Int32>(static_cast<sal_Int32>(GetTextWidth(pControls[i]->GetText())),nMaxTextWidth);
1445 	} // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1446 
1447 	// aTotalOutputSize.Width() - m_aHeaderLst.GetSizePixel().Width() - 3*aSpace.Width()
1448 	for (size_t i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1449 	{
1450 		pControls[i]->SetSizePixel(Size(nMaxTextWidth,pControls[i]->GetSizePixel().Height()));
1451 		Point aPos = pControls[i]->GetPosPixel();
1452 		aPos.X() += nMaxTextWidth + aSpace.Width();
1453 		aPos.Y() = pControlsLst[i]->GetPosPixel().Y();
1454 
1455 		pControlsLst[i]->SetPosSizePixel(aPos,Size(aTotalOutputSize.Width() - aPos.X() - aSpace.Width(),pControlsLst[i]->GetSizePixel().Height()));
1456 	} // for (int i = 0; i < sizeof(pControls)/sizeof(pControls[0]); ++i)
1457 
1458 	m_aFL.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL.GetSizePixel().Height()));
1459 	m_aFL2.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL2.GetSizePixel().Height()));
1460 	m_aFL3.SetSizePixel(Size(aTotalOutputSize.Width() - aSpace.Width(),m_aFL3.GetSizePixel().Height()));
1461 
1462 //BTN 	sal_Int32 nPos = aTotalOutputSize.Width() - aSpace.Width() - m_aPB_Up.GetSizePixel().Width();
1463 //BTN  	m_aPB_Delete.SetPosPixel(Point(nPos,m_aPB_Delete.GetPosPixel().Y()));
1464 //BTN
1465 //BTN  	nPos -= (m_aPB_Up.GetSizePixel().Width() + LogicToPixel( Size( UNRELATED_CONTROLS, 0 ), MAP_APPFONT ).Width());
1466 //BTN  	m_aPB_Down.SetPosPixel(Point(nPos,m_aPB_Down.GetPosPixel().Y()));
1467 //BTN
1468 //BTN  	nPos -= (m_aPB_Up.GetSizePixel().Width() + LogicToPixel( Size( RELATED_CONTROLS, 0 ), MAP_APPFONT ).Width());
1469 //BTN  	m_aPB_Up.SetPosPixel(Point(nPos,m_aPB_Up.GetPosPixel().Y()));
1470 	sal_Int32 nPos = aTotalOutputSize.Width() - aSpace.Width() - m_aToolBox.GetSizePixel().Width();
1471     m_aToolBox.SetPosPixel(Point(nPos,m_aToolBox.GetPosPixel().Y()));
1472 
1473 	Point aHelpPos = m_aHelpWindow.GetPosPixel();
1474 	m_aHelpWindow.SetSizePixel(Size(aTotalOutputSize.Width() - aHelpPos.X(),aTotalOutputSize.Height() - aHelpPos.Y()));
1475 }
1476 //------------------------------------------------------------------------------
1477 void OGroupsSortingDialog::checkButtons(sal_Int32 _nRow)
1478 {
1479 	sal_Int32 nGroupCount = m_xGroups->getCount();
1480     sal_Int32 nRowCount = m_pFieldExpression->GetRowCount();
1481     sal_Bool bEnabled = nGroupCount > 1;
1482 
1483     if (bEnabled && _nRow > 0 /* && _nRow < nGroupCount */ )
1484     {
1485         m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_UP, sal_True);
1486     }
1487     else
1488     {
1489         m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_UP, sal_False);
1490     }
1491     if (bEnabled && _nRow < (nRowCount - 1) /* && _nRow < (nGroupCount - 1) */ )
1492     {
1493         m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_DOWN, sal_True);
1494     }
1495     else
1496     {
1497         m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_DOWN, sal_False);
1498     }
1499     //BTN m_aPB_Up.Enable(bEnable && _nRow > 0 );
1500 	//BTN m_aPB_Down.Enable(bEnable && _nRow < (m_pFieldExpression->GetRowCount()-1) );
1501     // m_aToolBox.EnableItem(SID_RPT_GROUPSORT_MOVE_DOWN, bEnable && _nRow < (-1) );
1502 
1503     sal_Int32 nGroupPos = m_pFieldExpression->getGroupPosition(_nRow);
1504 	if ( nGroupPos != NO_GROUP )
1505     {
1506         sal_Bool bEnableDelete = nGroupCount > 0;
1507 	    //BTN m_aPB_Delete.Enable(bEnableDelete );
1508         m_aToolBox.EnableItem(SID_RPT_GROUPSORT_DELETE, bEnableDelete);
1509     }
1510     else
1511     {
1512 	    //BTN m_aPB_Delete.Enable( sal_False );
1513         m_aToolBox.EnableItem(SID_RPT_GROUPSORT_DELETE, sal_False);
1514     }
1515 }
1516 
1517 ImageList OGroupsSortingDialog::getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
1518 {
1519     sal_Int16 nN = IMG_CONDFORMAT_DLG_SC;
1520     sal_Int16 nH = IMG_CONDFORMAT_DLG_SCH;
1521     if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
1522     {
1523         nN = IMG_CONDFORMAT_DLG_LC;
1524         nH = IMG_CONDFORMAT_DLG_LCH;
1525     }
1526     return ImageList(ModuleRes( _bHiContast ? nH : nN ));
1527 }
1528 
1529 //------------------------------------------------------------------
1530 void OGroupsSortingDialog::resizeControls(const Size& _rDiff)
1531 {
1532     // we use large images so we must change them
1533     if ( _rDiff.Width() || _rDiff.Height() )
1534     {
1535         Point aPos = LogicToPixel( Point( 2*RELATED_CONTROLS , 0), MAP_APPFONT );
1536         Invalidate();
1537     }
1538 }
1539 
1540 //------------------------------------------------------------------
1541 // load the images
1542 ImageList OGroupsSortingDialog::getImageList(vcl::ImageListType _eType) SAL_THROW (( com::sun::star::lang::IllegalArgumentException ))
1543 {
1544     if (_eType == vcl::HIGHCONTRAST_NO)
1545     {
1546         return ImageList(ModuleRes(IMGLST_GROUPSORT_DLG_SC));
1547     }
1548     else if (_eType == vcl::HIGHCONTRAST_YES)
1549     {
1550         return ImageList(ModuleRes(IMGLST_GROUPSORT_DLG_SCH));
1551     }
1552     else
1553     {
1554         throw com::sun::star::lang::IllegalArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("High contrast parameter is wrong.")), NULL, 0);
1555     }
1556 }
1557 
1558 
1559 
1560 // =============================================================================
1561 } // rptui
1562 // =============================================================================
1563