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