LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - SelectionBrowseBox.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 1481 0.0 %
Date: 2014-04-14 Functions: 0 97 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10