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