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

Generated by: LCOV version 1.10