LCOV - code coverage report
Current view: top level - reportdesign/source/ui/dlg - Condition.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 359 0.0 %
Date: 2014-04-14 Functions: 0 45 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10