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