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