LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - SelectionBrowseBox.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 1483 0.1 %
Date: 2015-06-13 12:38:46 Functions: 2 100 2.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 "SelectionBrowseBox.hxx"
      21             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      22             : #include <com/sun/star/sdbc/DataType.hpp>
      23             : #include "QueryDesignView.hxx"
      24             : #include "querycontroller.hxx"
      25             : #include "sqlbison.hxx"
      26             : #include "QueryTableView.hxx"
      27             : #include "browserids.hxx"
      28             : #include <comphelper/extract.hxx>
      29             : #include <comphelper/stl_types.hxx>
      30             : #include <comphelper/string.hxx>
      31             : #include <comphelper/types.hxx>
      32             : #include "TableFieldInfo.hxx"
      33             : #include "dbu_qry.hrc"
      34             : #include "dbaccess_helpid.hrc"
      35             : #include <com/sun/star/container/XNameAccess.hpp>
      36             : #include "dbustrings.hrc"
      37             : #include "QTableWindow.hxx"
      38             : #include <vcl/msgbox.hxx>
      39             : #include <vcl/settings.hxx>
      40             : #include "QueryDesignFieldUndoAct.hxx"
      41             : #include "sqlmessage.hxx"
      42             : #include "UITools.hxx"
      43             : #include <osl/diagnose.h>
      44             : #include "svtools/treelistentry.hxx"
      45             : 
      46             : using namespace ::svt;
      47             : using namespace ::dbaui;
      48             : using namespace ::connectivity;
      49             : using namespace ::com::sun::star::uno;
      50             : using namespace ::com::sun::star::sdbc;
      51             : using namespace ::com::sun::star::beans;
      52             : using namespace ::com::sun::star::container;
      53             : using namespace ::com::sun::star::util;
      54             : using namespace ::com::sun::star::accessibility;
      55             : 
      56             : #define DEFAULT_QUERY_COLS  20
      57             : #define DEFAULT_SIZE        GetTextWidth("0") * 30
      58             : #define CHECKBOX_SIZE       10
      59             : #define HANDLE_ID            0
      60             : #define HANDLE_COLUMN_WITDH 70
      61             : #define SORT_COLUMN_NONE    0xFFFFFFFF
      62             : 
      63             : namespace
      64             : {
      65           0 :     bool isFieldNameAsterisk(const OUString& _sFieldName )
      66             :     {
      67           0 :         bool bAsterisk = !(!_sFieldName.isEmpty() && _sFieldName.toChar() != '*');
      68           0 :         if ( !bAsterisk )
      69             :         {
      70           0 :             OUString sName = _sFieldName;
      71           0 :             sal_Int32 nTokenCount = comphelper::string::getTokenCount(sName, '.');
      72           0 :             if (    (nTokenCount == 2 && sName.getToken(1,'.')[0] == '*' )
      73           0 :                 ||  (nTokenCount == 3 && sName.getToken(2,'.')[0] == '*' ) )
      74             :             {
      75           0 :                 bAsterisk = true;
      76           0 :             }
      77             :         }
      78           0 :         return bAsterisk;
      79             :     }
      80           0 :     bool lcl_SupportsCoreSQLGrammar(const Reference< XConnection>& _xConnection)
      81             :     {
      82           0 :         bool bSupportsCoreGrammar = false;
      83           0 :         if ( _xConnection.is() )
      84             :         {
      85             :             try
      86             :             {
      87           0 :                 Reference< XDatabaseMetaData >  xMetaData = _xConnection->getMetaData();
      88           0 :                 bSupportsCoreGrammar = xMetaData.is() && xMetaData->supportsCoreSQLGrammar();
      89             :             }
      90           0 :             catch(Exception&)
      91             :             {
      92             :             }
      93             :         }
      94           0 :         return bSupportsCoreGrammar;
      95             :     }
      96             : }
      97             : 
      98           0 : OSelectionBrowseBox::OSelectionBrowseBox( vcl::Window* pParent )
      99             :                    :EditBrowseBox( pParent,EditBrowseBoxFlags::NO_HANDLE_COLUMN_CONTENT, WB_3DLOOK, BrowserMode::COLUMNSELECTION | BrowserMode::KEEPHIGHLIGHT |  BrowserMode::HIDESELECT |
     100           0 :                                   BrowserMode::HIDECURSOR | BrowserMode::HLINES | BrowserMode::VLINES )
     101             :                    ,m_nSeekRow(0)
     102             :                    ,m_nMaxColumns(0)
     103             :                    ,m_aFunctionStrings(ModuleRes(STR_QUERY_FUNCTIONS))
     104             :                    ,m_nVisibleCount(0)
     105             :                    ,m_nLastSortColumn(SORT_COLUMN_NONE)
     106             :                    ,m_bOrderByUnRelated(true)
     107             :                    ,m_bGroupByUnRelated(true)
     108             :                    ,m_bStopTimer(false)
     109             :                    ,m_bWasEditing(false)
     110             :                    ,m_bDisableErrorBox(false)
     111           0 :                    ,m_bInUndoMode(false)
     112             : {
     113           0 :     SetHelpId(HID_CTL_QRYDGNCRIT);
     114             : 
     115           0 :     m_nMode =       BrowserMode::COLUMNSELECTION | BrowserMode::HIDESELECT
     116             :                 |   BrowserMode::KEEPHIGHLIGHT   | BrowserMode::HIDECURSOR
     117             :                 |   BrowserMode::HLINES      | BrowserMode::VLINES
     118           0 :                 |   BrowserMode::HEADERBAR_NEW   ;
     119             : 
     120           0 :     m_pTextCell     = VclPtr<Edit>::Create(&GetDataWindow(), 0);
     121           0 :     m_pVisibleCell  = VclPtr<CheckBoxControl>::Create(&GetDataWindow());
     122           0 :     m_pTableCell    = VclPtr<ListBoxControl>::Create(&GetDataWindow());     m_pTableCell->SetDropDownLineCount( 20 );
     123           0 :     m_pFieldCell    = VclPtr<ComboBoxControl>::Create(&GetDataWindow());    m_pFieldCell->SetDropDownLineCount( 20 );
     124           0 :     m_pOrderCell    = VclPtr<ListBoxControl>::Create(&GetDataWindow());
     125           0 :     m_pFunctionCell = VclPtr<ListBoxControl>::Create(&GetDataWindow());     m_pFunctionCell->SetDropDownLineCount( 20 );
     126             : 
     127           0 :     m_pVisibleCell->SetHelpId(HID_QRYDGN_ROW_VISIBLE);
     128           0 :     m_pTableCell->SetHelpId(HID_QRYDGN_ROW_TABLE);
     129           0 :     m_pFieldCell->SetHelpId(HID_QRYDGN_ROW_FIELD);
     130           0 :     m_pOrderCell->SetHelpId(HID_QRYDGN_ROW_ORDER);
     131           0 :     m_pFunctionCell->SetHelpId(HID_QRYDGN_ROW_FUNCTION);
     132             : 
     133             :     // switch off triState of ::com::sun::star::form::CheckBox
     134           0 :     m_pVisibleCell->GetBox().EnableTriState( false );
     135             : 
     136           0 :     vcl::Font aTitleFont = OutputDevice::GetDefaultFont( DefaultFontType::SANS_UNICODE,Window::GetSettings().GetLanguageTag().getLanguageType(),GetDefaultFontFlags::OnlyOne);
     137           0 :     aTitleFont.SetSize(Size(0, 6));
     138           0 :     SetTitleFont(aTitleFont);
     139             : 
     140           0 :     OUString aTxt(ModuleRes(STR_QUERY_SORTTEXT));
     141           0 :     sal_Int32 nCount = comphelper::string::getTokenCount(aTxt, ';');
     142           0 :     for (sal_Int32 nIdx = 0; nIdx < nCount; nIdx++)
     143           0 :         m_pOrderCell->InsertEntry(aTxt.getToken(nIdx, ';'));
     144             : 
     145           0 :     for(long i=0;i < BROW_ROW_CNT;i++)
     146           0 :         m_bVisibleRow.push_back(true);
     147             : 
     148           0 :     m_bVisibleRow[BROW_FUNCTION_ROW] = false;   // first hide
     149             : 
     150           0 :     m_timerInvalidate.SetTimeout(200);
     151           0 :     m_timerInvalidate.SetTimeoutHdl(LINK(this, OSelectionBrowseBox, OnInvalidateTimer));
     152           0 :     m_timerInvalidate.Start();
     153           0 : }
     154             : 
     155           0 : OSelectionBrowseBox::~OSelectionBrowseBox()
     156             : {
     157           0 :     disposeOnce();
     158           0 : }
     159             : 
     160           0 : void OSelectionBrowseBox::dispose()
     161             : {
     162           0 :     m_pTextCell.disposeAndClear();
     163           0 :     m_pVisibleCell.disposeAndClear();
     164           0 :     m_pFieldCell.disposeAndClear();
     165           0 :     m_pTableCell.disposeAndClear();
     166           0 :     m_pOrderCell.disposeAndClear();
     167           0 :     m_pFunctionCell.disposeAndClear();
     168           0 :     ::svt::EditBrowseBox::dispose();
     169           0 : }
     170             : 
     171           0 : void OSelectionBrowseBox::initialize()
     172             : {
     173           0 :     Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
     174           0 :     if(xConnection.is())
     175             :     {
     176           0 :         const IParseContext& rContext = static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext();
     177             :         IParseContext::InternationalKeyCode eFunctions[] = { IParseContext::KEY_AVG,IParseContext::KEY_COUNT,IParseContext::KEY_MAX
     178             :             ,IParseContext::KEY_MIN,IParseContext::KEY_SUM
     179             :             ,IParseContext::KEY_EVERY
     180             :             ,IParseContext::KEY_ANY
     181             :             ,IParseContext::KEY_SOME
     182             :             ,IParseContext::KEY_STDDEV_POP
     183             :             ,IParseContext::KEY_STDDEV_SAMP
     184             :             ,IParseContext::KEY_VAR_SAMP
     185             :             ,IParseContext::KEY_VAR_POP
     186             :             ,IParseContext::KEY_COLLECT
     187             :             ,IParseContext::KEY_FUSION
     188             :             ,IParseContext::KEY_INTERSECTION
     189           0 :         };
     190             : 
     191           0 :         OUString sGroup = m_aFunctionStrings.getToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';') - 1, ';');
     192           0 :         m_aFunctionStrings = m_aFunctionStrings.getToken(0, ';');
     193             : 
     194           0 :         for (size_t i = 0; i < sizeof (eFunctions) / sizeof (eFunctions[0]); ++i)
     195             :         {
     196           0 :             m_aFunctionStrings += ";";
     197           0 :             m_aFunctionStrings += OStringToOUString(rContext.getIntlKeywordAscii(eFunctions[i]),
     198           0 :                 RTL_TEXTENCODING_UTF8);
     199             :         }
     200           0 :         m_aFunctionStrings += ";";
     201           0 :         m_aFunctionStrings += sGroup;
     202             : 
     203             :         // Aggregate functions in general available only with Core SQL
     204             :         // We slip in a few optionals one, too.
     205           0 :         if ( lcl_SupportsCoreSQLGrammar(xConnection) )
     206             :         {
     207           0 :             sal_Int32 nCount = comphelper::string::getTokenCount(m_aFunctionStrings, ';');
     208           0 :             for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++ )
     209           0 :                 m_pFunctionCell->InsertEntry(m_aFunctionStrings.getToken(nIdx, ';'));
     210             :         }
     211             :         else // else only COUNT(*) and COUNT("table".*)
     212             :         {
     213           0 :             m_pFunctionCell->InsertEntry(m_aFunctionStrings.getToken(0, ';'));
     214           0 :             m_pFunctionCell->InsertEntry(m_aFunctionStrings.getToken(2, ';')); // 2 -> COUNT
     215             :         }
     216             :         try
     217             :         {
     218           0 :             Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
     219           0 :             if ( xMetaData.is() )
     220             :             {
     221           0 :                 m_bOrderByUnRelated = xMetaData->supportsOrderByUnrelated();
     222           0 :                 m_bGroupByUnRelated = xMetaData->supportsGroupByUnrelated();
     223           0 :             }
     224             :         }
     225           0 :         catch(Exception&)
     226             :         {
     227           0 :         }
     228             :     }
     229             : 
     230           0 :     Init();
     231           0 : }
     232             : 
     233           0 : OQueryDesignView* OSelectionBrowseBox::getDesignView()
     234             : {
     235             :     OSL_ENSURE(static_cast<const OQueryDesignView*>(GetParent()),"Parent isn't an OQueryDesignView!");
     236           0 :     return static_cast<OQueryDesignView*>(GetParent());
     237             : }
     238             : 
     239           0 : OQueryDesignView* OSelectionBrowseBox::getDesignView() const
     240             : {
     241             :     OSL_ENSURE(static_cast<const OQueryDesignView*>(GetParent()),"Parent isn't an OQueryDesignView!");
     242           0 :     return static_cast<OQueryDesignView*>(GetParent());
     243             : }
     244             : 
     245             : namespace
     246             : {
     247             :     class OSelectionBrwBoxHeader : public ::svt::EditBrowserHeader
     248             :     {
     249             :         VclPtr<OSelectionBrowseBox> m_pBrowseBox;
     250             :     protected:
     251             :         virtual void Select() SAL_OVERRIDE;
     252             :     public:
     253             :         OSelectionBrwBoxHeader(OSelectionBrowseBox* pParent);
     254           0 :         virtual ~OSelectionBrwBoxHeader() { disposeOnce(); }
     255           0 :         virtual void dispose() SAL_OVERRIDE { m_pBrowseBox.clear(); ::svt::EditBrowserHeader::dispose(); }
     256             :     };
     257           0 :     OSelectionBrwBoxHeader::OSelectionBrwBoxHeader(OSelectionBrowseBox* pParent)
     258             :         : ::svt::EditBrowserHeader(pParent,WB_BUTTONSTYLE|WB_DRAG)
     259           0 :         ,m_pBrowseBox(pParent)
     260             :     {
     261           0 :     }
     262             : 
     263           0 :     void OSelectionBrwBoxHeader::Select()
     264             :     {
     265           0 :         EditBrowserHeader::Select();
     266           0 :         m_pBrowseBox->GrabFocus();
     267             : 
     268           0 :         BrowserMode nMode = m_pBrowseBox->GetMode();
     269           0 :         if ( 0 == m_pBrowseBox->GetSelectColumnCount() )
     270             :         {
     271           0 :             m_pBrowseBox->DeactivateCell();
     272             :             // we are in the right mode if a row hase been selected row
     273           0 :             if ( nMode & BrowserMode::HIDESELECT )
     274             :             {
     275           0 :                 nMode &= ~BrowserMode::HIDESELECT;
     276           0 :                 nMode |= BrowserMode::MULTISELECTION;
     277           0 :                 m_pBrowseBox->SetMode( nMode );
     278             :             }
     279             :         }
     280           0 :         m_pBrowseBox->SelectColumnId( GetCurItemId() );
     281           0 :         m_pBrowseBox->DeactivateCell();
     282           0 :     }
     283             : }
     284             : 
     285           0 : VclPtr<BrowserHeader> OSelectionBrowseBox::imp_CreateHeaderBar(BrowseBox* /*pParent*/)
     286             : {
     287           0 :     return VclPtr<OSelectionBrwBoxHeader>::Create(this);
     288             : }
     289             : 
     290           0 : void OSelectionBrowseBox::ColumnMoved( sal_uInt16 nColId, bool _bCreateUndo )
     291             : {
     292           0 :     EditBrowseBox::ColumnMoved( nColId );
     293             :     // swap the two columns
     294           0 :     sal_uInt16 nNewPos = GetColumnPos( nColId );
     295           0 :     OTableFields& rFields = getFields();
     296           0 :     if ( rFields.size() > sal_uInt16(nNewPos-1) )
     297             :     {
     298           0 :         sal_uInt16 nOldPos = 0;
     299           0 :         OTableFields::iterator aEnd = rFields.end();
     300           0 :         OTableFields::iterator aIter = rFields.begin();
     301           0 :         for (; aIter != aEnd && ( (*aIter)->GetColumnId() != nColId ); ++aIter,++nOldPos)
     302             :             ;
     303             : 
     304             :         OSL_ENSURE( (nNewPos-1) != nOldPos && nOldPos < rFields.size(),"Old and new position are equal!");
     305           0 :         if ( aIter != aEnd )
     306             :         {
     307           0 :             OTableFieldDescRef pOldEntry = rFields[nOldPos];
     308           0 :             rFields.erase(rFields.begin() + nOldPos);
     309           0 :             rFields.insert(rFields.begin() + nNewPos - 1,pOldEntry);
     310             : 
     311             :             // create the undo action
     312           0 :             if ( !m_bInUndoMode && _bCreateUndo )
     313             :             {
     314           0 :                 OTabFieldMovedUndoAct* pUndoAct = new OTabFieldMovedUndoAct(this);
     315           0 :                 pUndoAct->SetColumnPosition( nOldPos + 1);
     316           0 :                 pUndoAct->SetTabFieldDescr(pOldEntry);
     317             : 
     318           0 :                 getDesignView()->getController().addUndoActionAndInvalidate(pUndoAct);
     319           0 :             }
     320             :         }
     321             :     }
     322             :     else
     323             :         OSL_FAIL("Invalid column id!");
     324           0 : }
     325             : 
     326           0 : void OSelectionBrowseBox::Init()
     327             : {
     328             : 
     329           0 :     EditBrowseBox::Init();
     330             : 
     331             :     // set the header bar
     332           0 :     BrowserHeader* pNewHeaderBar = CreateHeaderBar(this);
     333           0 :     pNewHeaderBar->SetMouseTransparent(false);
     334             : 
     335           0 :     SetHeaderBar(pNewHeaderBar);
     336           0 :     SetMode(m_nMode);
     337             : 
     338           0 :     vcl::Font aFont( GetDataWindow().GetFont() );
     339           0 :     aFont.SetWeight( WEIGHT_NORMAL );
     340           0 :     GetDataWindow().SetFont( aFont );
     341             : 
     342           0 :     Size aHeight;
     343           0 :     const Control* pControls[] = { m_pTextCell,m_pVisibleCell,m_pTableCell,m_pFieldCell };
     344             : 
     345           0 :     for (sal_Size i = 0; i < sizeof (pControls) / sizeof (pControls[0]); ++i)
     346             :     {
     347           0 :         const Size aTemp(pControls[i]->GetOptimalSize());
     348           0 :         if ( aTemp.Height() > aHeight.Height() )
     349           0 :             aHeight.Height() = aTemp.Height();
     350             :     }
     351           0 :     SetDataRowHeight(aHeight.Height());
     352           0 :     SetTitleLines(1);
     353             :     // get number of visible rows
     354           0 :     for(long i=0;i<BROW_ROW_CNT;i++)
     355             :     {
     356           0 :         if(m_bVisibleRow[i])
     357           0 :             m_nVisibleCount++;
     358             :     }
     359           0 :     RowInserted(0, m_nVisibleCount, false);
     360             :     try
     361             :     {
     362           0 :         Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
     363           0 :         if(xConnection.is())
     364             :         {
     365           0 :             Reference< XDatabaseMetaData >  xMetaData = xConnection->getMetaData();
     366           0 :             m_nMaxColumns = xMetaData.is() ? xMetaData->getMaxColumnsInSelect() : 0;
     367             : 
     368             :         }
     369             :         else
     370           0 :             m_nMaxColumns = 0;
     371             :     }
     372           0 :     catch(const SQLException&)
     373             :     {
     374             :         OSL_FAIL("Catched Exception when asking for database metadata options!");
     375           0 :         m_nMaxColumns = 0;
     376           0 :     }
     377           0 : }
     378             : 
     379           0 : void OSelectionBrowseBox::PreFill()
     380             : {
     381           0 :     SetUpdateMode(false);
     382             : 
     383           0 :     if (GetCurRow() != 0)
     384           0 :         GoToRow(0);
     385             : 
     386           0 :     static_cast< OQueryController& >( getDesignView()->getController() ).clearFields();
     387             : 
     388           0 :     DeactivateCell();
     389             : 
     390           0 :     RemoveColumns();
     391           0 :     InsertHandleColumn( HANDLE_COLUMN_WITDH );
     392           0 :     SetUpdateMode(true);
     393           0 : }
     394             : 
     395           0 : void OSelectionBrowseBox::ClearAll()
     396             : {
     397           0 :     SetUpdateMode(false);
     398             : 
     399           0 :     OTableFields::reverse_iterator aIter = getFields().rbegin();
     400           0 :     for ( ;aIter != getFields().rend(); ++aIter )
     401             :     {
     402           0 :         if ( !(*aIter)->IsEmpty() )
     403             :         {
     404           0 :             RemoveField( (*aIter)->GetColumnId() );
     405           0 :             aIter = getFields().rbegin();
     406             :         }
     407             :     }
     408           0 :     m_nLastSortColumn = SORT_COLUMN_NONE;
     409           0 :     SetUpdateMode(true);
     410           0 : }
     411             : 
     412           0 : void OSelectionBrowseBox::SetReadOnly(bool bRO)
     413             : {
     414           0 :     if (bRO)
     415             :     {
     416           0 :         DeactivateCell();
     417           0 :         m_nMode &= ~BrowserMode::HIDECURSOR;
     418           0 :         SetMode(m_nMode);
     419             :     }
     420             :     else
     421             :     {
     422           0 :         m_nMode |= BrowserMode::HIDECURSOR;
     423           0 :         SetMode(m_nMode);
     424           0 :         ActivateCell();
     425             :     }
     426           0 : }
     427             : 
     428           0 : CellController* OSelectionBrowseBox::GetController(long nRow, sal_uInt16 nColId)
     429             : {
     430           0 :     if ( nColId > getFields().size() )
     431           0 :         return NULL;
     432           0 :     OTableFieldDescRef pEntry = getFields()[nColId-1];
     433             :     OSL_ENSURE(pEntry.is(), "OSelectionBrowseBox::GetController : keine FieldDescription !");
     434             : 
     435           0 :     if (!pEntry.is())
     436           0 :         return NULL;
     437             : 
     438           0 :     if (static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
     439           0 :         return NULL;
     440             : 
     441           0 :     long nCellIndex = GetRealRow(nRow);
     442           0 :     switch (nCellIndex)
     443             :     {
     444             :         case BROW_FIELD_ROW:
     445           0 :             return new ComboBoxCellController(m_pFieldCell);
     446             :         case BROW_TABLE_ROW:
     447           0 :             return new ListBoxCellController(m_pTableCell);
     448             :         case BROW_VIS_ROW:
     449           0 :             return new CheckBoxCellController(m_pVisibleCell);
     450             :         case BROW_ORDER_ROW:
     451           0 :             return new ListBoxCellController(m_pOrderCell);
     452             :         case BROW_FUNCTION_ROW:
     453           0 :             return new ListBoxCellController(m_pFunctionCell);
     454             :         default:
     455           0 :             return new EditCellController(m_pTextCell);
     456           0 :     }
     457             : }
     458             : 
     459           0 : void OSelectionBrowseBox::InitController(CellControllerRef& /*rController*/, long nRow, sal_uInt16 nColId)
     460             : {
     461             :     OSL_ENSURE(nColId != BROWSER_INVALIDID,"An Invalid Id was set!");
     462           0 :     if ( nColId == BROWSER_INVALIDID )
     463           0 :         return;
     464           0 :     sal_uInt16 nPos = GetColumnPos(nColId);
     465           0 :     if ( nPos == 0 || nPos == BROWSER_INVALIDID || nPos > getFields().size() )
     466           0 :         return;
     467           0 :     OTableFieldDescRef pEntry = getFields()[nPos-1];
     468             :     OSL_ENSURE(pEntry.is(), "OSelectionBrowseBox::InitController : keine FieldDescription !");
     469           0 :     long nCellIndex = GetRealRow(nRow);
     470             : 
     471           0 :     switch (nCellIndex)
     472             :     {
     473             :         case BROW_FIELD_ROW:
     474             :         {
     475           0 :             m_pFieldCell->Clear();
     476           0 :             m_pFieldCell->SetText(OUString());
     477             : 
     478           0 :             OUString aField(pEntry->GetField());
     479           0 :             OUString aTable(pEntry->GetAlias());
     480             : 
     481           0 :             getDesignView()->fillValidFields(aTable, m_pFieldCell);
     482             : 
     483             :             // replace with alias.*
     484           0 :             if (aField.trim() == "*")
     485             :             {
     486           0 :                 aField = aTable + ".*";
     487             :             }
     488           0 :             m_pFieldCell->SetText(aField);
     489           0 :         }   break;
     490             :         case BROW_TABLE_ROW:
     491             :         {
     492           0 :             m_pTableCell->Clear();
     493           0 :             enableControl(pEntry,m_pTableCell);
     494           0 :             if ( !pEntry->isCondition() )
     495             :             {
     496           0 :                 OJoinTableView::OTableWindowMap& rTabWinList = getDesignView()->getTableView()->GetTabWinMap();
     497           0 :                 OJoinTableView::OTableWindowMap::iterator aIter = rTabWinList.begin();
     498           0 :                 OJoinTableView::OTableWindowMap::iterator aEnd = rTabWinList.end();
     499             : 
     500           0 :                 for(;aIter != aEnd;++aIter)
     501           0 :                     m_pTableCell->InsertEntry(static_cast<OQueryTableWindow*>(aIter->second.get())->GetAliasName());
     502             : 
     503           0 :                 m_pTableCell->InsertEntry(OUString(ModuleRes(STR_QUERY_NOTABLE)), 0);
     504           0 :                 if (!pEntry->GetAlias().isEmpty())
     505           0 :                     m_pTableCell->SelectEntry(pEntry->GetAlias());
     506             :                 else
     507           0 :                     m_pTableCell->SelectEntry(OUString(ModuleRes(STR_QUERY_NOTABLE)));
     508             :             }
     509           0 :         }   break;
     510             :         case BROW_VIS_ROW:
     511             :         {
     512           0 :             m_pVisibleCell->GetBox().Check(pEntry->IsVisible());
     513           0 :             m_pVisibleCell->GetBox().SaveValue();
     514             : 
     515           0 :             enableControl(pEntry,m_pTextCell);
     516             : 
     517           0 :             if(!pEntry->IsVisible() && pEntry->GetOrderDir() != ORDER_NONE && !m_bOrderByUnRelated)
     518             :             {
     519             :                // a column has to visible in order to show up in ORDER BY
     520           0 :                 pEntry->SetVisible(true);
     521           0 :                 m_pVisibleCell->GetBox().Check(pEntry->IsVisible());
     522           0 :                 m_pVisibleCell->GetBox().SaveValue();
     523           0 :                 m_pVisibleCell->GetBox().Disable();
     524           0 :                 m_pVisibleCell->GetBox().EnableInput(false);
     525           0 :                 OUString aMessage(ModuleRes(STR_QRY_ORDERBY_UNRELATED));
     526           0 :                 OQueryDesignView* paDView = getDesignView();
     527           0 :                 ScopedVclPtr<InfoBox>::Create(paDView, aMessage)->Execute();
     528             :             }
     529           0 :         }   break;
     530             :         case BROW_ORDER_ROW:
     531           0 :             m_pOrderCell->SelectEntryPos(
     532           0 :                 sal::static_int_cast< sal_uInt16 >(pEntry->GetOrderDir()));
     533           0 :             enableControl(pEntry,m_pOrderCell);
     534           0 :             break;
     535             :         case BROW_COLUMNALIAS_ROW:
     536           0 :             setTextCellContext(pEntry,pEntry->GetFieldAlias(),HID_QRYDGN_ROW_ALIAS);
     537           0 :             break;
     538             :         case BROW_FUNCTION_ROW:
     539           0 :             setFunctionCell(pEntry);
     540           0 :             break;
     541             :         default:
     542             :         {
     543           0 :             sal_uInt16  nIdx = sal_uInt16(nCellIndex - BROW_CRIT1_ROW);
     544           0 :             setTextCellContext(pEntry,pEntry->GetCriteria( nIdx ),HID_QRYDGN_ROW_CRIT);
     545             :         }
     546             :     }
     547           0 :     Controller()->ClearModified();
     548             : }
     549             : 
     550           0 : void OSelectionBrowseBox::notifyTableFieldChanged(const OUString& _sOldAlias, const OUString& _sAlias, bool& _bListAction, sal_uInt16 _nColumnId)
     551             : {
     552           0 :     appendUndoAction(_sOldAlias,_sAlias,BROW_TABLE_ROW,_bListAction);
     553           0 :     if ( m_bVisibleRow[BROW_TABLE_ROW] )
     554           0 :         RowModified(GetBrowseRow(BROW_TABLE_ROW), _nColumnId);
     555           0 : }
     556             : 
     557           0 : void OSelectionBrowseBox::notifyFunctionFieldChanged(const OUString& _sOldFunctionName, const OUString& _sFunctionName, bool& _bListAction, sal_uInt16 _nColumnId)
     558             : {
     559           0 :     appendUndoAction(_sOldFunctionName,_sFunctionName,BROW_FUNCTION_ROW,_bListAction);
     560           0 :     if ( !m_bVisibleRow[BROW_FUNCTION_ROW] )
     561           0 :         SetRowVisible(BROW_FUNCTION_ROW, true);
     562           0 :     RowModified(GetBrowseRow(BROW_FUNCTION_ROW), _nColumnId);
     563           0 : }
     564             : 
     565           0 : void OSelectionBrowseBox::clearEntryFunctionField(const OUString& _sFieldName,OTableFieldDescRef& _pEntry, bool& _bListAction,sal_uInt16 _nColumnId)
     566             : {
     567           0 :     if ( isFieldNameAsterisk( _sFieldName ) && (!_pEntry->isNoneFunction() || _pEntry->IsGroupBy()) )
     568             :     {
     569           0 :         OUString sFunctionName;
     570           0 :         GetFunctionName(SQL_TOKEN_COUNT,sFunctionName);
     571           0 :         OUString sOldLocalizedFunctionName = _pEntry->GetFunction();
     572           0 :         if ( sOldLocalizedFunctionName != sFunctionName || _pEntry->IsGroupBy() )
     573             :         {
     574             :             // append undo action for the function field
     575           0 :             _pEntry->SetFunctionType(FKT_NONE);
     576           0 :             _pEntry->SetFunction(OUString());
     577           0 :             _pEntry->SetGroupBy(false);
     578           0 :             notifyFunctionFieldChanged(sOldLocalizedFunctionName,_pEntry->GetFunction(),_bListAction,_nColumnId);
     579           0 :         }
     580             :     }
     581           0 : }
     582             : 
     583           0 : bool OSelectionBrowseBox::fillColumnRef(const OSQLParseNode* _pColumnRef, const Reference< XConnection >& _rxConnection, OTableFieldDescRef& _pEntry, bool& _bListAction )
     584             : {
     585             :     OSL_ENSURE(_pColumnRef,"No valid parsenode!");
     586           0 :     OUString sColumnName,sTableRange;
     587           0 :     OSQLParseTreeIterator::getColumnRange(_pColumnRef,_rxConnection,sColumnName,sTableRange);
     588           0 :     return fillColumnRef(sColumnName,sTableRange,_rxConnection->getMetaData(),_pEntry,_bListAction);
     589             : }
     590             : 
     591           0 : bool OSelectionBrowseBox::fillColumnRef(const OUString& _sColumnName, const OUString& _sTableRange, const Reference<XDatabaseMetaData>& _xMetaData, OTableFieldDescRef& _pEntry, bool& _bListAction)
     592             : {
     593           0 :     bool bError = false;
     594           0 :     ::comphelper::UStringMixEqual bCase(_xMetaData->supportsMixedCaseQuotedIdentifiers());
     595             :     // check if the table name is the same
     596           0 :     if ( !_sTableRange.isEmpty() && (bCase(_pEntry->GetTable(),_sTableRange) || bCase(_pEntry->GetAlias(),_sTableRange)) )
     597             :     { // a table was already inserted and the tables contains that column name
     598             : 
     599           0 :         if ( !_pEntry->GetTabWindow() )
     600             :         { // fill tab window
     601           0 :             OUString sOldAlias = _pEntry->GetAlias();
     602           0 :             if ( !fillEntryTable(_pEntry,_pEntry->GetTable()) )
     603           0 :                 fillEntryTable(_pEntry,_pEntry->GetAlias()); // only when the first failed
     604           0 :             if ( !bCase(sOldAlias,_pEntry->GetAlias()) )
     605           0 :                 notifyTableFieldChanged(sOldAlias,_pEntry->GetAlias(),_bListAction,GetCurColumnId());
     606             :         }
     607             :     }
     608             :     // check if the table window
     609           0 :     OQueryTableWindow* pEntryTab = static_cast<OQueryTableWindow*>(_pEntry->GetTabWindow());
     610           0 :     if ( !pEntryTab ) // no table found with this name so we have to travel through all tables
     611             :     {
     612           0 :         sal_uInt16 nTabCount = 0;
     613           0 :         if ( !static_cast<OQueryTableView*>(getDesignView()->getTableView())->FindTableFromField(_sColumnName,_pEntry,nTabCount) ) // error occurred: column not in table window
     614             :         {
     615           0 :             OUString sErrorMsg(ModuleRes(RID_STR_FIELD_DOESNT_EXIST));
     616           0 :             sErrorMsg = sErrorMsg.replaceFirst("$name$",_sColumnName);
     617           0 :             ScopedVclPtr<OSQLErrorBox>::Create( this, sErrorMsg )->Execute();
     618           0 :             bError = true;
     619             :         }
     620             :         else
     621             :         {
     622           0 :             pEntryTab = static_cast<OQueryTableWindow*>(_pEntry->GetTabWindow());
     623           0 :             notifyTableFieldChanged(OUString(),_pEntry->GetAlias(),_bListAction,GetCurColumnId());
     624             :         }
     625             :     }
     626           0 :     if ( pEntryTab ) // here we got a valid table
     627           0 :         _pEntry->SetField(_sColumnName);
     628             : 
     629           0 :     return bError;
     630             : }
     631             : 
     632           0 : bool OSelectionBrowseBox::saveField(OUString& _sFieldName ,OTableFieldDescRef& _pEntry, bool& _bListAction)
     633             : {
     634           0 :     bool bError = false;
     635             : 
     636           0 :     OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
     637             : 
     638             :     // first look if the name can be found in our tables
     639           0 :     sal_uInt16 nTabCount = 0;
     640           0 :     OUString sOldAlias = _pEntry->GetAlias();
     641           0 :     if ( static_cast<OQueryTableView*>(getDesignView()->getTableView())->FindTableFromField(_sFieldName,_pEntry,nTabCount) )
     642             :     {
     643             :         // append undo action for the alias name
     644           0 :         _pEntry->SetField(_sFieldName);
     645           0 :         notifyTableFieldChanged(sOldAlias,_pEntry->GetAlias(),_bListAction,GetCurColumnId());
     646           0 :         clearEntryFunctionField(_sFieldName,_pEntry,_bListAction,_pEntry->GetColumnId());
     647           0 :         return bError;
     648             :     }
     649             : 
     650           0 :     Reference<XConnection> xConnection( rController.getConnection() );
     651           0 :     Reference< XDatabaseMetaData > xMetaData;
     652           0 :     if ( xConnection.is() )
     653           0 :         xMetaData = xConnection->getMetaData();
     654             :     OSL_ENSURE( xMetaData.is(), "OSelectionBrowseBox::saveField: invalid connection/meta data!" );
     655           0 :     if ( !xMetaData.is() )
     656           0 :         return true;
     657             : 
     658           0 :     OUString sErrorMsg;
     659             :     // second test if the name can be set as select columns in a pseudo statement
     660             :     // we have to look which entries  we should quote
     661             : 
     662           0 :     const OUString sFieldAlias = _pEntry->GetFieldAlias();
     663           0 :     ::connectivity::OSQLParser& rParser( rController.getParser() );
     664             :     {
     665             :         // automatically add parentheses around subqueries
     666           0 :         OSQLParseNode *pParseNode = NULL;
     667           0 :         OUString devnull;
     668           0 :         pParseNode = rParser.parseTree( devnull, _sFieldName, true );
     669           0 :         if (pParseNode == NULL)
     670           0 :             pParseNode = rParser.parseTree( devnull, _sFieldName, false );
     671           0 :         if (pParseNode != NULL && SQL_ISRULE(pParseNode, select_statement))
     672           0 :             _sFieldName = "(" + _sFieldName + ")";
     673             :     }
     674             : 
     675           0 :     OSQLParseNode* pParseNode = NULL;
     676             :     {
     677             :         // 4 passes in trying to interprete the field name
     678             :         // - don't quote the field name, parse internationally
     679             :         // - don't quote the field name, parse en-US
     680             :         // - quote the field name, parse internationally
     681             :         // - quote the field name, parse en-US
     682           0 :         size_t nPass = 4;
     683           0 :         OUString sQuotedFullFieldName(::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), _sFieldName ));
     684           0 :         OUString sFullFieldName(_sFieldName);
     685             : 
     686           0 :         if  ( _pEntry->isAggreateFunction() )
     687             :         {
     688             :             OSL_ENSURE(!_pEntry->GetFunction().isEmpty(),"Functionname darf hier nicht leer sein! ;-(");
     689           0 :             sQuotedFullFieldName = _pEntry->GetFunction() + "(" + sQuotedFullFieldName + ")";
     690           0 :             sFullFieldName = _pEntry->GetFunction() + "(" + sFullFieldName + ")";
     691             :         }
     692             : 
     693           0 :         do
     694             :         {
     695           0 :             bool bQuote = ( nPass <= 2 );
     696           0 :             bool bInternational = ( nPass % 2 ) == 0;
     697             : 
     698           0 :             OUString sSql;
     699           0 :             if ( bQuote )
     700           0 :                 sSql += sQuotedFullFieldName;
     701             :             else
     702           0 :                 sSql += sFullFieldName;
     703             : 
     704           0 :             sSql = "SELECT " + sSql;
     705           0 :             if ( !sFieldAlias.isEmpty() )
     706             :             { // always quote the alias name: there cannot be a function in it
     707           0 :                 sSql += " ";
     708           0 :                 sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), sFieldAlias );
     709             :             }
     710           0 :             sSql += " FROM x";
     711             : 
     712           0 :             pParseNode = rParser.parseTree( sErrorMsg, sSql, bInternational );
     713             :         }
     714           0 :         while ( ( pParseNode == NULL ) && ( --nPass > 0 ) );
     715             :     }
     716             : 
     717           0 :     if ( pParseNode == NULL )
     718             :     {
     719             :         // something different which we have to check
     720           0 :         OUString sErrorMessage( ModuleRes( STR_QRY_COLUMN_NOT_FOUND ) );
     721           0 :         sErrorMessage = sErrorMessage.replaceFirst("$name$",_sFieldName);
     722           0 :         ScopedVclPtr<OSQLErrorBox>::Create( this, sErrorMessage )->Execute();
     723             : 
     724           0 :         return true;
     725             :     }
     726             : 
     727             :     // we got a valid select column
     728             :     // find what type of column has be inserted
     729           0 :     ::connectivity::OSQLParseNode* pSelection = pParseNode->getChild(2);
     730           0 :     if ( SQL_ISRULE(pSelection,selection) ) // we found the asterisk
     731             :     {
     732           0 :         _pEntry->SetField(_sFieldName);
     733           0 :         clearEntryFunctionField(_sFieldName,_pEntry,_bListAction,_pEntry->GetColumnId());
     734             :     }
     735             :     else // travel through the select column parse node
     736             :     {
     737           0 :         ::comphelper::UStringMixEqual bCase(xMetaData->supportsMixedCaseQuotedIdentifiers());
     738             : 
     739           0 :         OTableFieldDescRef aSelEntry = _pEntry;
     740           0 :         sal_uInt16 nColumnId = aSelEntry->GetColumnId();
     741             : 
     742           0 :         sal_uInt32 nCount = pSelection->count();
     743           0 :         for (sal_uInt32 i = 0; i < nCount; ++i)
     744             :         {
     745           0 :             if ( i > 0 ) // may we have to append more than one field
     746             :             {
     747             :                 sal_uInt16 nColumnPostion;
     748           0 :                 aSelEntry = FindFirstFreeCol(nColumnPostion);
     749           0 :                 if ( !aSelEntry.is() )
     750             :                 {
     751           0 :                     AppendNewCol(1);
     752           0 :                     aSelEntry = FindFirstFreeCol(nColumnPostion);
     753             :                 }
     754           0 :                 ++nColumnPostion;
     755           0 :                 nColumnId = GetColumnId(nColumnPostion);
     756             :             }
     757             : 
     758           0 :             ::connectivity::OSQLParseNode* pChild = pSelection->getChild( i );
     759             :             OSL_ENSURE(SQL_ISRULE(pChild,derived_column), "No derived column found!");
     760             :             // get the column alias
     761           0 :             OUString sColumnAlias = OSQLParseTreeIterator::getColumnAlias(pChild);
     762           0 :             if ( !sColumnAlias.isEmpty() ) // we found an as clause
     763             :             {
     764           0 :                 OUString aSelectionAlias = aSelEntry->GetFieldAlias();
     765           0 :                 aSelEntry->SetFieldAlias( sColumnAlias );
     766             :                 // append undo
     767           0 :                 appendUndoAction(aSelectionAlias,aSelEntry->GetFieldAlias(),BROW_COLUMNALIAS_ROW,_bListAction);
     768           0 :                 if ( m_bVisibleRow[BROW_COLUMNALIAS_ROW] )
     769           0 :                     RowModified(GetBrowseRow(BROW_COLUMNALIAS_ROW), nColumnId);
     770             :             }
     771             : 
     772           0 :             ::connectivity::OSQLParseNode* pColumnRef = pChild->getChild(0);
     773           0 :             if (
     774           0 :                     pColumnRef->getKnownRuleID() != OSQLParseNode::subquery &&
     775           0 :                     pColumnRef->count() == 3 &&
     776           0 :                     SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") &&
     777           0 :                     SQL_ISPUNCTUATION(pColumnRef->getChild(2),")")
     778             :                 )
     779           0 :                 pColumnRef = pColumnRef->getChild(1);
     780             : 
     781           0 :             if ( SQL_ISRULE(pColumnRef,column_ref) ) // we found a valid column name or more column names
     782             :             {
     783             :                 // look if we can find the corresponding table
     784           0 :                 bError = fillColumnRef( pColumnRef, xConnection, aSelEntry, _bListAction );
     785             : 
     786             :                 // we found a simple column so we must clear the function fields but only when the column name is '*'
     787             :                 // and the function is different to count
     788           0 :                 clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
     789             :             }
     790             :             // do we have a aggregate function and only a function?
     791           0 :             else if ( SQL_ISRULE(pColumnRef,general_set_fct) )
     792             :             {
     793           0 :                 OUString sLocalizedFunctionName;
     794           0 :                 if ( GetFunctionName(pColumnRef->getChild(0)->getTokenID(),sLocalizedFunctionName) )
     795             :                 {
     796           0 :                     OUString sOldLocalizedFunctionName = aSelEntry->GetFunction();
     797           0 :                     aSelEntry->SetFunction(sLocalizedFunctionName);
     798           0 :                     sal_uInt32 nFunCount = pColumnRef->count() - 1;
     799           0 :                     sal_Int32 nFunctionType = FKT_AGGREGATE;
     800           0 :                     bool bQuote = false;
     801             :                     // may be there exists only one parameter which is a column, fill all information into our fields
     802           0 :                     if ( nFunCount == 4 && SQL_ISRULE(pColumnRef->getChild(3),column_ref) )
     803           0 :                         bError = fillColumnRef( pColumnRef->getChild(3), xConnection, aSelEntry, _bListAction );
     804           0 :                     else if ( nFunCount == 3 ) // we have a COUNT(*) here, so take the first table
     805           0 :                         bError = fillColumnRef( OUString("*"), OUString(), xMetaData, aSelEntry, _bListAction );
     806             :                     else
     807             :                     {
     808           0 :                         nFunctionType |= FKT_NUMERIC;
     809           0 :                         bQuote = true;
     810           0 :                         aSelEntry->SetDataType(DataType::DOUBLE);
     811           0 :                         aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
     812             :                     }
     813             : 
     814             :                     // now parse the parameters
     815           0 :                     OUString sParameters;
     816           0 :                     for(sal_uInt32 function = 2; function < nFunCount; ++function) // we only want to parse the parameters of the function
     817           0 :                         pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), true, bQuote );
     818             : 
     819           0 :                     aSelEntry->SetFunctionType(nFunctionType);
     820           0 :                     aSelEntry->SetField(sParameters);
     821           0 :                     if ( aSelEntry->IsGroupBy() )
     822             :                     {
     823           0 :                         sOldLocalizedFunctionName = m_aFunctionStrings.getToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1, ';');
     824           0 :                         aSelEntry->SetGroupBy(false);
     825             :                     }
     826             : 
     827             :                     // append undo action
     828           0 :                     notifyFunctionFieldChanged(sOldLocalizedFunctionName,sLocalizedFunctionName,_bListAction, nColumnId);
     829             :                 }
     830             :                 else
     831           0 :                     OSL_FAIL("Unsupported function inserted!");
     832             : 
     833             :             }
     834             :             else
     835             :             {
     836             :                 // so we first clear the function field
     837           0 :                 clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
     838           0 :                 OUString sFunction;
     839             :                 pColumnRef->parseNodeToStr( sFunction,
     840             :                                             xConnection,
     841           0 :                                             &rController.getParser().getContext(),
     842             :                                             true,
     843           0 :                                             true); // quote is to true because we need quoted elements inside the function
     844             : 
     845           0 :                 getDesignView()->fillFunctionInfo(pColumnRef,sFunction,aSelEntry);
     846             : 
     847           0 :                 if( SQL_ISRULEOR3(pColumnRef, position_exp, extract_exp, fold) ||
     848           0 :                     SQL_ISRULEOR3(pColumnRef, char_substring_fct, length_exp, char_value_fct) )
     849             :                     // a calculation has been found ( can be calc and function )
     850             :                 {
     851             :                     // now parse the whole statement
     852           0 :                     sal_uInt32 nFunCount = pColumnRef->count();
     853           0 :                     OUString sParameters;
     854           0 :                     for(sal_uInt32 function = 0; function < nFunCount; ++function)
     855           0 :                         pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), true, true );
     856             : 
     857           0 :                     sOldAlias = aSelEntry->GetAlias();
     858           0 :                     sal_Int32 nNewFunctionType = aSelEntry->GetFunctionType() | FKT_NUMERIC | FKT_OTHER;
     859           0 :                     aSelEntry->SetFunctionType(nNewFunctionType);
     860           0 :                     aSelEntry->SetField(sParameters);
     861             :                 }
     862             :                 else
     863             :                 {
     864           0 :                     aSelEntry->SetFieldAlias(sColumnAlias);
     865           0 :                     if ( SQL_ISRULE(pColumnRef,set_fct_spec) )
     866           0 :                         aSelEntry->SetFunctionType(/*FKT_NUMERIC | */FKT_OTHER);
     867             :                     else
     868           0 :                         aSelEntry->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
     869             :                 }
     870             : 
     871           0 :                 aSelEntry->SetAlias(OUString());
     872           0 :                 notifyTableFieldChanged(sOldAlias,aSelEntry->GetAlias(),_bListAction, nColumnId);
     873             :             }
     874             : 
     875           0 :             if ( i > 0 && !InsertField(aSelEntry,BROWSER_INVALIDID,true,false).is() ) // may we have to append more than one field
     876             :             { // the field could not be inserted
     877           0 :                 OUString sErrorMessage( ModuleRes( RID_STR_FIELD_DOESNT_EXIST ) );
     878           0 :                 sErrorMessage = sErrorMessage.replaceFirst("$name$",aSelEntry->GetField());
     879           0 :                 ScopedVclPtr<OSQLErrorBox>::Create( this, sErrorMessage )->Execute();
     880           0 :                 bError = true;
     881             :             }
     882           0 :         }
     883             :     }
     884           0 :     delete pParseNode;
     885             : 
     886           0 :     return bError;
     887             : }
     888             : 
     889           0 : bool OSelectionBrowseBox::SaveModified()
     890             : {
     891           0 :     OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
     892           0 :     OTableFieldDescRef pEntry = NULL;
     893           0 :     sal_uInt16 nCurrentColumnPos = GetColumnPos(GetCurColumnId());
     894           0 :     if(getFields().size() > static_cast<sal_uInt16>(nCurrentColumnPos - 1))
     895           0 :         pEntry = getEntry(nCurrentColumnPos - 1);
     896             : 
     897           0 :     bool bWasEmpty      = pEntry.is() && pEntry->IsEmpty();
     898           0 :     bool bError         = false;
     899           0 :     bool bListAction    = false;
     900             : 
     901           0 :     if (pEntry.is() && Controller().Is() && Controller()->IsModified())
     902             :     {
     903             :         // for the Undo-action
     904           0 :         OUString strOldCellContents,sNewValue;
     905           0 :         long nRow = GetRealRow(GetCurRow());
     906           0 :         bool bAppendRow = false;
     907           0 :         switch (nRow)
     908             :         {
     909             :             case BROW_VIS_ROW:
     910             :                 {
     911           0 :                     bool bOldValue = m_pVisibleCell->GetBox().GetSavedValue() != TRISTATE_FALSE;
     912           0 :                     strOldCellContents = bOldValue ? OUStringLiteral("1") : OUStringLiteral("0");
     913           0 :                     sNewValue          = !bOldValue ? OUStringLiteral("1") : OUStringLiteral("0");
     914             :                 }
     915           0 :                 if((m_bOrderByUnRelated || pEntry->GetOrderDir() == ORDER_NONE) &&
     916           0 :                    (m_bGroupByUnRelated || !pEntry->IsGroupBy()))
     917             :                 {
     918           0 :                     pEntry->SetVisible(m_pVisibleCell->GetBox().IsChecked());
     919             :                 }
     920             :                 else
     921             :                 {
     922           0 :                     pEntry->SetVisible(true);
     923           0 :                     m_pVisibleCell->GetBox().Check();
     924             :                 }
     925           0 :                 break;
     926             : 
     927             :             case BROW_FIELD_ROW:
     928             :             {
     929           0 :                 OUString aFieldName(m_pFieldCell->GetText());
     930             :                 try
     931             :                 {
     932           0 :                     if (aFieldName.isEmpty())
     933             :                     {
     934           0 :                         OTableFieldDescRef pNewEntry = new OTableFieldDesc();
     935           0 :                         pNewEntry->SetColumnId( pEntry->GetColumnId() );
     936           0 :                         ::std::replace(getFields().begin(),getFields().end(),pEntry,pNewEntry);
     937           0 :                         sal_uInt16 nCol = GetCurColumnId();
     938           0 :                         for (int i = 0; i < m_nVisibleCount; i++)   // redraw column
     939           0 :                             RowModified(i,nCol);
     940             :                     }
     941             :                     else
     942             :                     {
     943           0 :                         strOldCellContents = pEntry->GetField();
     944           0 :                         bListAction = true;
     945           0 :                         if ( !m_bInUndoMode )
     946           0 :                             rController.GetUndoManager().EnterListAction(OUString(),OUString());
     947             : 
     948           0 :                         sal_Int32 nPos = m_pFieldCell->GetEntryPos(aFieldName);
     949           0 :                         OUString aAliasName = pEntry->GetAlias();
     950           0 :                         if ( nPos != COMBOBOX_ENTRY_NOTFOUND && aAliasName.isEmpty() && comphelper::string::getTokenCount(aFieldName, '.') > 1 )
     951             :                         { // special case, we have a table field so we must cut the table name
     952           0 :                             OUString sTableAlias = aFieldName.getToken(0,'.');
     953           0 :                             pEntry->SetAlias(sTableAlias);
     954           0 :                             OUString sColumnName = aFieldName.copy(sTableAlias.getLength()+1,aFieldName.getLength() - sTableAlias.getLength() -1);
     955           0 :                             Reference<XConnection> xConnection = rController.getConnection();
     956           0 :                             if ( !xConnection.is() )
     957           0 :                                 return false;
     958           0 :                             bError = fillColumnRef( sColumnName, sTableAlias, xConnection->getMetaData(), pEntry, bListAction );
     959             :                         }
     960             :                         else
     961           0 :                             bError = true;
     962             : 
     963           0 :                         if ( bError )
     964           0 :                             bError = saveField(aFieldName,pEntry,bListAction);
     965             :                     }
     966             :                 }
     967           0 :                 catch(Exception&)
     968             :                 {
     969           0 :                     bError = true;
     970             :                 }
     971           0 :                 if ( bError )
     972             :                 {
     973           0 :                     sNewValue = aFieldName;
     974           0 :                     if ( !m_bInUndoMode )
     975           0 :                         static_cast<OQueryController&>(getDesignView()->getController()).GetUndoManager().LeaveListAction();
     976           0 :                     bListAction = false;
     977             :                 }
     978             :                 else
     979           0 :                     sNewValue = pEntry->GetField();
     980           0 :                 rController.InvalidateFeature( ID_BROWSER_QUERY_EXECUTE );
     981             :             }
     982           0 :             break;
     983             : 
     984             :             case BROW_TABLE_ROW:
     985             :             {
     986           0 :                 OUString aAliasName = m_pTableCell->GetSelectEntry();
     987           0 :                 strOldCellContents = pEntry->GetAlias();
     988           0 :                 if ( m_pTableCell->GetSelectEntryPos() != 0 )
     989             :                 {
     990           0 :                     pEntry->SetAlias(aAliasName);
     991             :                     // we have to set the table name as well as the table window
     992           0 :                     OJoinTableView::OTableWindowMap& rTabWinList = getDesignView()->getTableView()->GetTabWinMap();
     993           0 :                     OJoinTableView::OTableWindowMap::iterator aIter = rTabWinList.find(aAliasName);
     994           0 :                     if(aIter != rTabWinList.end())
     995             :                     {
     996           0 :                         OQueryTableWindow* pEntryTab = static_cast<OQueryTableWindow*>(aIter->second.get());
     997           0 :                         if (pEntryTab)
     998             :                         {
     999           0 :                             pEntry->SetTable(pEntryTab->GetTableName());
    1000           0 :                             pEntry->SetTabWindow(pEntryTab);
    1001             :                         }
    1002             :                     }
    1003             :                 }
    1004             :                 else
    1005             :                 {
    1006           0 :                     pEntry->SetAlias(OUString());
    1007           0 :                     pEntry->SetTable(OUString());
    1008           0 :                     pEntry->SetTabWindow(NULL);
    1009             :                 }
    1010           0 :                 sNewValue = pEntry->GetAlias();
    1011             : 
    1012           0 :             }   break;
    1013             : 
    1014             :             case BROW_ORDER_ROW:
    1015             :             {
    1016           0 :                 strOldCellContents = OUString::number((sal_uInt16)pEntry->GetOrderDir());
    1017           0 :                 sal_Int32 nIdx = m_pOrderCell->GetSelectEntryPos();
    1018           0 :                 if (nIdx == LISTBOX_ENTRY_NOTFOUND)
    1019           0 :                     nIdx = 0;
    1020           0 :                 pEntry->SetOrderDir(EOrderDir(nIdx));
    1021           0 :                 if(!m_bOrderByUnRelated)
    1022             :                 {
    1023           0 :                     pEntry->SetVisible(true);
    1024           0 :                     m_pVisibleCell->GetBox().Check();
    1025           0 :                     RowModified(GetBrowseRow(BROW_VIS_ROW), GetCurColumnId());
    1026             :                 }
    1027           0 :                 sNewValue = OUString::number((sal_uInt16)pEntry->GetOrderDir());
    1028           0 :             }   break;
    1029             : 
    1030             :             case BROW_COLUMNALIAS_ROW:
    1031           0 :                 strOldCellContents = pEntry->GetFieldAlias();
    1032           0 :                 pEntry->SetFieldAlias(m_pTextCell->GetText());
    1033           0 :                 sNewValue = pEntry->GetFieldAlias();
    1034           0 :                 break;
    1035             :             case BROW_FUNCTION_ROW:
    1036             :                 {
    1037           0 :                     strOldCellContents = pEntry->GetFunction();
    1038           0 :                     sal_Int32 nPos = m_pFunctionCell->GetSelectEntryPos();
    1039             :                     // these functions are only available in CORE
    1040           0 :                     OUString sFunctionName        = m_pFunctionCell->GetEntry(nPos);
    1041           0 :                     OUString sGroupFunctionName   = m_aFunctionStrings.getToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1, ';');
    1042           0 :                     bool bGroupBy = false;
    1043           0 :                     if ( sGroupFunctionName.equals(sFunctionName) ) // check if the function name is GROUP
    1044             :                     {
    1045           0 :                         bGroupBy = true;
    1046             : 
    1047           0 :                         if ( !m_bGroupByUnRelated && !pEntry->IsVisible() )
    1048             :                         {
    1049             :                             // we have to change the visblie flag, so we must append also an undo action
    1050           0 :                             pEntry->SetVisible(true);
    1051           0 :                             m_pVisibleCell->GetBox().Check();
    1052           0 :                             appendUndoAction("0","1",BROW_VIS_ROW,bListAction);
    1053           0 :                             RowModified(GetBrowseRow(BROW_VIS_ROW), GetCurColumnId());
    1054             :                         }
    1055             : 
    1056           0 :                         pEntry->SetFunction(OUString());
    1057           0 :                         pEntry->SetFunctionType(pEntry->GetFunctionType() & ~FKT_AGGREGATE );
    1058             :                     }
    1059           0 :                     else if ( nPos ) // we found an aggregate function
    1060             :                     {
    1061           0 :                         pEntry->SetFunctionType(pEntry->GetFunctionType() | FKT_AGGREGATE );
    1062           0 :                         pEntry->SetFunction(sFunctionName);
    1063             :                     }
    1064             :                     else
    1065             :                     {
    1066           0 :                         sFunctionName.clear();
    1067           0 :                         pEntry->SetFunction(OUString());
    1068           0 :                         pEntry->SetFunctionType(pEntry->GetFunctionType() & ~FKT_AGGREGATE );
    1069             :                     }
    1070             : 
    1071           0 :                     pEntry->SetGroupBy(bGroupBy);
    1072             : 
    1073           0 :                     sNewValue = sFunctionName;
    1074             :                 }
    1075           0 :                 break;
    1076             :             default:
    1077             :             {
    1078           0 :                 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
    1079           0 :                 if(!xConnection.is())
    1080           0 :                     break;
    1081             : 
    1082           0 :                 sal_uInt16  nIdx = sal_uInt16(nRow - BROW_CRIT1_ROW);
    1083           0 :                 OUString aText = comphelper::string::stripStart(m_pTextCell->GetText(), ' ');
    1084             : 
    1085           0 :                 OUString aCrit;
    1086           0 :                 if(!aText.isEmpty())
    1087             :                 {
    1088           0 :                     OUString aErrorMsg;
    1089           0 :                     Reference<XPropertySet> xColumn;
    1090           0 :                     OSQLParseNode* pParseNode = getDesignView()->getPredicateTreeFromEntry(pEntry,aText,aErrorMsg,xColumn);
    1091             : 
    1092           0 :                     if (pParseNode)
    1093             :                     {
    1094             :                         pParseNode->parseNodeToPredicateStr(aCrit,
    1095             :                                                             xConnection,
    1096           0 :                                                             static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
    1097             :                                                             xColumn,
    1098             :                                                             pEntry->GetAlias(),
    1099             :                                                             getDesignView()->getLocale(),
    1100           0 :                                                             static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()),
    1101           0 :                                                             &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext()));
    1102           0 :                         delete pParseNode;
    1103             :                     }
    1104             :                     else
    1105             :                     {
    1106           0 :                         if(xColumn.is())
    1107             :                         {
    1108           0 :                             sal_Int32 nType = 0;
    1109           0 :                             xColumn->getPropertyValue(PROPERTY_TYPE) >>= nType;
    1110           0 :                             switch(nType)
    1111             :                             {
    1112             :                                 case DataType::CHAR:
    1113             :                                 case DataType::VARCHAR:
    1114             :                                 case DataType::LONGVARCHAR:
    1115             :                                 case DataType::CLOB:
    1116           0 :                                     if(!aText.startsWith("'") || !aText.endsWith("'"))
    1117             :                                     {
    1118           0 :                                         aText = aText.replaceAll("'", "''");
    1119           0 :                                         aText = "'" + aText + "'";
    1120             :                                     }
    1121           0 :                                     break;
    1122             :                                 default:
    1123             :                                     ;
    1124             :                             }
    1125           0 :                             ::connectivity::OSQLParser& rParser = static_cast<OQueryController&>(getDesignView()->getController()).getParser();
    1126             :                             pParseNode = rParser.predicateTree(aErrorMsg,
    1127             :                                                                 aText,
    1128           0 :                                                                 static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
    1129           0 :                                                                 xColumn);
    1130           0 :                             if (pParseNode)
    1131             :                             {
    1132             :                                 pParseNode->parseNodeToPredicateStr(aCrit,
    1133             :                                                                     xConnection,
    1134           0 :                                                                     static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
    1135             :                                                                     xColumn,
    1136             :                                                                     pEntry->GetAlias(),
    1137             :                                                                     getDesignView()->getLocale(),
    1138           0 :                                                                     static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()),
    1139           0 :                                                                     &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext()));
    1140           0 :                                 delete pParseNode;
    1141             :                             }
    1142             :                             else
    1143             :                             {
    1144           0 :                                 if ( !m_bDisableErrorBox )
    1145             :                                 {
    1146           0 :                                     ScopedVclPtr<OSQLWarningBox>::Create( this, aErrorMsg )->Execute();
    1147             :                                 }
    1148           0 :                                 bError = true;
    1149             :                             }
    1150             :                         }
    1151             :                         else
    1152             :                         {
    1153           0 :                             if ( !m_bDisableErrorBox )
    1154             :                             {
    1155           0 :                                 ScopedVclPtr<OSQLWarningBox>::Create( this, aErrorMsg )->Execute();
    1156             :                             }
    1157           0 :                             bError = true;
    1158             :                         }
    1159           0 :                     }
    1160             :                 }
    1161           0 :                 strOldCellContents = pEntry->GetCriteria(nIdx);
    1162           0 :                 pEntry->SetCriteria(nIdx, aCrit);
    1163           0 :                 sNewValue = pEntry->GetCriteria(nIdx);
    1164           0 :                 if(!aCrit.isEmpty() && nRow >= (GetRowCount()-1))
    1165           0 :                     bAppendRow = true;
    1166             :             }
    1167             :         }
    1168           0 :         if(!bError && Controller())
    1169           0 :             Controller()->ClearModified();
    1170             : 
    1171           0 :         RowModified(GetCurRow(), GetCurColumnId());
    1172             : 
    1173           0 :         if ( bAppendRow )
    1174             :         {
    1175           0 :             RowInserted( GetRowCount()-1, 1, true );
    1176           0 :             m_bVisibleRow.push_back(true);
    1177           0 :             ++m_nVisibleCount;
    1178             :         }
    1179             : 
    1180           0 :         if(!bError)
    1181             :         {
    1182             :             // and now the undo-action for the total
    1183           0 :             appendUndoAction(strOldCellContents,sNewValue,nRow);
    1184             : 
    1185           0 :         }
    1186             :     }
    1187             : 
    1188             :     // did I store data in a FieldDescription which was empty before and which is not empty anymore after the changes?
    1189           0 :     if ( pEntry.is() && bWasEmpty && !pEntry->IsEmpty() && !bError )
    1190             :     {
    1191             :         // Default to visible
    1192           0 :         pEntry->SetVisible(true);
    1193           0 :         appendUndoAction("0","1",BROW_VIS_ROW,bListAction);
    1194           0 :         RowModified(BROW_VIS_ROW, GetCurColumnId());
    1195             : 
    1196             :         // if required add empty columns
    1197             :         sal_uInt16 nDummy;
    1198           0 :         CheckFreeColumns(nDummy);
    1199             :     }
    1200             : 
    1201           0 :     if ( bListAction && !m_bInUndoMode )
    1202           0 :         static_cast<OQueryController&>(getDesignView()->getController()).GetUndoManager().LeaveListAction();
    1203             : 
    1204           0 :     return pEntry != NULL && !bError;
    1205             : }
    1206             : 
    1207           0 : bool OSelectionBrowseBox::SeekRow(long nRow)
    1208             : {
    1209           0 :     m_nSeekRow = nRow;
    1210           0 :     return nRow < m_nVisibleCount;
    1211             : }
    1212             : 
    1213           0 : void OSelectionBrowseBox::PaintCell(OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId) const
    1214             : {
    1215           0 :     rDev.SetClipRegion(vcl::Region(rRect));
    1216             : 
    1217           0 :     OTableFieldDescRef pEntry = NULL;
    1218           0 :     sal_uInt16 nPos = GetColumnPos(nColumnId);
    1219           0 :     if(getFields().size() > sal_uInt16(nPos - 1))
    1220           0 :         pEntry = getFields()[nPos - 1];
    1221             : 
    1222           0 :     if (!pEntry.is())
    1223           0 :         return;
    1224             : 
    1225           0 :     long nRow = GetRealRow(m_nSeekRow);
    1226           0 :     if (nRow == BROW_VIS_ROW)
    1227           0 :         PaintTristate(rDev, rRect, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE);
    1228             :     else
    1229           0 :         rDev.DrawText(rRect, GetCellText(nRow, nColumnId),DrawTextFlags::VCenter);
    1230             : 
    1231           0 :     rDev.SetClipRegion( );
    1232             : }
    1233             : 
    1234           0 : void OSelectionBrowseBox::PaintStatusCell(OutputDevice& rDev, const Rectangle& rRect) const
    1235             : {
    1236           0 :     Rectangle aRect(rRect);
    1237           0 :     aRect.TopLeft().Y() -= 2;
    1238           0 :     OUString  aLabel(ModuleRes(STR_QUERY_HANDLETEXT));
    1239             : 
    1240             :    // from BROW_CRIT2_ROW onwards all rows are shown "or"
    1241           0 :     sal_Int32 nToken = (m_nSeekRow >= GetBrowseRow(BROW_CRIT2_ROW))
    1242           0 :         ?  BROW_CRIT2_ROW : GetRealRow(m_nSeekRow);
    1243           0 :     rDev.DrawText(aRect, aLabel.getToken(nToken, ';'),DrawTextFlags::VCenter);
    1244           0 : }
    1245             : 
    1246           0 : void OSelectionBrowseBox::RemoveColumn(sal_uInt16 _nColumnId)
    1247             : {
    1248           0 :     OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
    1249             : 
    1250           0 :     sal_uInt16 nPos = GetColumnPos(_nColumnId);
    1251             :     // the control should always have exactly one more column: the HandleColumn
    1252             :     OSL_ENSURE((nPos == 0) || (nPos <= getFields().size()), "OSelectionBrowseBox::RemoveColumn : invalid parameter nColId");
    1253             :     // ColId is synonymous to Position, and the condition should be valid
    1254             : 
    1255           0 :     sal_uInt16 nCurCol = GetCurColumnId();
    1256           0 :     long nCurrentRow = GetCurRow();
    1257             : 
    1258           0 :     DeactivateCell();
    1259             : 
    1260           0 :     getFields().erase( getFields().begin() + (nPos - 1) );
    1261           0 :     OTableFieldDescRef pEntry = new OTableFieldDesc();
    1262           0 :     pEntry->SetColumnId(_nColumnId);
    1263           0 :     getFields().push_back(pEntry);
    1264             : 
    1265           0 :     EditBrowseBox::RemoveColumn( _nColumnId );
    1266           0 :     InsertDataColumn( _nColumnId , OUString(), DEFAULT_SIZE, HeaderBarItemBits::STDSTYLE, HEADERBAR_APPEND);
    1267             : 
    1268             :     // Neuzeichnen
    1269           0 :     Rectangle aInvalidRect = GetInvalidRect( _nColumnId );
    1270           0 :     Invalidate( aInvalidRect );
    1271             : 
    1272           0 :     ActivateCell( nCurrentRow, nCurCol );
    1273             : 
    1274           0 :     rController.setModified( sal_True );
    1275             : 
    1276           0 :     invalidateUndoRedo();
    1277           0 : }
    1278             : 
    1279           0 : void OSelectionBrowseBox::RemoveField(sal_uInt16 nColumnId )
    1280             : {
    1281           0 :     OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
    1282             : 
    1283           0 :     sal_uInt16 nPos = GetColumnPos(nColumnId);
    1284             :     OSL_ENSURE(getFields().size() > sal_uInt16(nPos-1),"ID is to great!");
    1285             : 
    1286           0 :     OTableFieldDescRef pDesc = getEntry((sal_uInt32)(nPos - 1)) ;
    1287           0 :     pDesc->SetColWidth( (sal_uInt16)GetColumnWidth(nColumnId) );    // was not stored this before
    1288             : 
    1289             :     // trigger UndoAction
    1290           0 :     if ( !m_bInUndoMode )
    1291             :     {
    1292           0 :         OTabFieldDelUndoAct* pUndoAction = new OTabFieldDelUndoAct( this );
    1293           0 :         pUndoAction->SetTabFieldDescr(pDesc);
    1294           0 :         pUndoAction->SetColumnPosition(nPos);
    1295           0 :         rController.addUndoActionAndInvalidate( pUndoAction );
    1296             :     }
    1297             : 
    1298           0 :     RemoveColumn(nColumnId);
    1299             : 
    1300           0 :     invalidateUndoRedo();
    1301           0 : }
    1302             : 
    1303           0 : void OSelectionBrowseBox::adjustSelectionMode( bool _bClickedOntoHeader, bool _bClickedOntoHandleCol )
    1304             : {
    1305             :     // if a Header has been selected it should be shown otherwise not
    1306           0 :     if ( _bClickedOntoHeader )
    1307             :     {
    1308           0 :         if (0 == GetSelectColumnCount() )
    1309             :             // I am in the correct mode if a selected column exists
    1310           0 :             if ( BrowserMode::HIDESELECT == ( m_nMode & BrowserMode::HIDESELECT ) )
    1311             :             {
    1312           0 :                 m_nMode &= ~BrowserMode::HIDESELECT;
    1313           0 :                 m_nMode |= BrowserMode::MULTISELECTION;
    1314           0 :                 SetMode( m_nMode );
    1315             :             }
    1316             :     }
    1317           0 :     else if ( BrowserMode::HIDESELECT != ( m_nMode & BrowserMode::HIDESELECT ) )
    1318             :     {
    1319           0 :         if ( GetSelectColumnCount() != 0 )
    1320           0 :             SetNoSelection();
    1321             : 
    1322           0 :         if ( _bClickedOntoHandleCol )
    1323             :         {
    1324           0 :             m_nMode |= BrowserMode::HIDESELECT;
    1325           0 :             m_nMode &= ~BrowserMode::MULTISELECTION;
    1326           0 :             SetMode( m_nMode );
    1327             :         }
    1328             :     }
    1329           0 : }
    1330             : 
    1331           0 : void OSelectionBrowseBox::MouseButtonDown(const BrowserMouseEvent& rEvt)
    1332             : {
    1333           0 :     if( rEvt.IsLeft() )
    1334             :     {
    1335           0 :         bool bOnHandle = HANDLE_ID == rEvt.GetColumnId();
    1336           0 :         bool bOnHeader = ( rEvt.GetRow() < 0 ) && !bOnHandle;
    1337           0 :         adjustSelectionMode( bOnHeader, bOnHandle );
    1338             :     }
    1339           0 :     EditBrowseBox::MouseButtonDown(rEvt);
    1340           0 : }
    1341             : 
    1342           0 : void OSelectionBrowseBox::MouseButtonUp(const BrowserMouseEvent& rEvt)
    1343             : {
    1344           0 :     EditBrowseBox::MouseButtonUp( rEvt );
    1345           0 :     static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( ID_BROWSER_QUERY_EXECUTE );
    1346           0 : }
    1347             : 
    1348           0 : void OSelectionBrowseBox::KeyInput( const KeyEvent& rEvt )
    1349             : {
    1350           0 :     if (IsColumnSelected(GetCurColumnId()))
    1351             :     {
    1352           0 :         if (rEvt.GetKeyCode().GetCode() == KEY_DELETE &&    // Delete rows
    1353           0 :             !rEvt.GetKeyCode().IsShift() &&
    1354           0 :             !rEvt.GetKeyCode().IsMod1())
    1355             :         {
    1356           0 :             RemoveField(GetCurColumnId());
    1357           0 :             return;
    1358             :         }
    1359             :     }
    1360           0 :     EditBrowseBox::KeyInput(rEvt);
    1361             : }
    1362             : 
    1363           0 : sal_Int8 OSelectionBrowseBox::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
    1364             : {
    1365           0 :     sal_Int8 nDropAction = DND_ACTION_NONE;
    1366           0 :     if  ( rEvt.GetRow() >= -1 )
    1367             :     {
    1368           0 :         if ( IsEditing() )
    1369             :         {
    1370             :             // allow the asterisk again
    1371           0 :             m_bDisableErrorBox = true;
    1372           0 :             SaveModified();
    1373           0 :             m_bDisableErrorBox = false;
    1374           0 :             DeactivateCell();
    1375             :         }
    1376             :         // check if the format is already supported, if not deactivate the current cell and try again
    1377           0 :         if ( OJoinExchObj::isFormatAvailable(GetDataFlavors()) )
    1378           0 :             nDropAction = DND_ACTION_LINK;
    1379             :     }
    1380             : 
    1381           0 :     return nDropAction;
    1382             : }
    1383             : 
    1384           0 : sal_Int8 OSelectionBrowseBox::ExecuteDrop( const BrowserExecuteDropEvent& _rEvt )
    1385             : {
    1386             : 
    1387           0 :     TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
    1388           0 :     if (!OJoinExchObj::isFormatAvailable(aDropped.GetDataFlavorExVector()))
    1389             :     {
    1390             :         OSL_FAIL("OSelectionBrowseBox::ExecuteDrop: this should never have passed AcceptDrop!");
    1391           0 :         return DND_ACTION_NONE;
    1392             :     }
    1393             : 
    1394           0 :     OTableFieldDesc aInfo;
    1395             :     // insert the field at the selected position
    1396           0 :     OJoinExchangeData jxdSource = OJoinExchObj::GetSourceDescription(_rEvt.maDropEvent.Transferable);
    1397           0 :     InsertField(jxdSource);
    1398             : 
    1399           0 :     return DND_ACTION_LINK;
    1400             : }
    1401             : 
    1402           0 : OTableFieldDescRef OSelectionBrowseBox::AppendNewCol( sal_uInt16 nCnt)
    1403             : {
    1404             :     // one or more can be created, but the first one will is not returned
    1405           0 :     sal_uInt32 nCount = getFields().size();
    1406           0 :     for (sal_uInt16 i=0 ; i<nCnt ; i++)
    1407             :     {
    1408           0 :         OTableFieldDescRef pEmptyEntry = new OTableFieldDesc();
    1409           0 :         getFields().push_back(pEmptyEntry);
    1410           0 :         sal_uInt16 nColumnId = sal::static_int_cast< sal_uInt16 >(getFields().size());
    1411           0 :         pEmptyEntry->SetColumnId( nColumnId );
    1412             : 
    1413           0 :         InsertDataColumn( nColumnId , OUString(), DEFAULT_SIZE, HeaderBarItemBits::STDSTYLE, HEADERBAR_APPEND);
    1414           0 :     }
    1415             : 
    1416           0 :     return getFields()[nCount];
    1417             : }
    1418             : 
    1419           0 : void OSelectionBrowseBox::DeleteFields(const OUString& rAliasName)
    1420             : {
    1421           0 :     if (!getFields().empty())
    1422             :     {
    1423           0 :         sal_uInt16 nColId = GetCurColumnId();
    1424           0 :         sal_uInt32 nRow = GetCurRow();
    1425             : 
    1426           0 :         bool bWasEditing = IsEditing();
    1427           0 :         if (bWasEditing)
    1428           0 :             DeactivateCell();
    1429             : 
    1430           0 :         OTableFields::reverse_iterator aIter = getFields().rbegin();
    1431           0 :         OTableFieldDescRef pEntry = NULL;
    1432           0 :         for(sal_uInt16 nPos=sal::static_int_cast< sal_uInt16 >(getFields().size());aIter != getFields().rend();++aIter,--nPos)
    1433             :         {
    1434           0 :             pEntry = *aIter;
    1435           0 :             if ( pEntry->GetAlias().equals( rAliasName ) )
    1436             :             {
    1437           0 :                 RemoveField( GetColumnId( nPos ) );
    1438           0 :                 break;
    1439             :             }
    1440             :         }
    1441             : 
    1442           0 :         if (bWasEditing)
    1443           0 :             ActivateCell(nRow , nColId);
    1444             :     }
    1445           0 : }
    1446             : 
    1447           0 : void OSelectionBrowseBox::SetColWidth(sal_uInt16 nColId, long nNewWidth)
    1448             : {
    1449           0 :     bool bWasEditing = IsEditing();
    1450           0 :     if (bWasEditing)
    1451           0 :         DeactivateCell();
    1452             : 
    1453             :     // create the BaseClass
    1454           0 :     SetColumnWidth(nColId, nNewWidth);
    1455             : 
    1456             :     // tell it the FieldDescription
    1457           0 :     OTableFieldDescRef pEntry = getEntry(GetColumnPos(nColId) - 1);
    1458           0 :     if (pEntry.is())
    1459           0 :         pEntry->SetColWidth(sal_uInt16(GetColumnWidth(nColId)));
    1460             : 
    1461           0 :     if (bWasEditing)
    1462           0 :         ActivateCell(GetCurRow(), GetCurColumnId());
    1463           0 : }
    1464             : 
    1465           0 : Rectangle OSelectionBrowseBox::GetInvalidRect( sal_uInt16 nColId )
    1466             : {
    1467             :     // The rectangle is the full output area of the window
    1468           0 :     Rectangle aInvalidRect( Point(0,0), GetOutputSizePixel() );
    1469             : 
    1470             :     // now update the left side
    1471           0 :     Rectangle aFieldRect(GetCellRect( 0, nColId )); // used instead of GetFieldRectPixel
    1472           0 :     aInvalidRect.Left() = aFieldRect.Left();
    1473             : 
    1474           0 :     return aInvalidRect;
    1475             : }
    1476             : 
    1477           0 : void OSelectionBrowseBox::InsertColumn(OTableFieldDescRef pEntry, sal_uInt16& _nColumnPosition)
    1478             : {
    1479             :     // the control should have exactly one more column: the HandleColumn
    1480             :     OSL_ENSURE(_nColumnPosition == BROWSER_INVALIDID || (_nColumnPosition <= (long)getFields().size()), "OSelectionBrowseBox::InsertColumn : invalid parameter nColId.");
    1481             :      // -1 means at the end. Count means at the end, others denotes a correct position
    1482             : 
    1483           0 :     sal_uInt16 nCurCol = GetCurColumnId();
    1484           0 :     long nCurrentRow = GetCurRow();
    1485             : 
    1486           0 :     DeactivateCell();
    1487             : 
    1488             :     // remember the column id of the current position
    1489           0 :     sal_uInt16 nColumnId = GetColumnId(_nColumnPosition);
    1490             :     // put at the end of the list if to small or to big,
    1491           0 :     if ((_nColumnPosition == BROWSER_INVALIDID) || (_nColumnPosition >= getFields().size()))   // append the field
    1492             :     {
    1493           0 :         if (FindFirstFreeCol(_nColumnPosition) == NULL)  // no more free columns
    1494             :         {
    1495           0 :             AppendNewCol(1);
    1496             :             _nColumnPosition = sal::static_int_cast< sal_uInt16 >(
    1497           0 :                 getFields().size());
    1498             :         }
    1499             :         else
    1500           0 :             ++_nColumnPosition; // within the list
    1501           0 :         nColumnId = GetColumnId(_nColumnPosition);
    1502           0 :         pEntry->SetColumnId( nColumnId );
    1503           0 :         getFields()[ _nColumnPosition - 1] = pEntry;
    1504             :     }
    1505             : 
    1506             :     // check if the column ids are identical, if not we have to move
    1507           0 :     if ( pEntry->GetColumnId() != nColumnId )
    1508             :     {
    1509           0 :         sal_uInt16 nOldPosition = GetColumnPos(pEntry->GetColumnId());
    1510             :         OSL_ENSURE( nOldPosition != 0,"Old position was 0. Not possible!");
    1511           0 :         SetColumnPos(pEntry->GetColumnId(),_nColumnPosition);
    1512             :         // we have to delete an empty field for the fields list, because the columns must have equal length
    1513           0 :         if ( nOldPosition > 0 && nOldPosition <= getFields().size() )
    1514           0 :             getFields()[nOldPosition - 1] = pEntry;
    1515             : 
    1516           0 :         ColumnMoved(pEntry->GetColumnId(),false);
    1517             :     }
    1518             : 
    1519           0 :     if ( pEntry->GetFunctionType() & (FKT_AGGREGATE) )
    1520             :     {
    1521           0 :         OUString sFunctionName = pEntry->GetFunction();
    1522           0 :         if ( GetFunctionName(sal_uInt32(-1),sFunctionName) )
    1523           0 :             pEntry->SetFunction(sFunctionName);
    1524             :     }
    1525             : 
    1526           0 :     nColumnId = pEntry->GetColumnId();
    1527             : 
    1528           0 :     SetColWidth(nColumnId,getDesignView()->getColWidth(GetColumnPos(nColumnId)-1));
    1529             :     // redraw
    1530           0 :     Rectangle aInvalidRect = GetInvalidRect( nColumnId );
    1531           0 :     Invalidate( aInvalidRect );
    1532             : 
    1533           0 :     ActivateCell( nCurrentRow, nCurCol );
    1534           0 :     static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True );
    1535             : 
    1536           0 :     invalidateUndoRedo();
    1537           0 : }
    1538             : 
    1539           0 : OTableFieldDescRef OSelectionBrowseBox::InsertField(const OJoinExchangeData& jxdSource, sal_uInt16 _nColumnPosition, bool bVis, bool bActivate)
    1540             : {
    1541           0 :     OQueryTableWindow* pSourceWin = static_cast<OQueryTableWindow*>(jxdSource.pListBox->GetTabWin());
    1542           0 :     if (!pSourceWin)
    1543           0 :         return NULL;
    1544             : 
    1545             :     // name and position of the selected field
    1546           0 :     OUString aFieldName = jxdSource.pListBox->GetEntryText(jxdSource.pEntry);
    1547           0 :     sal_uInt32 nFieldIndex = jxdSource.pListBox->GetModel()->GetAbsPos(jxdSource.pEntry);
    1548           0 :     OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(jxdSource.pEntry->GetUserData());
    1549             : 
    1550             :     // construct DragInfo, such that I use the other InsertField
    1551           0 :     OTableFieldDescRef aInfo = new OTableFieldDesc(pSourceWin->GetTableName(),aFieldName);
    1552           0 :     aInfo->SetTabWindow(pSourceWin);
    1553           0 :     aInfo->SetFieldIndex(nFieldIndex);
    1554           0 :     aInfo->SetFieldType(pInf->GetKeyType());
    1555           0 :     aInfo->SetAlias(pSourceWin->GetAliasName());
    1556             : 
    1557           0 :     aInfo->SetDataType(pInf->GetDataType());
    1558           0 :     aInfo->SetVisible(bVis);
    1559             : 
    1560           0 :     return InsertField(aInfo, _nColumnPosition, bVis, bActivate);
    1561             : }
    1562             : 
    1563           0 : OTableFieldDescRef OSelectionBrowseBox::InsertField(const OTableFieldDescRef& _rInfo, sal_uInt16 _nColumnPosition, bool bVis, bool bActivate)
    1564             : {
    1565             : 
    1566           0 :     if(m_nMaxColumns && m_nMaxColumns <= FieldsCount())
    1567           0 :         return NULL;
    1568           0 :     if (bActivate)
    1569           0 :         SaveModified();
    1570             : 
    1571             :     // new column description
    1572           0 :     OTableFieldDescRef pEntry = _rInfo;
    1573           0 :     pEntry->SetVisible(bVis);
    1574             : 
    1575             :     // insert column
    1576           0 :     InsertColumn( pEntry, _nColumnPosition );
    1577             : 
    1578           0 :     if ( !m_bInUndoMode )
    1579             :     {
    1580             :         // trigger UndoAction
    1581           0 :         OTabFieldCreateUndoAct* pUndoAction = new OTabFieldCreateUndoAct( this );
    1582           0 :         pUndoAction->SetTabFieldDescr( pEntry );
    1583           0 :         pUndoAction->SetColumnPosition(_nColumnPosition);
    1584           0 :         getDesignView()->getController().addUndoActionAndInvalidate( pUndoAction );
    1585             :     }
    1586             : 
    1587           0 :     return pEntry;
    1588             : }
    1589             : 
    1590           0 : sal_uInt16 OSelectionBrowseBox::FieldsCount()
    1591             : {
    1592           0 :     OTableFields::iterator aIter = getFields().begin();
    1593           0 :     sal_uInt16 nCount = 0;
    1594             : 
    1595           0 :     while (aIter != getFields().end())
    1596             :     {
    1597           0 :         if ((*aIter).is() && !(*aIter)->IsEmpty())
    1598           0 :             ++nCount;
    1599           0 :         ++aIter;
    1600             :     }
    1601             : 
    1602           0 :     return nCount;
    1603             : }
    1604             : 
    1605           0 : OTableFieldDescRef OSelectionBrowseBox::FindFirstFreeCol(sal_uInt16& _rColumnPosition )
    1606             : {
    1607           0 :     OTableFields::iterator aIter = getFields().begin();
    1608           0 :     OTableFields::iterator aEnd  = getFields().end();
    1609             : 
    1610           0 :     _rColumnPosition = BROWSER_INVALIDID;
    1611             : 
    1612           0 :     while ( aIter != aEnd )
    1613             :     {
    1614           0 :         ++_rColumnPosition;
    1615           0 :         OTableFieldDescRef pEntry = (*aIter);
    1616           0 :         if ( pEntry.is() && pEntry->IsEmpty() )
    1617           0 :             return pEntry;
    1618           0 :         ++aIter;
    1619           0 :     }
    1620             : 
    1621           0 :     return NULL;
    1622             : }
    1623             : 
    1624           0 : void OSelectionBrowseBox::CheckFreeColumns(sal_uInt16& _rColumnPosition)
    1625             : {
    1626           0 :     if (FindFirstFreeCol(_rColumnPosition) == NULL)
    1627             :     {
    1628             :         // it is full, append a Packen column
    1629           0 :         AppendNewCol(DEFAULT_QUERY_COLS);
    1630           0 :         OSL_VERIFY(FindFirstFreeCol(_rColumnPosition).is());
    1631             :     }
    1632           0 : }
    1633             : 
    1634           0 : void OSelectionBrowseBox::AddGroupBy( const OTableFieldDescRef& rInfo , sal_uInt32 /*_nCurrentPos*/)
    1635             : {
    1636           0 :     Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
    1637           0 :     if(!xConnection.is())
    1638           0 :         return;
    1639             :     OSL_ENSURE(!rInfo->IsEmpty(),"AddGroupBy:: OTableFieldDescRef sollte nicht Empty sein!");
    1640           0 :     OTableFieldDescRef pEntry;
    1641           0 :     const Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
    1642           0 :     const ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
    1643             :     //sal_Bool bAppend = sal_False;
    1644             : 
    1645           0 :     OTableFields& rFields = getFields();
    1646           0 :     OTableFields::iterator aIter = rFields.begin();
    1647           0 :     OTableFields::iterator aEnd = rFields.end();
    1648           0 :     for(;aIter != aEnd;++aIter)
    1649             :     {
    1650           0 :         pEntry = *aIter;
    1651             :         OSL_ENSURE(pEntry.is(),"OTableFieldDescRef was null!");
    1652             : 
    1653           0 :         const OUString   aField = pEntry->GetField();
    1654           0 :         const OUString   aAlias = pEntry->GetAlias();
    1655             : 
    1656           0 :         if (bCase(aField,rInfo->GetField()) &&
    1657           0 :             bCase(aAlias,rInfo->GetAlias()) &&
    1658           0 :             pEntry->GetFunctionType() == rInfo->GetFunctionType() &&
    1659           0 :             pEntry->GetFunction() == rInfo->GetFunction())
    1660             :         {
    1661           0 :             if ( pEntry->isNumericOrAggreateFunction() && rInfo->IsGroupBy() )
    1662             :             {
    1663           0 :                 pEntry->SetGroupBy(false);
    1664           0 :                 aIter = rFields.end();
    1665           0 :                 break;
    1666             :             }
    1667             :             else
    1668             :             {
    1669           0 :                 if ( !pEntry->IsGroupBy() && !pEntry->HasCriteria() ) // here we have a where condition which is no having clause
    1670             :                 {
    1671           0 :                     pEntry->SetGroupBy(rInfo->IsGroupBy());
    1672           0 :                     if(!m_bGroupByUnRelated && pEntry->IsGroupBy())
    1673           0 :                         pEntry->SetVisible(true);
    1674           0 :                     break;
    1675             :                 }
    1676             :             }
    1677             : 
    1678             :         }
    1679           0 :     }
    1680             : 
    1681           0 :     if (aIter == rFields.end())
    1682             :     {
    1683           0 :         OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, false, false );
    1684           0 :         if ( (pTmp->isNumericOrAggreateFunction() && rInfo->IsGroupBy()) ) // the GroupBy is inherited from rInfo
    1685           0 :             pTmp->SetGroupBy(false);
    1686           0 :     }
    1687             : }
    1688             : 
    1689           0 : void OSelectionBrowseBox::DuplicateConditionLevel( const sal_uInt16 nLevel)
    1690             : {
    1691           0 :     const sal_uInt16 nNewLevel = nLevel +1;
    1692           0 :     OTableFields& rFields = getFields();
    1693           0 :     OTableFields::iterator aIter = rFields.begin();
    1694           0 :     OTableFields::iterator aEnd = rFields.end();
    1695           0 :     for(;aIter != aEnd;++aIter)
    1696             :     {
    1697           0 :         OTableFieldDescRef pEntry = *aIter;
    1698             : 
    1699           0 :         OUString sValue = pEntry->GetCriteria(nLevel);
    1700           0 :         if ( !sValue.isEmpty() )
    1701             :         {
    1702           0 :             pEntry->SetCriteria( nNewLevel, sValue);
    1703           0 :             if ( nNewLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1) )
    1704             :             {
    1705           0 :                 RowInserted( GetRowCount()-1, 1, true );
    1706           0 :                 m_bVisibleRow.push_back(true);
    1707           0 :                 ++m_nVisibleCount;
    1708             :             }
    1709           0 :             m_bVisibleRow[BROW_CRIT1_ROW + nNewLevel] = true;
    1710             :         }
    1711           0 :     }
    1712           0 : }
    1713             : 
    1714           0 : void OSelectionBrowseBox::AddCondition( const OTableFieldDescRef& rInfo, const OUString& rValue, const sal_uInt16 nLevel,bool _bAddOrOnOneLine )
    1715             : {
    1716           0 :     Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
    1717           0 :     if(!xConnection.is())
    1718           0 :         return;
    1719             :     OSL_ENSURE(rInfo.is() && !rInfo->IsEmpty(),"AddCondition:: OTableFieldDescRef sollte nicht Empty sein!");
    1720             : 
    1721           0 :     OTableFieldDescRef pLastEntry;
    1722           0 :     Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
    1723           0 :     ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
    1724             : 
    1725           0 :     OTableFields& rFields = getFields();
    1726           0 :     OTableFields::iterator aIter = rFields.begin();
    1727           0 :     OTableFields::iterator aEnd = rFields.end();
    1728           0 :     for(;aIter != aEnd;++aIter)
    1729             :     {
    1730           0 :         OTableFieldDescRef pEntry = *aIter;
    1731           0 :         const OUString   aField = pEntry->GetField();
    1732           0 :         const OUString   aAlias = pEntry->GetAlias();
    1733             : 
    1734           0 :         if (bCase(aField,rInfo->GetField()) &&
    1735           0 :             bCase(aAlias,rInfo->GetAlias()) &&
    1736           0 :             pEntry->GetFunctionType() == rInfo->GetFunctionType() &&
    1737           0 :             pEntry->GetFunction() == rInfo->GetFunction() &&
    1738           0 :             pEntry->IsGroupBy() == rInfo->IsGroupBy() )
    1739             :         {
    1740           0 :             if ( pEntry->isNumericOrAggreateFunction() && rInfo->IsGroupBy() )
    1741           0 :                 pEntry->SetGroupBy(false);
    1742             :             else
    1743             :             {
    1744           0 :                 if(!m_bGroupByUnRelated && pEntry->IsGroupBy())
    1745           0 :                     pEntry->SetVisible(true);
    1746             :             }
    1747           0 :             if (pEntry->GetCriteria(nLevel).isEmpty() )
    1748             :             {
    1749           0 :                 pEntry->SetCriteria( nLevel, rValue);
    1750           0 :                 if(nLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1))
    1751             :                 {
    1752           0 :                     RowInserted( GetRowCount()-1, 1, true );
    1753           0 :                     m_bVisibleRow.push_back(true);
    1754           0 :                     ++m_nVisibleCount;
    1755             :                 }
    1756           0 :                 m_bVisibleRow[BROW_CRIT1_ROW + nLevel] = true;
    1757           0 :                 break;
    1758             :             }
    1759           0 :             if ( _bAddOrOnOneLine )
    1760             :             {
    1761           0 :                 pLastEntry = pEntry;
    1762             :             }
    1763             :         }
    1764           0 :     }
    1765           0 :     if ( pLastEntry.is() )
    1766             :     {
    1767           0 :         OUString sCriteria = rValue;
    1768           0 :         OUString sOldCriteria = pLastEntry->GetCriteria( nLevel );
    1769           0 :         if ( !sOldCriteria.isEmpty() )
    1770             :         {
    1771           0 :             sCriteria = "( ";
    1772           0 :             sCriteria += sOldCriteria;
    1773           0 :             sCriteria += " OR ";
    1774           0 :             sCriteria += rValue;
    1775           0 :             sCriteria += " )";
    1776             :         }
    1777           0 :         pLastEntry->SetCriteria( nLevel, sCriteria);
    1778           0 :         if(nLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1))
    1779             :         {
    1780           0 :             RowInserted( GetRowCount()-1, 1, true );
    1781           0 :             m_bVisibleRow.push_back(true);
    1782           0 :             ++m_nVisibleCount;
    1783             :         }
    1784           0 :         m_bVisibleRow[BROW_CRIT1_ROW + nLevel] = true;
    1785             :     }
    1786           0 :     else if (aIter == rFields.end())
    1787             :     {
    1788           0 :         OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, false, false );
    1789           0 :         if ( pTmp->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) // the GroupBy was inherited from rInfo
    1790           0 :             pTmp->SetGroupBy(false);
    1791           0 :         if ( pTmp.is() )
    1792             :         {
    1793           0 :             pTmp->SetCriteria( nLevel, rValue);
    1794           0 :             if(nLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1))
    1795             :             {
    1796           0 :                 RowInserted( GetRowCount()-1, 1, true );
    1797           0 :                 m_bVisibleRow.push_back(true);
    1798           0 :                 ++m_nVisibleCount;
    1799             :             }
    1800           0 :         }
    1801           0 :     }
    1802             : }
    1803             : 
    1804           0 : void OSelectionBrowseBox::AddOrder( const OTableFieldDescRef& rInfo, const EOrderDir eDir, sal_uInt32 _nCurrentPos)
    1805             : {
    1806           0 :     if (_nCurrentPos == 0)
    1807           0 :         m_nLastSortColumn = SORT_COLUMN_NONE;
    1808             : 
    1809           0 :     Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
    1810           0 :     if(!xConnection.is())
    1811           0 :         return;
    1812             :     OSL_ENSURE(!rInfo->IsEmpty(),"AddOrder:: OTableFieldDescRef should not be Empty!");
    1813           0 :     OTableFieldDescRef pEntry;
    1814           0 :     Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
    1815           0 :     ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
    1816             : 
    1817           0 :     bool bAppend = false;
    1818           0 :     OTableFields& rFields = getFields();
    1819           0 :     OTableFields::iterator aIter = rFields.begin();
    1820           0 :     OTableFields::iterator aEnd = rFields.end();
    1821           0 :     for(;aIter != aEnd;++aIter)
    1822             :     {
    1823           0 :         pEntry = *aIter;
    1824           0 :         OUString aField = pEntry->GetField();
    1825           0 :         OUString aAlias = pEntry->GetAlias();
    1826             : 
    1827           0 :         if (bCase(aField,rInfo->GetField()) &&
    1828           0 :             bCase(aAlias,rInfo->GetAlias()))
    1829             :         {
    1830           0 :             sal_uInt32 nPos = aIter - rFields.begin();
    1831           0 :             bAppend = (m_nLastSortColumn != SORT_COLUMN_NONE) && (nPos <= m_nLastSortColumn);
    1832           0 :             if ( bAppend )
    1833           0 :                 aIter = rFields.end();
    1834             :             else
    1835             :             {
    1836           0 :                 if ( !m_bOrderByUnRelated )
    1837           0 :                     pEntry->SetVisible(true);
    1838           0 :                 pEntry->SetOrderDir( eDir );
    1839           0 :                 m_nLastSortColumn = nPos;
    1840             :             }
    1841           0 :             break;
    1842             :         }
    1843           0 :     }
    1844             : 
    1845           0 :     if (aIter == rFields.end())
    1846             :     {
    1847           0 :         OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, false, false );
    1848           0 :         if(pTmp.is())
    1849             :         {
    1850           0 :             m_nLastSortColumn = pTmp->GetColumnId() - 1;
    1851           0 :             if ( !m_bOrderByUnRelated && !bAppend )
    1852           0 :                 pTmp->SetVisible(true);
    1853           0 :             pTmp->SetOrderDir( eDir );
    1854           0 :         }
    1855           0 :     }
    1856             : }
    1857             : 
    1858           0 : void OSelectionBrowseBox::ArrangeControls(sal_uInt16& nX, sal_uInt16 nY)
    1859             : {
    1860           0 :     EditBrowseBox::ArrangeControls(nX, nY);
    1861           0 : }
    1862             : 
    1863           0 : bool OSelectionBrowseBox::Save()
    1864             : {
    1865           0 :     bool bRet = true;
    1866           0 :     if (IsModified())
    1867           0 :         bRet = SaveModified();
    1868           0 :     return bRet;
    1869             : }
    1870             : 
    1871           0 : void OSelectionBrowseBox::CellModified()
    1872             : {
    1873           0 :     long nRow = GetRealRow(GetCurRow());
    1874           0 :     switch (nRow)
    1875             :     {
    1876             :         case BROW_VIS_ROW:
    1877             :             {
    1878           0 :                 OTableFieldDescRef  pEntry = getEntry(GetColumnPos(GetCurColumnId()) - 1);
    1879             : 
    1880           0 :                 sal_Int32 nIdx = m_pOrderCell->GetSelectEntryPos();
    1881           0 :                 if(!m_bOrderByUnRelated && nIdx > 0 &&
    1882           0 :                     nIdx != LISTBOX_ENTRY_NOTFOUND  &&
    1883           0 :                     !pEntry->IsEmpty()              &&
    1884           0 :                     pEntry->GetOrderDir() != ORDER_NONE)
    1885             :                 {
    1886           0 :                     m_pVisibleCell->GetBox().Check();
    1887           0 :                     pEntry->SetVisible(true);
    1888             :                 }
    1889             :                 else
    1890           0 :                     pEntry->SetVisible(m_pVisibleCell->GetBox().IsChecked());
    1891             :             }
    1892           0 :             break;
    1893             :     }
    1894           0 :     static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True );
    1895           0 : }
    1896             : 
    1897           0 : void OSelectionBrowseBox::Fill()
    1898             : {
    1899             :     OSL_ENSURE(ColCount() >= 1, "OSelectionBrowseBox::Fill : please call only after inserting the handle column !");
    1900             : 
    1901           0 :     sal_uInt16 nColCount = ColCount() - 1;
    1902           0 :     if (nColCount < DEFAULT_QUERY_COLS)
    1903           0 :         AppendNewCol(DEFAULT_QUERY_COLS - nColCount);
    1904           0 : }
    1905             : 
    1906           0 : Size OSelectionBrowseBox::CalcOptimalSize( const Size& _rAvailable )
    1907             : {
    1908           0 :     Size aReturn( _rAvailable.Width(), GetTitleHeight() );
    1909             : 
    1910           0 :     aReturn.Height() += ( m_nVisibleCount ? m_nVisibleCount : 15 ) * GetDataRowHeight();
    1911           0 :     aReturn.Height() += 40; // just some space
    1912             : 
    1913           0 :     return aReturn;
    1914             : }
    1915             : 
    1916           0 : void OSelectionBrowseBox::Command(const CommandEvent& rEvt)
    1917             : {
    1918           0 :     switch (rEvt.GetCommand())
    1919             :     {
    1920             :         case CommandEventId::ContextMenu:
    1921             :         {
    1922           0 :             Point aMenuPos( rEvt.GetMousePosPixel() );
    1923             : 
    1924           0 :             if (!rEvt.IsMouseEvent())
    1925             :             {
    1926           0 :                 if  ( 1 == GetSelectColumnCount() )
    1927             :                 {
    1928             :                     sal_uInt16 nSelId = GetColumnId(
    1929             :                         sal::static_int_cast< sal_uInt16 >(
    1930           0 :                             FirstSelectedColumn() ) );
    1931           0 :                     ::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, false ) );
    1932             : 
    1933           0 :                     aMenuPos = aColRect.TopCenter();
    1934             :                 }
    1935             :                 else
    1936             :                 {
    1937           0 :                     EditBrowseBox::Command(rEvt);
    1938           0 :                     return;
    1939             :                 }
    1940             :             }
    1941             : 
    1942           0 :             sal_uInt16 nColId = GetColumnId(GetColumnAtXPosPixel( aMenuPos.X() ));
    1943           0 :             long   nRow = GetRowAtYPosPixel( aMenuPos.Y() );
    1944             : 
    1945           0 :             if (nRow < 0 && nColId > HANDLE_ID )
    1946             :             {
    1947           0 :                 if ( !IsColumnSelected( nColId ) )
    1948             :                 {
    1949           0 :                     adjustSelectionMode( true /* clicked onto a header */ , false /* not onto the handle col */ );
    1950           0 :                     SelectColumnId( nColId );
    1951             :                 }
    1952             : 
    1953           0 :                 if (!static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
    1954             :                 {
    1955           0 :                     PopupMenu aContextMenu( ModuleRes( RID_QUERYCOLPOPUPMENU ) );
    1956           0 :                     switch (aContextMenu.Execute(this, aMenuPos))
    1957             :                     {
    1958             :                         case SID_DELETE:
    1959           0 :                             RemoveField(nColId);
    1960           0 :                             break;
    1961             : 
    1962             :                         case ID_BROWSER_COLWIDTH:
    1963           0 :                             adjustBrowseBoxColumnWidth( this, nColId );
    1964           0 :                             break;
    1965           0 :                     }
    1966           0 :                 }
    1967             :             }
    1968           0 :             else if(nRow >= 0 && nColId <= HANDLE_ID)
    1969             :             {
    1970           0 :                 if (!static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
    1971             :                 {
    1972           0 :                     PopupMenu aContextMenu(ModuleRes(RID_QUERYFUNCTION_POPUPMENU));
    1973           0 :                     aContextMenu.CheckItem( ID_QUERY_FUNCTION, m_bVisibleRow[BROW_FUNCTION_ROW]);
    1974           0 :                     aContextMenu.CheckItem( ID_QUERY_TABLENAME, m_bVisibleRow[BROW_TABLE_ROW]);
    1975           0 :                     aContextMenu.CheckItem( ID_QUERY_ALIASNAME, m_bVisibleRow[BROW_COLUMNALIAS_ROW]);
    1976           0 :                     aContextMenu.CheckItem( ID_QUERY_DISTINCT, static_cast<OQueryController&>(getDesignView()->getController()).isDistinct());
    1977             : 
    1978           0 :                     switch (aContextMenu.Execute(this, aMenuPos))
    1979             :                     {
    1980             :                         case ID_QUERY_FUNCTION:
    1981           0 :                             SetRowVisible(BROW_FUNCTION_ROW, !IsRowVisible(BROW_FUNCTION_ROW));
    1982           0 :                             static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_VIEW_FUNCTIONS );
    1983           0 :                             break;
    1984             :                         case ID_QUERY_TABLENAME:
    1985           0 :                             SetRowVisible(BROW_TABLE_ROW, !IsRowVisible(BROW_TABLE_ROW));
    1986           0 :                             static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_VIEW_TABLES );
    1987           0 :                             break;
    1988             :                         case ID_QUERY_ALIASNAME:
    1989           0 :                             SetRowVisible(BROW_COLUMNALIAS_ROW, !IsRowVisible(BROW_COLUMNALIAS_ROW));
    1990           0 :                             static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_VIEW_ALIASES );
    1991           0 :                             break;
    1992             :                         case ID_QUERY_DISTINCT:
    1993           0 :                             static_cast<OQueryController&>(getDesignView()->getController()).setDistinct(!static_cast<OQueryController&>(getDesignView()->getController()).isDistinct());
    1994           0 :                             static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True );
    1995           0 :                             static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_DISTINCT_VALUES );
    1996           0 :                             break;
    1997             :                     }
    1998             : 
    1999           0 :                     static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True );
    2000           0 :                 }
    2001             :             }
    2002             :             else
    2003             :             {
    2004           0 :                 EditBrowseBox::Command(rEvt);
    2005           0 :                 return;
    2006             :             }
    2007             :         }
    2008             :         //fall-through
    2009             :         default:
    2010           0 :             EditBrowseBox::Command(rEvt);
    2011             :     }
    2012             : }
    2013             : 
    2014           0 : bool OSelectionBrowseBox::IsRowVisible(sal_uInt16 _nWhich) const
    2015             : {
    2016             :     OSL_ENSURE(_nWhich<(m_bVisibleRow.size()), "OSelectionBrowseBox::IsRowVisible : invalid parameter !");
    2017           0 :     return m_bVisibleRow[_nWhich];
    2018             : }
    2019             : 
    2020           0 : void OSelectionBrowseBox::SetRowVisible(sal_uInt16 _nWhich, bool _bVis)
    2021             : {
    2022             :     OSL_ENSURE(_nWhich<m_bVisibleRow.size(), "OSelectionBrowseBox::SetRowVisible : invalid parameter !");
    2023             : 
    2024           0 :     bool bWasEditing = IsEditing();
    2025           0 :     if (bWasEditing)
    2026           0 :         DeactivateCell();
    2027             : 
    2028             :     // do this before removing or inserting rows, as this triggers ActivateCell-calls, which rely on m_bVisibleRow
    2029           0 :     m_bVisibleRow[_nWhich] = !m_bVisibleRow[_nWhich];
    2030             : 
    2031           0 :     long nId = GetBrowseRow(_nWhich);
    2032           0 :     if (_bVis)
    2033             :     {
    2034           0 :         RowInserted(nId,1);
    2035           0 :         ++m_nVisibleCount;
    2036             :     }
    2037             :     else
    2038             :     {
    2039           0 :         RowRemoved(nId,1);
    2040           0 :         --m_nVisibleCount;
    2041             :     }
    2042             : 
    2043           0 :     if (bWasEditing)
    2044           0 :         ActivateCell();
    2045           0 : }
    2046             : 
    2047           0 : long OSelectionBrowseBox::GetBrowseRow(long nRowId) const
    2048             : {
    2049           0 :     sal_uInt16 nCount(0);
    2050           0 :     for(long i = 0 ; i < nRowId ; ++i)
    2051             :     {
    2052           0 :         if ( m_bVisibleRow[i] )
    2053           0 :             ++nCount;
    2054             :     }
    2055           0 :     return nCount;
    2056             : }
    2057             : 
    2058           0 : long OSelectionBrowseBox::GetRealRow(long nRowId) const
    2059             : {
    2060           0 :     long nErg=0,i;
    2061           0 :     const long nCount = m_bVisibleRow.size();
    2062           0 :     for(i=0;i < nCount; ++i)
    2063             :     {
    2064           0 :         if(m_bVisibleRow[i])
    2065             :         {
    2066           0 :             if(nErg++ == nRowId)
    2067           0 :                 break;
    2068             :         }
    2069             :     }
    2070             :     OSL_ENSURE(nErg <= long(m_bVisibleRow.size()),"nErg kann nicht groesser als BROW_ROW_CNT sein!");
    2071           0 :     return i;
    2072             : }
    2073             : 
    2074             : static const long nVisibleRowMask[] =
    2075             :                     {
    2076             :                             0x0001,
    2077             :                             0x0002,
    2078             :                             0x0004,
    2079             :                             0x0008,
    2080             :                             0x0010,
    2081             :                             0x0020,
    2082             :                             0x0040,
    2083             :                             0x0080,
    2084             :                             0x0100,
    2085             :                             0x0200,
    2086             :                             0x0400,
    2087             :                             0x0800
    2088             :                     };
    2089           0 : sal_Int32 OSelectionBrowseBox::GetNoneVisibleRows() const
    2090             : {
    2091           0 :     sal_Int32 nErg(0);
    2092             :     // only the first 11 row are interesting
    2093           0 :     sal_Int32 nSize = sizeof(nVisibleRowMask) / sizeof(nVisibleRowMask[0]);
    2094           0 :     for(sal_Int32 i=0;i<nSize;i++)
    2095             :     {
    2096           0 :         if(!m_bVisibleRow[i])
    2097           0 :             nErg |= nVisibleRowMask[i];
    2098             :     }
    2099           0 :     return nErg;
    2100             : }
    2101             : 
    2102           0 : void OSelectionBrowseBox::SetNoneVisbleRow(long nRows)
    2103             : {
    2104             :     // only the first 11 row are interesting
    2105           0 :     sal_Int32 nSize = sizeof(nVisibleRowMask) / sizeof(nVisibleRowMask[0]);
    2106           0 :     for(sal_Int32 i=0;i< nSize;i++)
    2107           0 :         m_bVisibleRow[i] = !(nRows & nVisibleRowMask[i]);
    2108           0 : }
    2109             : 
    2110           0 : OUString OSelectionBrowseBox::GetCellText(long nRow, sal_uInt16 nColId) const
    2111             : {
    2112             : 
    2113           0 :     sal_uInt16 nPos = GetColumnPos(nColId);
    2114             : 
    2115           0 :     OTableFieldDescRef pEntry = getFields()[nPos-1];
    2116             :     OSL_ENSURE(pEntry != NULL, "OSelectionBrowseBox::GetCellText : invalid column id, prepare for GPF ... ");
    2117           0 :     if ( pEntry->IsEmpty() )
    2118           0 :         return OUString();
    2119             : 
    2120           0 :     OUString aText;
    2121           0 :     switch (nRow)
    2122             :     {
    2123             :         case BROW_TABLE_ROW:
    2124           0 :             aText = pEntry->GetAlias();
    2125           0 :             break;
    2126             :         case BROW_FIELD_ROW:
    2127             :         {
    2128           0 :             OUString aField = pEntry->GetField();
    2129           0 :             if (!aField.isEmpty() && aField[0] == '*')                   // * durch alias.* ersetzen
    2130             :             {
    2131           0 :                 aField = pEntry->GetAlias();
    2132           0 :                 if(!aField.isEmpty())
    2133           0 :                     aField += ".";
    2134           0 :                 aField += "*";
    2135             :             }
    2136           0 :             aText = aField;
    2137           0 :         }   break;
    2138             :         case BROW_ORDER_ROW:
    2139           0 :             if (pEntry->GetOrderDir() != ORDER_NONE)
    2140           0 :                 aText = OUString(ModuleRes(STR_QUERY_SORTTEXT)).getToken(sal::static_int_cast< sal_uInt16 >(pEntry->GetOrderDir()), ';');
    2141           0 :             break;
    2142             :         case BROW_VIS_ROW:
    2143           0 :             break;
    2144             :         case BROW_COLUMNALIAS_ROW:
    2145           0 :             aText = pEntry->GetFieldAlias();
    2146           0 :             break;
    2147             :         case BROW_FUNCTION_ROW:
    2148             :             // we always show the group function at first
    2149           0 :             if ( pEntry->IsGroupBy() )
    2150           0 :                 aText = m_aFunctionStrings.getToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1, ';');
    2151           0 :             else if ( pEntry->isNumericOrAggreateFunction() )
    2152           0 :                 aText = pEntry->GetFunction();
    2153           0 :             break;
    2154             :         default:
    2155           0 :             aText = pEntry->GetCriteria(sal_uInt16(nRow - BROW_CRIT1_ROW));
    2156             :     }
    2157           0 :     return aText;
    2158             : }
    2159             : 
    2160           0 : bool OSelectionBrowseBox::GetFunctionName(sal_uInt32 _nFunctionTokenId, OUString& rFkt)
    2161             : {
    2162           0 :     bool bErg=true;
    2163           0 :     switch(_nFunctionTokenId)
    2164             :     {
    2165             :         case SQL_TOKEN_COUNT:
    2166           0 :             rFkt = (m_pFunctionCell->GetEntryCount() < 3) ? m_pFunctionCell->GetEntry(1) : m_pFunctionCell->GetEntry(2);
    2167           0 :             break;
    2168             :         case SQL_TOKEN_AVG:
    2169           0 :             rFkt = m_pFunctionCell->GetEntry(1);
    2170           0 :             break;
    2171             :         case SQL_TOKEN_MAX:
    2172           0 :             rFkt = m_pFunctionCell->GetEntry(3);
    2173           0 :             break;
    2174             :         case SQL_TOKEN_MIN:
    2175           0 :             rFkt = m_pFunctionCell->GetEntry(4);
    2176           0 :             break;
    2177             :         case SQL_TOKEN_SUM:
    2178           0 :             rFkt = m_pFunctionCell->GetEntry(5);
    2179           0 :             break;
    2180             :         case SQL_TOKEN_EVERY:
    2181           0 :             rFkt = m_pFunctionCell->GetEntry(6);
    2182           0 :             break;
    2183             :         case SQL_TOKEN_ANY:
    2184           0 :             rFkt = m_pFunctionCell->GetEntry(7);
    2185           0 :             break;
    2186             :         case SQL_TOKEN_SOME:
    2187           0 :             rFkt = m_pFunctionCell->GetEntry(8);
    2188           0 :             break;
    2189             :         case SQL_TOKEN_STDDEV_POP:
    2190           0 :             rFkt = m_pFunctionCell->GetEntry(9);
    2191           0 :             break;
    2192             :         case SQL_TOKEN_STDDEV_SAMP:
    2193           0 :             rFkt = m_pFunctionCell->GetEntry(10);
    2194           0 :             break;
    2195             :         case SQL_TOKEN_VAR_SAMP:
    2196           0 :             rFkt = m_pFunctionCell->GetEntry(11);
    2197           0 :             break;
    2198             :         case SQL_TOKEN_VAR_POP:
    2199           0 :             rFkt = m_pFunctionCell->GetEntry(12);
    2200           0 :             break;
    2201             :         case SQL_TOKEN_COLLECT:
    2202           0 :             rFkt = m_pFunctionCell->GetEntry(13);
    2203           0 :             break;
    2204             :         case SQL_TOKEN_FUSION:
    2205           0 :             rFkt = m_pFunctionCell->GetEntry(14);
    2206           0 :             break;
    2207             :         case SQL_TOKEN_INTERSECTION:
    2208           0 :             rFkt = m_pFunctionCell->GetEntry(15);
    2209           0 :             break;
    2210             :         default:
    2211             :             {
    2212           0 :                 sal_Int32 nCount = comphelper::string::getTokenCount(m_aFunctionStrings, ';');
    2213             :                 sal_Int32 i;
    2214           0 :                 for( i = 0; i < nCount-1; i++ ) // grouping is not counted
    2215             :                 {
    2216           0 :                     if(rFkt.equalsIgnoreAsciiCase(m_aFunctionStrings.getToken(i, ';')))
    2217             :                     {
    2218           0 :                         rFkt = m_aFunctionStrings.getToken(i, ';');
    2219           0 :                         break;
    2220             :                     }
    2221             :                 }
    2222           0 :                 if(i == nCount-1)
    2223           0 :                     bErg = false;
    2224             :             }
    2225             :     }
    2226             : 
    2227           0 :     return bErg;
    2228             : }
    2229             : 
    2230           0 : OUString OSelectionBrowseBox::GetCellContents(sal_Int32 nCellIndex, sal_uInt16 nColId)
    2231             : {
    2232           0 :     if ( GetCurColumnId() == nColId && !m_bInUndoMode )
    2233           0 :         SaveModified();
    2234             : 
    2235           0 :     sal_uInt16 nPos = GetColumnPos(nColId);
    2236           0 :     OTableFieldDescRef pEntry = getFields()[nPos - 1];
    2237             :     OSL_ENSURE(pEntry != NULL, "OSelectionBrowseBox::GetCellContents : invalid column id, prepare for GPF ... ");
    2238             : 
    2239           0 :     switch (nCellIndex)
    2240             :     {
    2241             :         case BROW_VIS_ROW :
    2242           0 :             return pEntry->IsVisible() ? OUStringLiteral("1") : OUStringLiteral("0");
    2243             :         case BROW_ORDER_ROW:
    2244             :         {
    2245           0 :             sal_Int32 nIdx = m_pOrderCell->GetSelectEntryPos();
    2246           0 :             if (nIdx == LISTBOX_ENTRY_NOTFOUND)
    2247           0 :                 nIdx = 0;
    2248           0 :             return OUString(nIdx);
    2249             :         }
    2250             :         default:
    2251           0 :             return GetCellText(nCellIndex, nColId);
    2252           0 :     }
    2253             : }
    2254             : 
    2255           0 : void OSelectionBrowseBox::SetCellContents(sal_Int32 nRow, sal_uInt16 nColId, const OUString& strNewText)
    2256             : {
    2257           0 :     bool bWasEditing = IsEditing() && (GetCurColumnId() == nColId) && IsRowVisible(static_cast<sal_uInt16>(nRow)) && (GetCurRow() == static_cast<sal_uInt16>(GetBrowseRow(nRow)));
    2258           0 :     if (bWasEditing)
    2259           0 :         DeactivateCell();
    2260             : 
    2261           0 :     sal_uInt16 nPos = GetColumnPos(nColId);
    2262           0 :     OTableFieldDescRef pEntry = getEntry(nPos - 1);
    2263             :     OSL_ENSURE(pEntry != NULL, "OSelectionBrowseBox::SetCellContents : invalid column id, prepare for GPF ... ");
    2264             : 
    2265           0 :     switch (nRow)
    2266             :     {
    2267             :         case BROW_VIS_ROW:
    2268           0 :             pEntry->SetVisible(strNewText == "1");
    2269           0 :             break;
    2270             :         case BROW_FIELD_ROW:
    2271           0 :             pEntry->SetField(strNewText);
    2272           0 :             break;
    2273             :         case BROW_TABLE_ROW:
    2274           0 :             pEntry->SetAlias(strNewText);
    2275           0 :             break;
    2276             :         case BROW_ORDER_ROW:
    2277             :         {
    2278           0 :             sal_uInt16 nIdx = (sal_uInt16)strNewText.toInt32();
    2279           0 :             pEntry->SetOrderDir(EOrderDir(nIdx));
    2280           0 :         }   break;
    2281             :         case BROW_COLUMNALIAS_ROW:
    2282           0 :             pEntry->SetFieldAlias(strNewText);
    2283           0 :             break;
    2284             :         case BROW_FUNCTION_ROW:
    2285             :         {
    2286           0 :             OUString sGroupFunctionName = m_aFunctionStrings.getToken(comphelper::string::getTokenCount(m_aFunctionStrings, ';')-1, ';');
    2287           0 :             pEntry->SetFunction(strNewText);
    2288             :             // first reset this two member
    2289           0 :             sal_Int32 nFunctionType = pEntry->GetFunctionType();
    2290           0 :             nFunctionType &= ~FKT_AGGREGATE;
    2291           0 :             pEntry->SetFunctionType(nFunctionType);
    2292           0 :             if ( pEntry->IsGroupBy() && !sGroupFunctionName.equalsIgnoreAsciiCase(strNewText) )
    2293           0 :                 pEntry->SetGroupBy(false);
    2294             : 
    2295           0 :             if ( sGroupFunctionName.equalsIgnoreAsciiCase(strNewText) )
    2296           0 :                 pEntry->SetGroupBy(true);
    2297           0 :             else if ( !strNewText.isEmpty() )
    2298             :             {
    2299           0 :                 nFunctionType |= FKT_AGGREGATE;
    2300           0 :                 pEntry->SetFunctionType(nFunctionType);
    2301           0 :             }
    2302           0 :         }   break;
    2303             :         default:
    2304           0 :             pEntry->SetCriteria(sal_uInt16(nRow - BROW_CRIT1_ROW), strNewText);
    2305             :     }
    2306             : 
    2307           0 :     long nCellIndex = GetRealRow(nRow);
    2308           0 :     if(IsRowVisible(static_cast<sal_uInt16>(nRow)))
    2309           0 :         RowModified(nCellIndex, nColId);
    2310             : 
    2311             :     // the appropriate field-description is now empty -> set Visible to sal_False (now it is consistent to normal empty rows)
    2312           0 :     if (pEntry->IsEmpty())
    2313           0 :         pEntry->SetVisible(false);
    2314             : 
    2315           0 :     if (bWasEditing)
    2316           0 :         ActivateCell(nCellIndex, nColId);
    2317             : 
    2318           0 :     static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True );
    2319           0 : }
    2320             : 
    2321           0 : sal_uInt32 OSelectionBrowseBox::GetTotalCellWidth(long nRow, sal_uInt16 nColId) const
    2322             : {
    2323             : 
    2324           0 :     long nRowId = GetRealRow(nRow);
    2325           0 :     if (nRowId == BROW_VIS_ROW)
    2326           0 :         return CHECKBOX_SIZE;
    2327             :     else
    2328           0 :         return  GetDataWindow().GetTextWidth(GetCellText(nRowId, nColId));
    2329             : }
    2330             : 
    2331           0 : void OSelectionBrowseBox::ColumnResized(sal_uInt16 nColId)
    2332             : {
    2333           0 :     if (static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
    2334           0 :         return;
    2335             :     // The resizing of columns can't be suppressed (BrowseBox doesn't support that) so we have to do this
    2336             :     // fake. It's not _that_ bad : the user may change column widths while in read-only mode to see all details
    2337             :     // but the changes aren't permanent ...
    2338             : 
    2339           0 :     sal_uInt16 nPos = GetColumnPos(nColId);
    2340             :     OSL_ENSURE(nPos <= getFields().size(),"ColumnResized:: nColId sollte nicht groesser als List::count sein!");
    2341           0 :     OTableFieldDescRef pEntry = getEntry(nPos-1);
    2342             :     OSL_ENSURE(pEntry.is(), "OSelectionBrowseBox::ColumnResized : keine FieldDescription !");
    2343           0 :     static_cast<OQueryController&>(getDesignView()->getController()).setModified( sal_True );
    2344           0 :     EditBrowseBox::ColumnResized(nColId);
    2345             : 
    2346           0 :     if ( pEntry.is())
    2347             :     {
    2348           0 :         if ( !m_bInUndoMode )
    2349             :         {
    2350             :             // create the undo action
    2351           0 :             OTabFieldSizedUndoAct* pUndo = new OTabFieldSizedUndoAct(this);
    2352           0 :             pUndo->SetColumnPosition( nPos );
    2353           0 :             pUndo->SetOriginalWidth(pEntry->GetColWidth());
    2354           0 :             getDesignView()->getController().addUndoActionAndInvalidate(pUndo);
    2355             :         }
    2356           0 :         pEntry->SetColWidth(sal_uInt16(GetColumnWidth(nColId)));
    2357           0 :     }
    2358             : }
    2359             : 
    2360           0 : sal_uInt32 OSelectionBrowseBox::GetTotalCellWidth(long nRowId, sal_uInt16 nColId)
    2361             : {
    2362           0 :     sal_uInt16 nPos = GetColumnPos(nColId);
    2363             :     OSL_ENSURE((nPos == 0) || (nPos <= getFields().size()), "OSelectionBrowseBox::GetTotalCellWidth : invalid parameter nColId");
    2364             : 
    2365           0 :     OTableFieldDescRef pEntry = getFields()[nPos-1];
    2366             :     OSL_ENSURE(pEntry.is(), "OSelectionBrowseBox::GetTotalCellWidth : invalid FieldDescription !");
    2367             : 
    2368           0 :     long nRow = GetRealRow(nRowId);
    2369           0 :     OUString strText(GetCellText(nRow, nColId));
    2370           0 :     return GetDataWindow().LogicToPixel(Size(GetDataWindow().GetTextWidth(strText),0)).Width();
    2371             : }
    2372             : 
    2373           0 : bool OSelectionBrowseBox::isCutAllowed()
    2374             : {
    2375           0 :     bool bCutAllowed = false;
    2376           0 :     long nRow = GetRealRow(GetCurRow());
    2377           0 :     switch (nRow)
    2378             :     {
    2379             :         case BROW_VIS_ROW:
    2380             :         case BROW_ORDER_ROW:
    2381             :         case BROW_TABLE_ROW:
    2382             :         case BROW_FUNCTION_ROW:
    2383           0 :             break;
    2384             :         case BROW_FIELD_ROW:
    2385           0 :             bCutAllowed = !m_pFieldCell->GetSelected().isEmpty();
    2386           0 :             break;
    2387             :         default:
    2388           0 :             bCutAllowed = !m_pTextCell->GetSelected().isEmpty();
    2389           0 :             break;
    2390             :     }
    2391           0 :     return bCutAllowed;
    2392             : }
    2393             : 
    2394           0 : void OSelectionBrowseBox::cut()
    2395             : {
    2396           0 :     long nRow = GetRealRow(GetCurRow());
    2397           0 :     switch (nRow)
    2398             :     {
    2399             :         case BROW_FIELD_ROW:
    2400           0 :             m_pFieldCell->Cut();
    2401           0 :             m_pFieldCell->SetModifyFlag();
    2402           0 :             break;
    2403             :         default:
    2404           0 :             m_pTextCell->Cut();
    2405           0 :             m_pTextCell->SetModifyFlag();
    2406             :     }
    2407           0 :     SaveModified();
    2408           0 :     RowModified(GetBrowseRow(nRow), GetCurColumnId());
    2409             : 
    2410           0 :     invalidateUndoRedo();
    2411           0 : }
    2412             : 
    2413           0 : void OSelectionBrowseBox::paste()
    2414             : {
    2415           0 :     long nRow = GetRealRow(GetCurRow());
    2416           0 :     switch (nRow)
    2417             :     {
    2418             :         case BROW_FIELD_ROW:
    2419           0 :             m_pFieldCell->Paste();
    2420           0 :             m_pFieldCell->SetModifyFlag();
    2421           0 :             break;
    2422             :         default:
    2423           0 :             m_pTextCell->Paste();
    2424           0 :             m_pTextCell->SetModifyFlag();
    2425             :     }
    2426           0 :     RowModified(GetBrowseRow(nRow), GetCurColumnId());
    2427           0 :     invalidateUndoRedo();
    2428           0 : }
    2429             : 
    2430           0 : bool OSelectionBrowseBox::isPasteAllowed()
    2431             : {
    2432           0 :     bool bPasteAllowed = true;
    2433           0 :     long nRow = GetRealRow(GetCurRow());
    2434           0 :     switch (nRow)
    2435             :     {
    2436             :         case BROW_VIS_ROW:
    2437             :         case BROW_ORDER_ROW:
    2438             :         case BROW_TABLE_ROW:
    2439             :         case BROW_FUNCTION_ROW:
    2440           0 :             bPasteAllowed = false;
    2441           0 :             break;
    2442             :     }
    2443           0 :     return bPasteAllowed;
    2444             : }
    2445             : 
    2446           0 : bool OSelectionBrowseBox::isCopyAllowed()
    2447             : {
    2448           0 :     return isCutAllowed();
    2449             : }
    2450             : 
    2451           0 : void OSelectionBrowseBox::copy()
    2452             : {
    2453           0 :     long nRow = GetRealRow(GetCurRow());
    2454           0 :     switch (nRow)
    2455             :     {
    2456             :         case BROW_FIELD_ROW:
    2457           0 :             m_pFieldCell->Copy();
    2458           0 :             break;
    2459             :         default:
    2460           0 :             m_pTextCell->Copy();
    2461             :     }
    2462           0 : }
    2463             : 
    2464           0 : void OSelectionBrowseBox::appendUndoAction(const OUString& _rOldValue, const OUString& _rNewValue, sal_Int32 _nRow, bool& _bListAction)
    2465             : {
    2466           0 :     if ( !m_bInUndoMode && _rNewValue != _rOldValue )
    2467             :     {
    2468           0 :         if ( !_bListAction )
    2469             :         {
    2470           0 :             _bListAction = true;
    2471           0 :             static_cast<OQueryController&>(getDesignView()->getController()).GetUndoManager().EnterListAction(OUString(),OUString());
    2472             :         }
    2473           0 :         appendUndoAction(_rOldValue,_rNewValue,_nRow);
    2474             :     }
    2475           0 : }
    2476             : 
    2477           0 : void OSelectionBrowseBox::appendUndoAction(const OUString& _rOldValue,const OUString& _rNewValue,sal_Int32 _nRow)
    2478             : {
    2479           0 :     if ( !m_bInUndoMode && _rNewValue != _rOldValue )
    2480             :     {
    2481           0 :         OTabFieldCellModifiedUndoAct* pUndoAct = new OTabFieldCellModifiedUndoAct(this);
    2482           0 :         pUndoAct->SetCellIndex(_nRow);
    2483             :         OSL_ENSURE(GetColumnPos(GetCurColumnId()) != BROWSER_INVALIDID,"Current position isn't valid!");
    2484           0 :         pUndoAct->SetColumnPosition( GetColumnPos(GetCurColumnId()) );
    2485           0 :         pUndoAct->SetCellContents(_rOldValue);
    2486           0 :         getDesignView()->getController().addUndoActionAndInvalidate(pUndoAct);
    2487             :     }
    2488           0 : }
    2489             : 
    2490           0 : IMPL_LINK_NOARG_TYPED(OSelectionBrowseBox, OnInvalidateTimer, Timer *, void)
    2491             : {
    2492           0 :     static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature(SID_CUT);
    2493           0 :     static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature(SID_COPY);
    2494           0 :     static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature(SID_PASTE);
    2495           0 :     if(!m_bStopTimer)
    2496           0 :         m_timerInvalidate.Start();
    2497           0 : }
    2498             : 
    2499           0 : void OSelectionBrowseBox::stopTimer()
    2500             : {
    2501           0 :     m_bStopTimer = true;
    2502           0 :     if (m_timerInvalidate.IsActive())
    2503           0 :         m_timerInvalidate.Stop();
    2504           0 : }
    2505             : 
    2506           0 : void OSelectionBrowseBox::startTimer()
    2507             : {
    2508           0 :     m_bStopTimer = false;
    2509           0 :     if (!m_timerInvalidate.IsActive())
    2510           0 :         m_timerInvalidate.Start();
    2511           0 : }
    2512             : 
    2513           0 : OTableFields& OSelectionBrowseBox::getFields() const
    2514             : {
    2515           0 :     OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
    2516           0 :     return rController.getTableFieldDesc();
    2517             : }
    2518             : 
    2519           0 : void OSelectionBrowseBox::enableControl(const OTableFieldDescRef& _rEntry,Window* _pControl)
    2520             : {
    2521           0 :     bool bEnable = !_rEntry->isCondition();
    2522           0 :     _pControl->Enable(bEnable);
    2523           0 :     _pControl->EnableInput(bEnable);
    2524           0 : }
    2525             : 
    2526           0 : void OSelectionBrowseBox::setTextCellContext(const OTableFieldDescRef& _rEntry,const OUString& _sText,const OString& _sHelpId)
    2527             : {
    2528           0 :     m_pTextCell->SetText(_sText);
    2529           0 :     m_pTextCell->ClearModifyFlag();
    2530           0 :     if (!m_pTextCell->HasFocus())
    2531           0 :         m_pTextCell->GrabFocus();
    2532             : 
    2533           0 :     enableControl(_rEntry,m_pTextCell);
    2534             : 
    2535           0 :     if (m_pTextCell->GetHelpId() != _sHelpId)
    2536             :         // as TextCell is used in various contexts I will delete the cached HelpText
    2537           0 :         m_pTextCell->SetHelpText(OUString());
    2538           0 :     m_pTextCell->SetHelpId(_sHelpId);
    2539           0 : }
    2540             : 
    2541           0 : void OSelectionBrowseBox::invalidateUndoRedo()
    2542             : {
    2543           0 :     OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
    2544           0 :     rController.InvalidateFeature( ID_BROWSER_UNDO );
    2545           0 :     rController.InvalidateFeature( ID_BROWSER_REDO );
    2546           0 :     rController.InvalidateFeature( ID_BROWSER_QUERY_EXECUTE );
    2547           0 : }
    2548             : 
    2549           0 : OTableFieldDescRef OSelectionBrowseBox::getEntry(OTableFields::size_type _nPos)
    2550             : {
    2551             :     // we have to check if we need a new entry at this position
    2552           0 :     OTableFields& aFields = getFields();
    2553             :     OSL_ENSURE(aFields.size() > _nPos,"ColID is to great!");
    2554             : 
    2555           0 :     OTableFieldDescRef pEntry = aFields[_nPos];
    2556             :     OSL_ENSURE(pEntry.is(),"Invalid entry!");
    2557           0 :     if ( !pEntry.is() )
    2558             :     {
    2559           0 :         pEntry = new OTableFieldDesc();
    2560             :         pEntry->SetColumnId(
    2561           0 :             GetColumnId(sal::static_int_cast< sal_uInt16 >(_nPos+1)));
    2562           0 :         aFields[_nPos] = pEntry;
    2563             :     }
    2564           0 :     return pEntry;
    2565             : }
    2566             : 
    2567           0 : void OSelectionBrowseBox::GetFocus()
    2568             : {
    2569           0 :     if(!IsEditing() && !m_bWasEditing)
    2570           0 :         ActivateCell();
    2571           0 :     EditBrowseBox::GetFocus();
    2572           0 : }
    2573             : 
    2574           0 : void OSelectionBrowseBox::DeactivateCell(bool _bUpdate)
    2575             : {
    2576           0 :     m_bWasEditing = true;
    2577           0 :     EditBrowseBox::DeactivateCell(_bUpdate);
    2578           0 :     m_bWasEditing = false;
    2579           0 : }
    2580             : 
    2581           0 : OUString OSelectionBrowseBox::GetRowDescription( sal_Int32 _nRow ) const
    2582             : {
    2583           0 :     OUString  aLabel(ModuleRes(STR_QUERY_HANDLETEXT));
    2584             : 
    2585             :     // from BROW_CRIT2_ROW onwards all rows are shown as "or"
    2586           0 :     sal_Int32 nToken = (_nRow >= GetBrowseRow(BROW_CRIT2_ROW))
    2587           0 :         ?  BROW_CRIT2_ROW : GetRealRow(_nRow);
    2588           0 :     return aLabel.getToken(nToken, ';');
    2589             : }
    2590             : 
    2591           0 : OUString OSelectionBrowseBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition) const
    2592             : {
    2593           0 :     OUString sRetText;
    2594           0 :     switch( _eObjType )
    2595             :     {
    2596             :         case ::svt::BBTYPE_ROWHEADERCELL:
    2597           0 :             sRetText = GetRowDescription(_nPosition);
    2598           0 :             break;
    2599             :         default:
    2600           0 :             sRetText = EditBrowseBox::GetAccessibleObjectDescription(_eObjType,_nPosition);
    2601             :     }
    2602           0 :     return sRetText;
    2603             : }
    2604             : 
    2605           0 : bool OSelectionBrowseBox::fillEntryTable(OTableFieldDescRef& _pEntry,const OUString& _sTableName)
    2606             : {
    2607           0 :     bool bRet = false;
    2608           0 :     OJoinTableView::OTableWindowMap& rTabWinList = getDesignView()->getTableView()->GetTabWinMap();
    2609           0 :     OJoinTableView::OTableWindowMap::iterator aIter = rTabWinList.find(_sTableName);
    2610           0 :     if(aIter != rTabWinList.end())
    2611             :     {
    2612           0 :         OQueryTableWindow* pEntryTab = static_cast<OQueryTableWindow*>(aIter->second.get());
    2613           0 :         if (pEntryTab)
    2614             :         {
    2615           0 :             _pEntry->SetTable(pEntryTab->GetTableName());
    2616           0 :             _pEntry->SetTabWindow(pEntryTab);
    2617           0 :             bRet = true;
    2618             :         }
    2619             :     }
    2620           0 :     return bRet;
    2621             : }
    2622             : 
    2623           0 : void OSelectionBrowseBox::setFunctionCell(OTableFieldDescRef& _pEntry)
    2624             : {
    2625           0 :     Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
    2626           0 :     if ( xConnection.is() )
    2627             :     {
    2628             :         // Aggregate functions in general only available with Core SQL
    2629           0 :         if ( lcl_SupportsCoreSQLGrammar(xConnection) )
    2630             :         {
    2631             :             // if we have an asterisk, no other function than count is allowed
    2632           0 :             m_pFunctionCell->Clear();
    2633           0 :             m_pFunctionCell->InsertEntry(m_aFunctionStrings.getToken(0, ';'));
    2634           0 :             if ( isFieldNameAsterisk(_pEntry->GetField()) )
    2635           0 :                 m_pFunctionCell->InsertEntry(m_aFunctionStrings.getToken(2, ';')); // 2 -> COUNT
    2636             :             else
    2637             :             {
    2638           0 :                 sal_Int32 nCount = comphelper::string::getTokenCount(m_aFunctionStrings, ';');
    2639           0 :                 if ( _pEntry->isNumeric() )
    2640           0 :                     --nCount;
    2641           0 :                 for( sal_Int32 nIdx = 1; nIdx < nCount; nIdx++ )
    2642           0 :                     m_pFunctionCell->InsertEntry(m_aFunctionStrings.getToken(nIdx, ';'));
    2643             :             }
    2644             : 
    2645           0 :             if ( _pEntry->IsGroupBy() )
    2646             :             {
    2647             :                 OSL_ENSURE(!_pEntry->isNumeric(),"Not allowed to combine group by and numeric values!");
    2648           0 :                 m_pFunctionCell->SelectEntry(m_pFunctionCell->GetEntry(m_pFunctionCell->GetEntryCount() - 1));
    2649             :             }
    2650           0 :             else if ( m_pFunctionCell->GetEntryPos(OUString(_pEntry->GetFunction())) != COMBOBOX_ENTRY_NOTFOUND )
    2651           0 :                 m_pFunctionCell->SelectEntry(OUString(_pEntry->GetFunction()));
    2652             :             else
    2653           0 :                 m_pFunctionCell->SelectEntryPos(0);
    2654             : 
    2655           0 :             enableControl(_pEntry,m_pFunctionCell);
    2656             :         }
    2657             :         else
    2658             :         {
    2659             :             // only COUNT(*) and COUNT("table".*) allowed
    2660           0 :             bool bCountRemoved = !isFieldNameAsterisk(_pEntry->GetField());
    2661           0 :             if ( bCountRemoved )
    2662           0 :                 m_pFunctionCell->RemoveEntry(1);
    2663             : 
    2664           0 :             if ( !bCountRemoved && m_pFunctionCell->GetEntryCount() < 2)
    2665           0 :                 m_pFunctionCell->InsertEntry(m_aFunctionStrings.getToken(2, ';')); // 2 -> COUNT
    2666             : 
    2667           0 :             if(m_pFunctionCell->GetEntryPos(OUString(_pEntry->GetFunction())) != COMBOBOX_ENTRY_NOTFOUND)
    2668           0 :                 m_pFunctionCell->SelectEntry(_pEntry->GetFunction());
    2669             :             else
    2670           0 :                 m_pFunctionCell->SelectEntryPos(0);
    2671             :         }
    2672           0 :     }
    2673           0 : }
    2674             : 
    2675           0 : Reference< XAccessible > OSelectionBrowseBox::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
    2676             : {
    2677           0 :     OTableFieldDescRef pEntry = NULL;
    2678           0 :     if(getFields().size() > sal_uInt16(_nColumnPos - 1))
    2679           0 :         pEntry = getFields()[_nColumnPos - 1];
    2680             : 
    2681           0 :     if ( _nRow == BROW_VIS_ROW && pEntry.is() )
    2682           0 :         return EditBrowseBox::CreateAccessibleCheckBoxCell( _nRow, _nColumnPos,pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE );
    2683             : 
    2684           0 :     return EditBrowseBox::CreateAccessibleCell( _nRow, _nColumnPos );
    2685             : }
    2686             : 
    2687           0 : bool OSelectionBrowseBox::HasFieldByAliasName(const OUString& rFieldName, OTableFieldDescRef& rInfo) const
    2688             : {
    2689           0 :     OTableFields& aFields = getFields();
    2690           0 :     OTableFields::iterator aIter = aFields.begin();
    2691           0 :     OTableFields::iterator aEnd  = aFields.end();
    2692             : 
    2693           0 :     for(;aIter != aEnd;++aIter)
    2694             :     {
    2695           0 :         if ( (*aIter)->GetFieldAlias() == rFieldName )
    2696             :         {
    2697           0 :             *rInfo = *(*aIter);
    2698           0 :             break;
    2699             :         }
    2700             :     }
    2701           0 :     return aIter != aEnd;
    2702          36 : }
    2703             : 
    2704             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11