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

Generated by: LCOV version 1.10