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