Update ooo320-m1
[ooovba.git] / reportdesign / source / ui / dlg / Condition.cxx
blobf5caf057999d629e26c20193ce8d2f389a9986ec
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Condition.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
32 #include "Condition.hxx"
33 #include "UITools.hxx"
34 #include "CondFormat.hxx"
35 #include "CondFormat.hrc"
36 #include "RptResId.hrc"
37 #include "ReportController.hxx"
38 #include "ModuleHelper.hxx"
39 #include "ColorChanger.hxx"
40 #include "RptResId.hrc"
41 #include "helpids.hrc"
42 #include "reportformula.hxx"
43 #include <com/sun/star/util/URL.hpp>
44 #include <com/sun/star/beans/PropertyValue.hpp>
45 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
46 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
47 #include <com/sun/star/ui/XImageManager.hpp>
48 #include <com/sun/star/awt/FontDescriptor.hpp>
49 #include <com/sun/star/ui/ImageType.hpp>
51 #define ITEMID_COLOR
52 #define ITEMID_BRUSH
53 #include <svx/tbcontrl.hxx>
54 #include <svx/svxids.hrc>
55 #include <svx/xtable.hxx>
56 #include <svx/tbxcolorupdate.hxx>
57 #include <toolkit/helper/vclunohelper.hxx>
58 #include <svtools/imgdef.hxx>
59 #include <svtools/pathoptions.hxx>
60 #include <vcl/svapp.hxx>
61 #include <vcl/bmpacc.hxx>
62 #include <tools/diagnose_ex.h>
63 #include <rtl/ustrbuf.hxx>
65 namespace rptui
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::beans;
71 ConditionField::ConditionField( Condition* _pParent, const ResId& _rResId ) : Edit(_pParent,_rResId)
72 ,m_pParent(_pParent)
73 ,m_aFormula(this)
75 m_pSubEdit = new Edit(this,0);
76 SetSubEdit(m_pSubEdit);
77 m_pSubEdit->EnableRTL( FALSE );
78 m_pSubEdit->SetPosPixel( Point() );
80 m_aFormula.SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("...")));
81 m_aFormula.SetClickHdl( LINK( this, ConditionField, OnFormula ) );
82 m_aFormula.Show();
83 m_pSubEdit->Show();
84 Resize();
86 // -----------------------------------------------------------------------------
87 ConditionField::~ConditionField()
89 SetSubEdit(NULL);
90 delete m_pSubEdit;
92 // -----------------------------------------------------------------------------
93 void ConditionField::Resize()
95 Edit::Resize();
96 const Size aSize = GetOutputSizePixel();
97 const Size aButtonSize( LogicToPixel( Size( 12, 0 ), MAP_APPFONT ).Width(),aSize.Height());
98 const Point aButtonPos(aSize.Width() - aButtonSize.Width(), 0);
99 m_aFormula.SetPosSizePixel(aButtonPos,aButtonSize);
100 m_pSubEdit->SetPosSizePixel(Point(0,0),Size(aButtonPos.X() ,aSize.Height()));
102 // -----------------------------------------------------------------------------
103 IMPL_LINK( ConditionField, OnFormula, Button*, /*_pClickedButton*/ )
105 ::rtl::OUString sFormula(m_pSubEdit->GetText());
106 const sal_Int32 nLen = sFormula.getLength();
107 if ( nLen )
109 ReportFormula aFormula( sFormula );
110 sFormula = aFormula.getCompleteFormula();
111 } // if ( nLen )
112 uno::Reference< awt::XWindow> xInspectorWindow = VCLUnoHelper::GetInterface(this);
113 uno::Reference< beans::XPropertySet> xProp(m_pParent->getController().getRowSet(),uno::UNO_QUERY);
114 if ( rptui::openDialogFormula_nothrow( sFormula, m_pParent->getController().getContext(),xInspectorWindow,xProp ) )
116 ReportFormula aFormula( sFormula );
117 m_pSubEdit->SetText(aFormula.getUndecoratedContent());
119 return 0L;
121 //========================================================================
122 // class SvxColorWindow_Impl --------------------------------------------------
123 //========================================================================
124 #ifndef WB_NO_DIRECTSELECT
125 #define WB_NO_DIRECTSELECT ((WinBits)0x04000000)
126 #endif
128 #define PALETTE_X 10
129 #define PALETTE_Y 10
130 #define PALETTE_SIZE (PALETTE_X * PALETTE_Y)
131 class OColorPopup : public FloatingWindow
133 DECL_LINK( SelectHdl, void * );
134 Condition* m_pCondition;
135 USHORT m_nSlotId;
136 public:
137 OColorPopup(Window* _pParent,Condition* _pCondition);
138 ValueSet m_aColorSet;
140 virtual void KeyInput( const KeyEvent& rKEvt );
141 virtual void Resize();
143 void StartSelection();
144 void SetSlotId(USHORT _nSlotId);
146 // -----------------------------------------------------------------------------
147 OColorPopup::OColorPopup(Window* _pParent,Condition* _pCondition)
148 :FloatingWindow(_pParent, WinBits( WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK|WB_DIALOGCONTROL ))
149 ,m_pCondition(_pCondition)
150 ,m_nSlotId(0)
151 ,m_aColorSet( this, WinBits( WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) )
153 m_aColorSet.SetHelpId( HID_RPT_POPUP_COLOR_CTRL );
154 SetHelpId( HID_RPT_POPUP_COLOR );
155 const Size aSize12( 13, 13 );
156 ::std::auto_ptr<XColorTable> pColorTable(new XColorTable( SvtPathOptions().GetPalettePath() ));
157 short i = 0;
158 long nCount = pColorTable->Count();
159 XColorEntry* pEntry = NULL;
160 Color aColWhite( COL_WHITE );
161 String aStrWhite( ModuleRes(STR_COLOR_WHITE) );
163 if ( nCount > PALETTE_SIZE )
164 // Show scrollbar if more than PALLETTE_SIZE colors are available
165 m_aColorSet.SetStyle( m_aColorSet.GetStyle() | WB_VSCROLL );
167 for ( i = 0; i < nCount; i++ )
169 pEntry = pColorTable->GetColor(i);
170 m_aColorSet.InsertItem( i+1, pEntry->GetColor(), pEntry->GetName() );
173 while ( i < PALETTE_SIZE )
175 // fill empty elements if less then PALLETTE_SIZE colors are available
176 m_aColorSet.InsertItem( i+1, aColWhite, aStrWhite );
177 i++;
180 m_aColorSet.SetSelectHdl( LINK( this, OColorPopup, SelectHdl ) );
181 m_aColorSet.SetColCount( PALETTE_X );
182 m_aColorSet.SetLineCount( PALETTE_Y );
183 Size aSize = m_aColorSet.CalcWindowSizePixel( aSize12 );
184 aSize.Width() += 4;
185 aSize.Height() += 4;
186 SetOutputSizePixel( aSize );
187 m_aColorSet.Show();
189 // -----------------------------------------------------------------------------
190 void OColorPopup::KeyInput( const KeyEvent& rKEvt )
192 m_aColorSet.KeyInput(rKEvt);
195 // -----------------------------------------------------------------------------
196 void OColorPopup::Resize()
198 Size aSize = GetOutputSizePixel();
199 aSize.Width() -= 4;
200 aSize.Height() -= 4;
201 m_aColorSet.SetPosSizePixel( Point(2,2), aSize );
204 // -----------------------------------------------------------------------------
205 void OColorPopup::StartSelection()
207 m_aColorSet.StartSelection();
209 // -----------------------------------------------------------------------------
210 void OColorPopup::SetSlotId(USHORT _nSlotId)
212 m_nSlotId = _nSlotId;
213 if ( SID_ATTR_CHAR_COLOR_BACKGROUND == _nSlotId || SID_BACKGROUND_COLOR == _nSlotId )
215 m_aColorSet.SetStyle( m_aColorSet.GetStyle() | WB_NONEFIELD );
216 m_aColorSet.SetText( String(ModuleRes( STR_TRANSPARENT )) );
217 } // if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId )
219 // -----------------------------------------------------------------------------
220 IMPL_LINK( OColorPopup, SelectHdl, void *, EMPTYARG )
222 USHORT nItemId = m_aColorSet.GetSelectItemId();
223 Color aColor( nItemId == 0 ? Color( COL_TRANSPARENT ) : m_aColorSet.GetItemColor( nItemId ) );
225 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() calls.
226 This instance may be deleted in the meantime (i.e. when a dialog is opened
227 while in Dispatch()), accessing members will crash in this case. */
228 m_aColorSet.SetNoSelection();
230 if ( IsInPopupMode() )
231 EndPopupMode();
233 m_pCondition->ApplyCommand( m_nSlotId, aColor );
234 return 0;
237 // =============================================================================
238 // = Condition
239 // =============================================================================
240 // -----------------------------------------------------------------------------
241 Condition::Condition( Window* _pParent, IConditionalFormatAction& _rAction, ::rptui::OReportController& _rController )
242 :Control(_pParent, ModuleRes(WIN_CONDITION))
243 ,m_rController( _rController )
244 ,m_rAction( _rAction )
245 ,m_aHeader(this, ModuleRes(FL_CONDITION_HEADER))
246 ,m_aConditionType(this, ModuleRes(LB_COND_TYPE))
247 ,m_aOperationList( this, ModuleRes(LB_OP))
248 ,m_aCondLHS(this, ModuleRes(ED_CONDITION_LHS))
249 ,m_aOperandGlue(this, ModuleRes(FT_AND))
250 ,m_aCondRHS(this, ModuleRes(ED_CONDITION_RHS))
251 ,m_aActions(this, ModuleRes(TB_FORMAT))
252 ,m_aPreview(this, ModuleRes(CRTL_FORMAT_PREVIEW))
253 ,m_aMoveUp( this, ModuleRes( BTN_MOVE_UP ) )
254 ,m_aMoveDown( this, ModuleRes( BTN_MOVE_DOWN ) )
255 ,m_aAddCondition( this, ModuleRes( BTN_ADD_CONDITION ) )
256 ,m_aRemoveCondition( this, ModuleRes( BTN_REMOVE_CONDITION ) )
257 ,m_pColorFloat(NULL)
258 ,m_pBtnUpdaterFontColor(NULL)
259 ,m_pBtnUpdaterBackgroundColor(NULL)
260 ,m_nCondIndex( 0 )
261 ,m_nLastKnownWindowWidth( -1 )
262 ,m_bInDestruction( false )
264 m_aMoveUp.SetModeImage( ModuleRes( IMG_MOVE_UP_HC ), BMP_COLOR_HIGHCONTRAST );
265 m_aMoveDown.SetModeImage( ModuleRes( IMG_MOVE_DOWN_HC ), BMP_COLOR_HIGHCONTRAST );
267 FreeResource();
268 m_aActions.SetStyle(m_aActions.GetStyle()|WB_LINESPACING);
269 m_aCondLHS.GrabFocus();
271 m_aConditionType.SetSelectHdl( LINK( this, Condition, OnTypeSelected ) );
273 m_aOperationList.SetDropDownLineCount( 10 );
274 m_aOperationList.SetSelectHdl( LINK( this, Condition, OnOperationSelected ) );
276 m_aActions.SetSelectHdl(LINK(this, Condition, OnFormatAction));
277 m_aActions.SetDropdownClickHdl( LINK( this, Condition, DropdownClick ) );
278 setToolBox(&m_aActions);
280 m_aMoveUp.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
281 m_aMoveDown.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
282 m_aAddCondition.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
283 m_aRemoveCondition.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
285 m_aMoveUp.SetStyle( m_aMoveUp.GetStyle() | WB_NOPOINTERFOCUS );
286 m_aMoveDown.SetStyle( m_aMoveDown.GetStyle() | WB_NOPOINTERFOCUS );
287 m_aAddCondition.SetStyle( m_aMoveUp.GetStyle() | WB_NOPOINTERFOCUS | WB_CENTER | WB_VCENTER );
288 m_aRemoveCondition.SetStyle( m_aMoveDown.GetStyle() | WB_NOPOINTERFOCUS | WB_CENTER | WB_VCENTER );
290 Font aFont( m_aAddCondition.GetFont() );
291 aFont.SetWeight( WEIGHT_BOLD );
292 m_aAddCondition.SetFont( aFont );
293 m_aRemoveCondition.SetFont( aFont );
295 m_aOperandGlue.SetStyle( m_aOperandGlue.GetStyle() | WB_VCENTER );
297 m_aConditionType.SelectEntryPos( 0 );
298 m_aOperationList.SelectEntryPos( 0 );
300 // the toolbar got its site automatically, ensure that the preview is positioned
301 // right of it
302 Size aRelatedControls( LogicToPixel( Size( RELATED_CONTROLS, 0 ), MAP_APPFONT ) );
303 Point aToolbarPos( m_aActions.GetPosPixel() );
304 Size aToolbarSize( m_aActions.GetSizePixel() );
305 m_aPreview.SetPosSizePixel( aToolbarPos.X() + aToolbarSize.Width() + 2 * aRelatedControls.Width(),
306 0, 0, 0, WINDOW_POSSIZE_X );
308 // ensure the toolbar is vertically centered, relative to the preview
309 Size aPreviewSize( m_aPreview.GetSizePixel() );
310 m_aActions.SetPosSizePixel( 0, aToolbarPos.Y() + ( aPreviewSize.Height() - aToolbarSize.Height() ) / 2, 0, 0, WINDOW_POSSIZE_Y );
312 m_pBtnUpdaterBackgroundColor = new ::svx::ToolboxButtonColorUpdater(
313 SID_BACKGROUND_COLOR, SID_BACKGROUND_COLOR, &m_aActions );
314 m_pBtnUpdaterFontColor = new ::svx::ToolboxButtonColorUpdater(
315 SID_ATTR_CHAR_COLOR2, SID_ATTR_CHAR_COLOR2, &m_aActions, TBX_UPDATER_MODE_CHAR_COLOR_NEW );
317 Show();
319 impl_layoutAll();
321 ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions );
324 // -----------------------------------------------------------------------------
325 Condition::~Condition()
327 m_bInDestruction = true;
329 delete m_pColorFloat;
330 delete m_pBtnUpdaterFontColor;
331 delete m_pBtnUpdaterBackgroundColor;
333 // -----------------------------------------------------------------------------
334 IMPL_LINK( Condition, DropdownClick, ToolBox*, /*pToolBar*/ )
336 USHORT nId( m_aActions.GetCurItemId() );
337 if ( !m_pColorFloat )
338 m_pColorFloat = new OColorPopup(&m_aActions,this);
340 USHORT nTextId = 0;
341 switch(nId)
343 case SID_ATTR_CHAR_COLOR2:
344 nTextId = STR_CHARCOLOR;
345 break;
346 case SID_BACKGROUND_COLOR:
347 nTextId = STR_CHARBACKGROUND;
348 break;
349 default:
350 break;
351 } // switch(nId)
352 if ( nTextId )
353 m_pColorFloat->SetText(String(ModuleRes(nTextId)));
354 m_pColorFloat->SetSlotId(nId);
355 m_pColorFloat->SetPosPixel(m_aActions.GetItemPopupPosition(nId,m_pColorFloat->GetSizePixel()));
356 m_pColorFloat->StartPopupMode(&m_aActions);
357 m_pColorFloat->StartSelection();
359 return 1;
361 //------------------------------------------------------------------
362 IMPL_LINK( Condition, OnFormatAction, ToolBox*, /*NOTINTERESTEDIN*/ )
364 Color aCol(COL_AUTO);
365 ApplyCommand(m_aActions.GetCurItemId(),aCol);
366 return 0L;
369 //------------------------------------------------------------------
370 IMPL_LINK( Condition, OnConditionAction, Button*, _pClickedButton )
372 if ( _pClickedButton == &m_aMoveUp )
373 m_rAction.moveConditionUp( getConditionIndex() );
374 else if ( _pClickedButton == &m_aMoveDown )
375 m_rAction.moveConditionDown( getConditionIndex() );
376 else if ( _pClickedButton == &m_aAddCondition )
377 m_rAction.addCondition( getConditionIndex() );
378 else if ( _pClickedButton == &m_aRemoveCondition )
379 m_rAction.deleteCondition( getConditionIndex() );
380 return 0L;
383 //------------------------------------------------------------------------------
384 void Condition::ApplyCommand( USHORT _nCommandId, const ::Color& _rColor)
386 if ( _nCommandId == SID_ATTR_CHAR_COLOR2 )
387 m_pBtnUpdaterFontColor->Update( _rColor );
388 else if ( _nCommandId == SID_BACKGROUND_COLOR )
389 m_pBtnUpdaterBackgroundColor->Update( _rColor );
391 m_rAction.applyCommand( m_nCondIndex, _nCommandId, _rColor );
393 //------------------------------------------------------------------------------
394 ImageList Condition::getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
396 sal_Int16 nN = IMG_CONDFORMAT_DLG_SC;
397 sal_Int16 nH = IMG_CONDFORMAT_DLG_SCH;
398 if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
400 nN = IMG_CONDFORMAT_DLG_LC;
401 nH = IMG_CONDFORMAT_DLG_LCH;
403 return ImageList(ModuleRes( _bHiContast ? nH : nN ));
405 //------------------------------------------------------------------
406 void Condition::resizeControls(const Size& _rDiff)
408 // we use large images so we must change them
409 if ( _rDiff.Width() || _rDiff.Height() )
411 Point aPos = LogicToPixel( Point( 2*RELATED_CONTROLS , 0), MAP_APPFONT );
412 Invalidate();
415 // -----------------------------------------------------------------------------
416 void Condition::Paint( const Rectangle& rRect )
418 Control::Paint(rRect);
420 // draw border
421 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
422 ColorChanger aColors( this, rStyleSettings.GetShadowColor(), rStyleSettings.GetDialogColor() );
423 DrawRect( impl_getToolBarBorderRect() );
425 // -----------------------------------------------------------------------------
426 void Condition::StateChanged( StateChangedType nType )
428 Control::StateChanged( nType );
430 if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
432 // Check if we need to get new images for normal/high contrast mode
433 checkImageList();
435 else if ( nType == STATE_CHANGE_TEXT )
437 // The physical toolbar changed its outlook and shows another logical toolbar!
438 // We have to set the correct high contrast mode on the new tbx manager.
439 // pMgr->SetHiContrast( IsHiContrastMode() );
440 checkImageList();
443 // -----------------------------------------------------------------------------
444 void Condition::DataChanged( const DataChangedEvent& rDCEvt )
446 Control::DataChanged( rDCEvt );
448 if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
449 ( rDCEvt.GetType() == DATACHANGED_DISPLAY )) &&
450 ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
452 // Check if we need to get new images for normal/high contrast mode
453 checkImageList();
457 // -----------------------------------------------------------------------------
458 void Condition::GetFocus()
460 Control::GetFocus();
461 if ( !m_bInDestruction )
462 m_aCondLHS.GrabFocus();
465 // -----------------------------------------------------------------------------
466 void Condition::Resize()
468 Control::Resize();
469 impl_layoutAll();
472 // -----------------------------------------------------------------------------
473 Rectangle Condition::impl_getToolBarBorderRect() const
475 const Point aToolbarPos( m_aActions.GetPosPixel() );
476 const Size aToolbarSize( m_aActions.GetSizePixel() );
477 const Size aRelatedControls = LogicToPixel( Size( RELATED_CONTROLS, RELATED_CONTROLS ), MAP_APPFONT );
479 Rectangle aBorderRect( aToolbarPos, aToolbarSize );
480 aBorderRect.Left() -= aRelatedControls.Width();
481 aBorderRect.Top() -= aRelatedControls.Height();
482 aBorderRect.Right() += aRelatedControls.Width();
483 aBorderRect.Bottom() += aRelatedControls.Height();
485 return aBorderRect;
488 // -----------------------------------------------------------------------------
489 void Condition::impl_layoutAll()
491 // if our width changed, resize/-position some controls
492 const Size aSize( GetOutputSizePixel() );
493 if ( aSize.Width() == m_nLastKnownWindowWidth )
494 return;
496 m_nLastKnownWindowWidth = aSize.Width();
498 const Size aRelatedControls( LogicToPixel( Size( RELATED_CONTROLS, RELATED_CONTROLS ), MAP_APPFONT ) );
499 const Size aUnrelatedControls( LogicToPixel( Size( UNRELATED_CONTROLS, 0 ), MAP_APPFONT ) );
500 const Point aRow1( LogicToPixel( Point( 0, ROW_1_POS ), MAP_APPFONT ) );
501 const Point aRow3( LogicToPixel( Point( 0, ROW_3_POS ), MAP_APPFONT ) );
503 // resize the header line
504 m_aHeader.SetPosSizePixel( 0, 0, aSize.Width() - 2 * aRelatedControls.Width(), 0, WINDOW_POSSIZE_WIDTH );
506 // position the up/down buttons
507 const Size aButtonSize( LogicToPixel( Size( IMAGE_BUTTON_WIDTH, IMAGE_BUTTON_HEIGHT ), MAP_APPFONT ) );
508 Point aButtonPos( aSize.Width() - aUnrelatedControls.Width() - aButtonSize.Width(), aRow1.Y() );
509 m_aMoveUp.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
510 aButtonPos.Move( 0, aButtonSize.Height() + aRelatedControls.Height() );
511 m_aMoveDown.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
513 // resize the preview
514 const long nNewPreviewRight = aButtonPos.X() - aRelatedControls.Width();
516 const Point aPreviewPos( m_aPreview.GetPosPixel() );
517 OSL_ENSURE( aPreviewPos.X() < nNewPreviewRight, "Condition::impl_layoutAll: being *that* small should not be allowed!" );
518 m_aPreview.SetPosSizePixel( 0, 0, nNewPreviewRight - aPreviewPos.X(), 0, WINDOW_POSSIZE_WIDTH );
520 // position the add/remove buttons
521 aButtonPos = Point( nNewPreviewRight - aButtonSize.Width(), aRow3.Y() );
522 m_aRemoveCondition.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
523 aButtonPos.Move( -( aButtonSize.Width() + aRelatedControls.Width() ), 0 );
524 m_aAddCondition.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
526 // layout the operands input controls
527 impl_layoutOperands();
530 // -----------------------------------------------------------------------------
531 IMPL_LINK( Condition, OnTypeSelected, ListBox*, /*_pNotInterestedIn*/ )
533 impl_layoutOperands();
534 return 0L;
537 // -----------------------------------------------------------------------------
538 IMPL_LINK( Condition, OnOperationSelected, ListBox*, /*_pNotInterestedIn*/ )
540 impl_layoutOperands();
541 return 0L;
544 // -----------------------------------------------------------------------------
545 void Condition::impl_layoutOperands()
547 const ConditionType eType( impl_getCurrentConditionType() );
548 const ComparisonOperation eOperation( impl_getCurrentComparisonOperation() );
550 const bool bIsExpression = ( eType == eExpression );
551 const bool bHaveRHS =
552 ( ( eType == eFieldValueComparison )
553 && ( ( eOperation == eBetween )
554 || ( eOperation == eNotBetween )
558 const Size aRelatedControls( LogicToPixel( Size( RELATED_CONTROLS, 0 ), MAP_APPFONT ) );
559 const Rectangle aPreviewRect( m_aPreview.GetPosPixel(), m_aPreview.GetSizePixel() );
561 // the "condition type" list box
562 const Rectangle aCondTypeRect( m_aConditionType.GetPosPixel(), m_aConditionType.GetSizePixel() );
563 const Point aOpListPos( aCondTypeRect.Right() + aRelatedControls.Width(), aCondTypeRect.Top() );
564 const Size aOpListSize( LogicToPixel( Size( COND_OP_WIDTH, 60 ), MAP_APPFONT ) );
565 m_aOperationList.SetPosSizePixel( aOpListPos.X(), aOpListPos.Y(),aOpListSize.Width(), aOpListSize.Height() );
566 m_aOperationList.Show( !bIsExpression );
568 // the LHS input field
569 Point aLHSPos( aOpListPos.X() + aOpListSize.Width() + aRelatedControls.Width(), aOpListPos.Y() );
570 if ( bIsExpression )
571 aLHSPos.X() = aOpListPos.X();
572 Size aLHSSize( LogicToPixel( Size( EDIT_WIDTH, EDIT_HEIGHT ), MAP_APPFONT ) );
573 if ( !bHaveRHS )
574 aLHSSize.Width() = aPreviewRect.Right() - aLHSPos.X();
575 m_aCondLHS.SetPosSizePixel( aLHSPos.X(), aLHSPos.Y(), aLHSSize.Width(), aLHSSize.Height() );
577 if ( bHaveRHS )
579 // the "and" text being the glue between LHS and RHS
580 const Point aOpGluePos( aLHSPos.X() + aLHSSize.Width() + aRelatedControls.Width(), aLHSPos.Y() );
581 const Size aOpGlueSize( m_aOperandGlue.GetTextWidth( m_aOperandGlue.GetText() ) + aRelatedControls.Width(), aLHSSize.Height() );
582 m_aOperandGlue.SetPosSizePixel( aOpGluePos.X(), aOpGluePos.Y(), aOpGlueSize.Width(), aOpGlueSize.Height() );
584 // the RHS input field
585 const Point aRHSPos( aOpGluePos.X() + aOpGlueSize.Width() + aRelatedControls.Width(), aOpGluePos.Y() );
586 const Size aRHSSize( aPreviewRect.Right() - aRHSPos.X(), aLHSSize.Height() );
587 m_aCondRHS.SetPosSizePixel( aRHSPos.X(), aRHSPos.Y(), aRHSSize.Width(), aRHSSize.Height() );
590 m_aOperandGlue.Show( bHaveRHS );
591 m_aCondRHS.Show( bHaveRHS );
594 // -----------------------------------------------------------------------------
595 void Condition::impl_setCondition( const ::rtl::OUString& _rConditionFormula )
597 // determine the condition's type and comparison operation
598 ConditionType eType( eFieldValueComparison );
599 ComparisonOperation eOperation( eBetween );
601 // LHS and RHS, matched below
602 ::rtl::OUString sLHS, sRHS;
604 if ( _rConditionFormula.getLength() )
606 // the unprefixed expression which forms the condition
607 ReportFormula aFormula( _rConditionFormula );
608 OSL_ENSURE( aFormula.getType() == ReportFormula::Expression, "Condition::setCondition: illegal formula!" );
609 ::rtl::OUString sExpression;
610 if ( aFormula.getType() == ReportFormula::Expression )
611 sExpression = aFormula.getExpression();
612 // as fallback, if the below matching does not succeed, assume
613 // the whole expression is the LHS
614 eType = eExpression;
615 sLHS = sExpression;
617 // the data field (or expression) to which our control is bound
618 const ReportFormula aFieldContentFormula( m_rAction.getDataField() );
619 const ::rtl::OUString sUnprefixedFieldContent( aFieldContentFormula.getBracketedFieldOrExpression() );
621 // check whether one of the Field Value Expression Factories recognizes the expression
622 for ( ConditionalExpressions::const_iterator exp = m_aConditionalExpressions.begin();
623 exp != m_aConditionalExpressions.end();
624 ++exp
627 if ( exp->second->matchExpression( sExpression, sUnprefixedFieldContent, sLHS, sRHS ) )
629 eType = eFieldValueComparison;
630 eOperation = exp->first;
631 break;
636 // update UI
637 m_aConditionType.SelectEntryPos( (USHORT)eType );
638 m_aOperationList.SelectEntryPos( (USHORT)eOperation );
639 m_aCondLHS.SetText( sLHS );
640 m_aCondRHS.SetText( sRHS );
642 // re-layout
643 impl_layoutOperands();
646 // -----------------------------------------------------------------------------
647 void Condition::setCondition( const uno::Reference< report::XFormatCondition >& _rxCondition )
649 OSL_PRECOND( _rxCondition.is(), "Condition::setCondition: empty condition object!" );
650 if ( !_rxCondition.is() )
651 return;
653 ::rtl::OUString sConditionFormula;
656 if ( _rxCondition.is() )
657 sConditionFormula = _rxCondition->getFormula();
659 catch( const Exception& )
661 DBG_UNHANDLED_EXCEPTION();
663 impl_setCondition( sConditionFormula );
664 updateToolbar( _rxCondition.get() );
667 // -----------------------------------------------------------------------------
668 void Condition::updateToolbar(const uno::Reference< report::XReportControlFormat >& _xReportControlFormat)
670 OSL_ENSURE(_xReportControlFormat.is(),"XReportControlFormat is NULL!");
671 if ( _xReportControlFormat.is() )
673 USHORT nItemCount = m_aActions.GetItemCount();
674 for (USHORT j = 0; j< nItemCount; ++j)
676 USHORT nItemId = m_aActions.GetItemId(j);
677 m_aActions.CheckItem( nItemId, m_rController.isFormatCommandEnabled( nItemId, _xReportControlFormat ) );
682 Font aBaseFont( Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetAppFont() );
683 SvxFont aFont( VCLUnoHelper::CreateFont( _xReportControlFormat->getFontDescriptor(), aBaseFont ) );
684 aFont.SetHeight( OutputDevice::LogicToLogic( Size( 0, (sal_Int32)aFont.GetHeight() ), MAP_POINT, MAP_TWIP ).Height());
685 aFont.SetEmphasisMark( static_cast< FontEmphasisMark >( _xReportControlFormat->getControlTextEmphasis() ) );
686 aFont.SetRelief( static_cast< FontRelief >( _xReportControlFormat->getCharRelief() ) );
687 aFont.SetColor( _xReportControlFormat->getCharColor() );
688 m_aPreview.SetFont( aFont );
689 m_aPreview.SetBackColor( _xReportControlFormat->getControlBackground() );
690 m_aPreview.SetTextLineColor( Color( _xReportControlFormat->getCharUnderlineColor() ) );
692 catch( const Exception& )
694 DBG_UNHANDLED_EXCEPTION();
698 // -----------------------------------------------------------------------------
699 void Condition::fillFormatCondition(const uno::Reference< report::XFormatCondition >& _xCondition)
701 const ConditionType eType( impl_getCurrentConditionType() );
702 const ComparisonOperation eOperation( impl_getCurrentComparisonOperation() );
704 const ::rtl::OUString sLHS( m_aCondLHS.GetText() );
705 const ::rtl::OUString sRHS( m_aCondRHS.GetText() );
707 ::rtl::OUString sUndecoratedFormula( sLHS );
709 if ( eType == eFieldValueComparison )
711 ReportFormula aFieldContentFormula( m_rAction.getDataField() );
712 ::rtl::OUString sUnprefixedFieldContent( aFieldContentFormula.getBracketedFieldOrExpression() );
714 PConditionalExpression pFactory( m_aConditionalExpressions[ eOperation ] );
715 sUndecoratedFormula = pFactory->assembleExpression( sUnprefixedFieldContent, sLHS, sRHS );
718 ReportFormula aFormula( ReportFormula::Expression, sUndecoratedFormula );
719 _xCondition->setFormula( aFormula.getCompleteFormula() );
721 // -----------------------------------------------------------------------------
722 void Condition::setConditionIndex( size_t _nCondIndex, size_t _nCondCount )
724 m_nCondIndex = _nCondIndex;
725 String sHeader( ModuleRes( STR_NUMBERED_CONDITION ) );
726 sHeader.SearchAndReplaceAscii( "$number$", String::CreateFromInt32( _nCondIndex + 1 ) );
727 m_aHeader.SetText( sHeader );
729 m_aMoveUp.Enable( _nCondIndex > 0 );
730 OSL_PRECOND( _nCondCount > 0, "Condition::setConditionIndex: having no conditions at all is nonsense!" );
731 m_aMoveDown.Enable( _nCondIndex < _nCondCount - 1 );
734 // -----------------------------------------------------------------------------
735 bool Condition::isEmpty() const
737 return m_aCondLHS.GetText().Len() == 0;
740 // =============================================================================
741 } // rptui
742 // =============================================================================