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