update dev300-m58
[ooovba.git] / dbaccess / source / ui / querydesign / SelectionBrowseBox.cxx
blobc1f8f1649b30de945a50823cef11bf9881736d02
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SelectionBrowseBox.cxx,v $
10 * $Revision: 1.83 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_QUERYDESIGN_OSELECTIONBROWSEBOX_HXX
34 #include "SelectionBrowseBox.hxx"
35 #endif
36 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
37 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
40 #include <com/sun/star/sdbc/DataType.hpp>
41 #endif
42 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
43 #include "QueryDesignView.hxx"
44 #endif
45 #ifndef DBAUI_QUERYCONTROLLER_HXX
46 #include "querycontroller.hxx"
47 #endif
48 #ifndef DBAUI_QUERYTABLEVIEW_HXX
49 #include "QueryTableView.hxx"
50 #endif
51 #ifndef DBACCESS_UI_BROWSER_ID_HXX
52 #include "browserids.hxx"
53 #endif
54 #ifndef _COMPHELPER_TYPES_HXX_
55 #include <comphelper/types.hxx>
56 #endif
57 #ifndef DBAUI_TABLEFIELDINFO_HXX
58 #include "TableFieldInfo.hxx"
59 #endif
60 #ifndef _DBU_QRY_HRC_
61 #include "dbu_qry.hrc"
62 #endif
63 #ifndef _DBA_DBACCESS_HELPID_HRC_
64 #include "dbaccess_helpid.hrc"
65 #endif
66 #ifndef _TOOLS_DEBUG_HXX
67 #include <tools/debug.hxx>
68 #endif
69 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
70 #include <com/sun/star/container/XNameAccess.hpp>
71 #endif
72 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
73 #include "dbustrings.hrc"
74 #endif
75 #ifndef DBAUI_QUERY_TABLEWINDOW_HXX
76 #include "QTableWindow.hxx"
77 #endif
78 #ifndef DBAUI_QUERYTABLEVIEW_HXX
79 #include "QueryTableView.hxx"
80 #endif
81 #ifndef _SV_MSGBOX_HXX
82 #include <vcl/msgbox.hxx>
83 #endif
84 #ifndef DBAUI_QUERYDESIGNFIELDUNDOACT_HXX
85 #include "QueryDesignFieldUndoAct.hxx"
86 #endif
87 #ifndef _SVX_DBEXCH_HRC
88 #include <svx/dbexch.hrc>
89 #endif
90 #ifndef _COMPHELPER_STLTYPES_HXX_
91 #include <comphelper/stl_types.hxx>
92 #endif
93 #ifndef _COMPHELPER_EXTRACT_HXX_
94 #include <comphelper/extract.hxx>
95 #endif
96 #ifndef _DBAUI_SQLMESSAGE_HXX_
97 #include "sqlmessage.hxx"
98 #endif
99 #ifndef DBAUI_TOOLS_HXX
100 #include "UITools.hxx"
101 #endif
103 using namespace ::svt;
104 using namespace ::dbaui;
105 using namespace ::connectivity;
106 using namespace ::com::sun::star::uno;
107 using namespace ::com::sun::star::sdbc;
108 using namespace ::com::sun::star::beans;
109 using namespace ::com::sun::star::container;
110 using namespace ::com::sun::star::util;
111 using namespace ::com::sun::star::accessibility;
113 const String g_strOne = String::CreateFromAscii("1");
114 const String g_strZero = String::CreateFromAscii("0");
116 #define DEFAULT_QUERY_COLS 20
117 #define DEFAULT_SIZE GetTextWidth(g_strZero) * 30
118 #define CHECKBOX_SIZE 10
119 #define HANDLE_ID 0
120 #define HANDLE_COLUMN_WITDH 70
122 #define SQL_ISRULEOR2(pParseNode, e1,e2) ((pParseNode)->isRule() && (\
123 (pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e1) || \
124 (pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::e2)))
127 // -----------------------------------------------------------------------------
128 namespace
130 sal_Bool isFieldNameAsterix(const ::rtl::OUString& _sFieldName )
132 sal_Bool bAsterix = !(_sFieldName.getLength() && _sFieldName.toChar() != '*');
133 if ( !bAsterix )
135 String sName = _sFieldName;
136 xub_StrLen nTokenCount = sName.GetTokenCount('.');
137 if ( (nTokenCount == 2 && sName.GetToken(1,'.').GetChar(0) == '*' )
138 || (nTokenCount == 3 && sName.GetToken(2,'.').GetChar(0) == '*' ) )
140 bAsterix = sal_True;
143 return bAsterix;
145 // -----------------------------------------------------------------------------
146 sal_Bool lcl_SupportsCoreSQLGrammar(const Reference< XConnection>& _xConnection)
148 sal_Bool bSupportsCoreGrammar = sal_False;
149 if ( _xConnection.is() )
153 Reference< XDatabaseMetaData > xMetaData = _xConnection->getMetaData();
154 bSupportsCoreGrammar = xMetaData.is() && xMetaData->supportsCoreSQLGrammar();
156 catch(Exception&)
160 return bSupportsCoreGrammar;
164 DBG_NAME(OSelectionBrowseBox)
165 //------------------------------------------------------------------------------
166 OSelectionBrowseBox::OSelectionBrowseBox( Window* pParent )
167 :EditBrowseBox( pParent,EBBF_NOROWPICTURE, WB_3DLOOK, BROWSER_COLUMNSELECTION | BROWSER_KEEPSELECTION | BROWSER_HIDESELECT |
168 BROWSER_HIDECURSOR | BROWSER_HLINESFULL | BROWSER_VLINESFULL )
169 ,m_aFunctionStrings(ModuleRes(STR_QUERY_FUNCTIONS))
170 ,m_nVisibleCount(0)
171 ,m_bOrderByUnRelated(sal_True)
172 ,m_bGroupByUnRelated(sal_True)
173 ,m_bStopTimer(sal_False)
174 ,m_bWasEditing(sal_False)
175 ,m_bDisableErrorBox(sal_False)
176 ,m_bInUndoMode(sal_False)
178 DBG_CTOR(OSelectionBrowseBox,NULL);
179 SetHelpId(HID_CTL_QRYDGNCRIT);
181 m_nMode = BROWSER_COLUMNSELECTION | BROWSER_HIDESELECT
182 | BROWSER_KEEPSELECTION | BROWSER_HIDECURSOR
183 | BROWSER_HLINESFULL | BROWSER_VLINESFULL
184 | BROWSER_HEADERBAR_NEW ;
186 m_pTextCell = new Edit(&GetDataWindow(), 0);
187 // m_pTextCell->EnableSpecialCheck(sal_False);
188 m_pVisibleCell = new CheckBoxControl(&GetDataWindow());
189 m_pTableCell = new ListBoxControl(&GetDataWindow()); m_pTableCell->SetDropDownLineCount( 20 );
190 m_pFieldCell = new ComboBoxControl(&GetDataWindow()); m_pFieldCell->SetDropDownLineCount( 20 );
191 m_pOrderCell = new ListBoxControl(&GetDataWindow());
192 m_pFunctionCell = new ListBoxControl(&GetDataWindow()); m_pFunctionCell->SetDropDownLineCount( 20 );
194 m_pVisibleCell->SetHelpId(HID_QRYDGN_ROW_VISIBLE);
195 m_pTableCell->SetHelpId(HID_QRYDGN_ROW_TABLE);
196 m_pFieldCell->SetHelpId(HID_QRYDGN_ROW_FIELD);
197 m_pOrderCell->SetHelpId(HID_QRYDGN_ROW_ORDER);
198 m_pFunctionCell->SetHelpId(HID_QRYDGN_ROW_FUNCTION);
200 //////////////////////////////////////////////////////////////////////
201 // TriState der ::com::sun::star::form::CheckBox abschalten
202 m_pVisibleCell->GetBox().EnableTriState( sal_False );
204 // m_pEmptyEntry = new OTableFieldDesc();
205 // m_pEmptyEntry->SetColWidth(DEFAULT_SIZE);
207 Font aTitleFont = OutputDevice::GetDefaultFont( DEFAULTFONT_SANS_UNICODE,Window::GetSettings().GetLanguage(),DEFAULTFONT_FLAGS_ONLYONE);
208 aTitleFont.SetSize(Size(0, 6));
209 SetTitleFont(aTitleFont);
211 String aTxt(ModuleRes(STR_QUERY_SORTTEXT));
212 xub_StrLen nCount = aTxt.GetTokenCount();
213 xub_StrLen nIdx = 0;
214 for (; nIdx < nCount; nIdx++)
215 m_pOrderCell->InsertEntry(aTxt.GetToken(nIdx));
217 for(long i=0;i < BROW_ROW_CNT;i++)
218 m_bVisibleRow.push_back(sal_True);
220 m_bVisibleRow[BROW_FUNCTION_ROW] = sal_False; // zuerst ausblenden
222 m_timerInvalidate.SetTimeout(200);
223 m_timerInvalidate.SetTimeoutHdl(LINK(this, OSelectionBrowseBox, OnInvalidateTimer));
224 m_timerInvalidate.Start();
227 //------------------------------------------------------------------------------
228 OSelectionBrowseBox::~OSelectionBrowseBox()
230 DBG_DTOR(OSelectionBrowseBox,NULL);
232 delete m_pTextCell;
233 delete m_pVisibleCell;
234 delete m_pFieldCell;
235 delete m_pTableCell;
236 delete m_pOrderCell;
237 delete m_pFunctionCell;
239 // -----------------------------------------------------------------------------
240 void OSelectionBrowseBox::initialize()
242 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
243 if(xConnection.is())
245 const IParseContext& rContext = static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext();
246 IParseContext::InternationalKeyCode eFunctions[] = { IParseContext::KEY_AVG,IParseContext::KEY_COUNT,IParseContext::KEY_MAX
247 ,IParseContext::KEY_MIN,IParseContext::KEY_SUM
248 ,IParseContext::KEY_EVERY
249 ,IParseContext::KEY_ANY
250 ,IParseContext::KEY_SOME
251 ,IParseContext::KEY_STDDEV_POP
252 ,IParseContext::KEY_STDDEV_SAMP
253 ,IParseContext::KEY_VAR_SAMP
254 ,IParseContext::KEY_VAR_POP
255 ,IParseContext::KEY_COLLECT
256 ,IParseContext::KEY_FUSION
257 ,IParseContext::KEY_INTERSECTION
260 String sGroup = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount() - 1);
261 m_aFunctionStrings = m_aFunctionStrings.GetToken(0);
263 for (size_t i = 0; i < sizeof(eFunctions)/sizeof(eFunctions[0]) ; ++i)
265 m_aFunctionStrings += String(RTL_CONSTASCII_USTRINGPARAM(";"));
266 m_aFunctionStrings += String(ByteString(rContext.getIntlKeywordAscii(eFunctions[i])),RTL_TEXTENCODING_UTF8);
268 } // for (sal_Int32 i = 0; i < sizeof(eFunctions)/sizeof(eFunctions[0]) ; ++i)
269 m_aFunctionStrings += String(RTL_CONSTASCII_USTRINGPARAM(";"));
270 m_aFunctionStrings += sGroup;
272 // Diese Funktionen stehen nur unter CORE zur Verfügung
273 if ( lcl_SupportsCoreSQLGrammar(xConnection) )
275 xub_StrLen nCount = m_aFunctionStrings.GetTokenCount();
276 for (xub_StrLen nIdx = 0; nIdx < nCount; nIdx++)
277 m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(nIdx));
279 else // sonst nur COUNT(*)
281 m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(0));
282 m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(2)); // 2 -> COUNT
286 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
287 if ( xMetaData.is() )
289 m_bOrderByUnRelated = xMetaData->supportsOrderByUnrelated();
290 m_bGroupByUnRelated = xMetaData->supportsGroupByUnrelated();
293 catch(Exception&)
298 Init();
300 //==============================================================================
301 OQueryDesignView* OSelectionBrowseBox::getDesignView()
303 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
304 OSL_ENSURE(static_cast<const OQueryDesignView*>(GetParent()),"Parent isn't an OQueryDesignView!");
305 return static_cast<OQueryDesignView*>(GetParent());
307 // -----------------------------------------------------------------------------
308 OQueryDesignView* OSelectionBrowseBox::getDesignView() const
310 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
311 OSL_ENSURE(static_cast<const OQueryDesignView*>(GetParent()),"Parent isn't an OQueryDesignView!");
312 return static_cast<OQueryDesignView*>(GetParent());
314 namespace
316 class OSelectionBrwBoxHeader : public ::svt::EditBrowserHeader
318 OSelectionBrowseBox* m_pBrowseBox;
319 protected:
320 virtual void Select();
321 public:
322 OSelectionBrwBoxHeader(OSelectionBrowseBox* pParent);
324 OSelectionBrwBoxHeader::OSelectionBrwBoxHeader(OSelectionBrowseBox* pParent)
325 : ::svt::EditBrowserHeader(pParent,WB_BUTTONSTYLE|WB_DRAG)
326 ,m_pBrowseBox(pParent)
330 void OSelectionBrwBoxHeader::Select()
332 EditBrowserHeader::Select();
333 m_pBrowseBox->GrabFocus();
335 BrowserMode nMode = m_pBrowseBox->GetMode();
336 if ( 0 == m_pBrowseBox->GetSelectColumnCount() )
338 m_pBrowseBox->DeactivateCell();
339 // wenn es schon eine selektierte Spalte gibt, bin ich schon im richtigen Modus
340 if ( BROWSER_HIDESELECT == ( nMode & BROWSER_HIDESELECT ) )
342 nMode &= ~BROWSER_HIDESELECT;
343 nMode |= BROWSER_MULTISELECTION;
344 m_pBrowseBox->SetMode( nMode );
347 m_pBrowseBox->SelectColumnId( GetCurItemId() );
348 m_pBrowseBox->DeactivateCell();
352 // -----------------------------------------------------------------------------
353 BrowserHeader* OSelectionBrowseBox::imp_CreateHeaderBar(BrowseBox* /*pParent*/)
355 return new OSelectionBrwBoxHeader(this);
357 // -----------------------------------------------------------------------------
358 void OSelectionBrowseBox::ColumnMoved( USHORT nColId,BOOL _bCreateUndo )
360 EditBrowseBox::ColumnMoved( nColId );
361 // swap the two columns
362 USHORT nNewPos = GetColumnPos( nColId );
363 OTableFields& rFields = getFields();
364 if ( rFields.size() > USHORT(nNewPos-1) )
366 USHORT nOldPos = 0;
367 OTableFields::iterator aEnd = rFields.end();
368 OTableFields::iterator aIter = rFields.begin();
369 for (; aIter != aEnd && ( (*aIter)->GetColumnId() != nColId ); ++aIter,++nOldPos)
372 OSL_ENSURE( (nNewPos-1) != nOldPos && nOldPos < rFields.size(),"Old and new position are equal!");
373 if ( aIter != aEnd )
375 OTableFieldDescRef pOldEntry = rFields[nOldPos];
376 rFields.erase(rFields.begin() + nOldPos);
377 rFields.insert(rFields.begin() + nNewPos - 1,pOldEntry);
379 // create the undo action
380 if ( !m_bInUndoMode && _bCreateUndo )
382 OTabFieldMovedUndoAct* pUndoAct = new OTabFieldMovedUndoAct(this);
383 pUndoAct->SetColumnPosition( nOldPos + 1);
384 pUndoAct->SetTabFieldDescr(pOldEntry);
386 getDesignView()->getController().addUndoActionAndInvalidate(pUndoAct);
387 } // if ( !m_bInUndoMode && _bCreateUndo )
390 else
391 OSL_ENSURE(0,"Invalid column id!");
393 //------------------------------------------------------------------------------
394 void OSelectionBrowseBox::Init()
396 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
398 EditBrowseBox::Init();
400 // set the header bar
401 BrowserHeader* pNewHeaderBar = CreateHeaderBar(this);
402 pNewHeaderBar->SetMouseTransparent(sal_False);
404 SetHeaderBar(pNewHeaderBar);
405 SetMode(m_nMode);
407 Font aFont( GetDataWindow().GetFont() );
408 aFont.SetWeight( WEIGHT_NORMAL );
409 GetDataWindow().SetFont( aFont );
411 Size aHeight;
412 const Control* pControls[] = { m_pTextCell,m_pVisibleCell,m_pTableCell,m_pFieldCell };
413 for(sal_Size i= 0; i < sizeof(pControls)/sizeof(pControls[0]);++i)
415 const Size aTemp( pControls[i]->GetOptimalSize(WINDOWSIZE_PREFERRED) );
416 if ( aTemp.Height() > aHeight.Height() )
417 aHeight.Height() = aTemp.Height();
418 } // for(int i= 0; i < sizeof(pControls)/sizeof(pControls[0]);++i
419 SetDataRowHeight(aHeight.Height());
420 SetTitleLines(1);
421 // Anzahl der sichtbaren Zeilen ermitteln
422 for(long i=0;i<BROW_ROW_CNT;i++)
424 if(m_bVisibleRow[i])
425 m_nVisibleCount++;
427 RowInserted(0, m_nVisibleCount, sal_False);
430 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
431 if(xConnection.is())
433 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
434 m_nMaxColumns = xMetaData.is() ? xMetaData->getMaxColumnsInSelect() : 0;
437 else
438 m_nMaxColumns = 0;
440 catch(const SQLException&)
442 OSL_ENSURE(0,"Catched Exception when asking for database metadata options!");
443 m_nMaxColumns = 0;
447 //------------------------------------------------------------------------------
448 void OSelectionBrowseBox::PreFill()
450 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
451 SetUpdateMode(sal_False);
453 if (GetCurRow() != 0)
454 GoToRow(0);
457 static_cast< OQueryController& >( getDesignView()->getController() ).clearFields();
459 DeactivateCell();
461 RemoveColumns();
462 InsertHandleColumn( HANDLE_COLUMN_WITDH );
463 SetUpdateMode(sal_True);
465 //------------------------------------------------------------------------------
466 void OSelectionBrowseBox::ClearAll()
468 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
469 SetUpdateMode(sal_False);
471 OTableFields::reverse_iterator aIter = getFields().rbegin();
472 for ( ;aIter != getFields().rend(); ++aIter )
474 if ( !(*aIter)->IsEmpty() )
476 RemoveField( (*aIter)->GetColumnId() );
477 aIter = getFields().rbegin();
480 SetUpdateMode(sal_True);
482 //------------------------------------------------------------------------------
483 void OSelectionBrowseBox::SetReadOnly(sal_Bool bRO)
485 if (bRO)
487 DeactivateCell();
488 m_nMode &= ~BROWSER_HIDECURSOR;
489 SetMode(m_nMode);
491 else
493 m_nMode |= BROWSER_HIDECURSOR;
494 SetMode(m_nMode);
495 ActivateCell();
499 //------------------------------------------------------------------------------
500 CellController* OSelectionBrowseBox::GetController(long nRow, sal_uInt16 nColId)
502 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
503 if ( nColId > getFields().size() )
504 return NULL;
505 OTableFieldDescRef pEntry = getFields()[nColId-1];
506 DBG_ASSERT(pEntry.isValid(), "OSelectionBrowseBox::GetController : keine FieldDescription !");
508 if (!pEntry.isValid())
509 return NULL;
511 if (static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
512 return NULL;
514 long nCellIndex = GetRealRow(nRow);
515 switch (nCellIndex)
517 case BROW_FIELD_ROW:
518 return new ComboBoxCellController(m_pFieldCell);
519 case BROW_TABLE_ROW:
520 return new ListBoxCellController(m_pTableCell);
521 case BROW_VIS_ROW:
522 return new CheckBoxCellController(m_pVisibleCell);
523 case BROW_ORDER_ROW:
524 return new ListBoxCellController(m_pOrderCell);
525 case BROW_FUNCTION_ROW:
526 return new ListBoxCellController(m_pFunctionCell);
527 default:
528 return new EditCellController(m_pTextCell);
532 //------------------------------------------------------------------------------
533 void OSelectionBrowseBox::InitController(CellControllerRef& /*rController*/, long nRow, sal_uInt16 nColId)
535 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
536 OSL_ENSURE(nColId != BROWSER_INVALIDID,"An Invalid Id was set!");
537 if ( nColId == BROWSER_INVALIDID )
538 return;
539 USHORT nPos = GetColumnPos(nColId);
540 if ( nPos == 0 || nPos == BROWSER_INVALIDID || nPos > getFields().size() )
541 return;
542 OTableFieldDescRef pEntry = getFields()[nPos-1];
543 DBG_ASSERT(pEntry.isValid(), "OSelectionBrowseBox::InitController : keine FieldDescription !");
544 long nCellIndex = GetRealRow(nRow);
546 switch (nCellIndex)
548 case BROW_FIELD_ROW:
550 m_pFieldCell->Clear();
551 m_pFieldCell->SetText(String());
553 String aField(pEntry->GetField());
554 String aTable(pEntry->GetAlias());
556 getDesignView()->fillValidFields(aTable, m_pFieldCell);
558 // * durch alias.* ersetzen
559 if ((aField.GetChar(0) == '*') && aTable.Len())
561 aField = aTable;
562 aField.AppendAscii(".*");
564 m_pFieldCell->SetText(aField);
565 } break;
566 case BROW_TABLE_ROW:
568 m_pTableCell->Clear();
569 enableControl(pEntry,m_pTableCell);
570 if ( !pEntry->isCondition() )
572 OJoinTableView::OTableWindowMap* pTabWinList = getDesignView()->getTableView()->GetTabWinMap();
573 if (pTabWinList)
575 OJoinTableView::OTableWindowMap::iterator aIter = pTabWinList->begin();
576 OJoinTableView::OTableWindowMap::iterator aEnd = pTabWinList->end();
578 for(;aIter != aEnd;++aIter)
579 m_pTableCell->InsertEntry(static_cast<OQueryTableWindow*>(aIter->second)->GetAliasName());
581 m_pTableCell->InsertEntry(String(ModuleRes(STR_QUERY_NOTABLE)), 0);
582 if (pEntry->GetAlias().getLength())
583 m_pTableCell->SelectEntry(pEntry->GetAlias());
584 else
585 m_pTableCell->SelectEntry(String(ModuleRes(STR_QUERY_NOTABLE)));
588 } break;
589 case BROW_VIS_ROW:
591 m_pVisibleCell->GetBox().Check(pEntry->IsVisible());
592 m_pVisibleCell->GetBox().SaveValue();
594 enableControl(pEntry,m_pTextCell);
596 if(!pEntry->IsVisible() && pEntry->GetOrderDir() != ORDER_NONE && !m_bOrderByUnRelated)
598 // Spalte muss sichtbar sein, um im ORDER BY aufzutauchen
599 pEntry->SetVisible(sal_True);
600 m_pVisibleCell->GetBox().Check(pEntry->IsVisible());
601 m_pVisibleCell->GetBox().SaveValue();
602 m_pVisibleCell->GetBox().Disable();
603 m_pVisibleCell->GetBox().EnableInput(sal_False);
604 String aMessage(ModuleRes(STR_QRY_ORDERBY_UNRELATED));
605 OQueryDesignView* paDView = getDesignView();
606 InfoBox(paDView, aMessage).Execute();
608 } break;
609 case BROW_ORDER_ROW:
610 m_pOrderCell->SelectEntryPos(
611 sal::static_int_cast< USHORT >(pEntry->GetOrderDir()));
612 enableControl(pEntry,m_pOrderCell);
613 break;
614 case BROW_COLUMNALIAS_ROW:
615 setTextCellContext(pEntry,pEntry->GetFieldAlias(),HID_QRYDGN_ROW_ALIAS);
616 break;
617 case BROW_FUNCTION_ROW:
618 setFunctionCell(pEntry);
619 break;
620 default:
622 sal_uInt16 nIdx = sal_uInt16(nCellIndex - BROW_CRIT1_ROW);
623 setTextCellContext(pEntry,pEntry->GetCriteria( nIdx ),HID_QRYDGN_ROW_CRIT);
626 Controller()->ClearModified();
628 // -----------------------------------------------------------------------------
629 void OSelectionBrowseBox::notifyTableFieldChanged(const String& _sOldAlias,const String& _sAlias,sal_Bool& _bListAction,USHORT _nColumnId)
631 appendUndoAction(_sOldAlias,_sAlias,BROW_TABLE_ROW,_bListAction);
632 if ( m_bVisibleRow[BROW_TABLE_ROW] )
633 RowModified(GetBrowseRow(BROW_TABLE_ROW), _nColumnId);
635 // -----------------------------------------------------------------------------
636 void OSelectionBrowseBox::notifyFunctionFieldChanged(const String& _sOldFunctionName,const String& _sFunctionName,sal_Bool& _bListAction,USHORT _nColumnId)
638 appendUndoAction(_sOldFunctionName,_sFunctionName,BROW_FUNCTION_ROW,_bListAction);
639 if ( !m_bVisibleRow[BROW_FUNCTION_ROW] )
640 SetRowVisible(BROW_FUNCTION_ROW, sal_True);
641 RowModified(GetBrowseRow(BROW_FUNCTION_ROW), _nColumnId);
643 // -----------------------------------------------------------------------------
644 void OSelectionBrowseBox::clearEntryFunctionField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction,USHORT _nColumnId)
646 if ( isFieldNameAsterix( _sFieldName ) && (!_pEntry->isNoneFunction() || _pEntry->IsGroupBy()) )
648 String sFunctionName;
649 GetFunctionName(SQL_TOKEN_COUNT,sFunctionName);
650 String sOldLocalizedFunctionName = _pEntry->GetFunction();
651 if ( !sOldLocalizedFunctionName.Equals(sFunctionName) || _pEntry->IsGroupBy() )
653 // append undo action for the function field
654 _pEntry->SetFunctionType(FKT_NONE);
655 _pEntry->SetFunction(::rtl::OUString());
656 _pEntry->SetGroupBy(sal_False);
657 notifyFunctionFieldChanged(sOldLocalizedFunctionName,_pEntry->GetFunction(),_bListAction,_nColumnId);
661 // -----------------------------------------------------------------------------
662 sal_Bool OSelectionBrowseBox::fillColumnRef(const OSQLParseNode* _pColumnRef, const Reference< XConnection >& _rxConnection, OTableFieldDescRef& _pEntry, sal_Bool& _bListAction )
664 OSL_ENSURE(_pColumnRef,"No valid parsenode!");
665 ::rtl::OUString sColumnName,sTableRange;
666 OSQLParseTreeIterator::getColumnRange(_pColumnRef,_rxConnection,sColumnName,sTableRange);
667 return fillColumnRef(sColumnName,sTableRange,_rxConnection->getMetaData(),_pEntry,_bListAction);
669 // -----------------------------------------------------------------------------
670 sal_Bool OSelectionBrowseBox::fillColumnRef(const ::rtl::OUString& _sColumnName,const ::rtl::OUString& _sTableRange,const Reference<XDatabaseMetaData>& _xMetaData,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction)
672 sal_Bool bError = sal_False;
673 ::comphelper::UStringMixEqual bCase(_xMetaData->supportsMixedCaseQuotedIdentifiers());
674 // check if the table name is the same
675 if ( _sTableRange.getLength() && (bCase(_pEntry->GetTable(),_sTableRange) || bCase(_pEntry->GetAlias(),_sTableRange)) )
676 { // a table was already inserted and the tables contains that column name
678 if ( !_pEntry->GetTabWindow() )
679 { // fill tab window
680 ::rtl::OUString sOldAlias = _pEntry->GetAlias();
681 if ( !fillEntryTable(_pEntry,_pEntry->GetTable()) )
682 fillEntryTable(_pEntry,_pEntry->GetAlias()); // only when the first failed
683 if ( !bCase(sOldAlias,_pEntry->GetAlias()) )
684 notifyTableFieldChanged(sOldAlias,_pEntry->GetAlias(),_bListAction,GetCurColumnId());
687 // check if the table window
688 OQueryTableWindow* pEntryTab = static_cast<OQueryTableWindow*>(_pEntry->GetTabWindow());
689 if ( !pEntryTab ) // no table found with this name so we have to travel through all tables
691 OJoinTableView::OTableWindowMap* pTabWinList = getDesignView()->getTableView()->GetTabWinMap();
692 if ( pTabWinList )
694 sal_uInt16 nTabCount = 0;
695 if ( !static_cast<OQueryTableView*>(getDesignView()->getTableView())->FindTableFromField(_sColumnName,_pEntry,nTabCount) ) // error occured: column not in table window
697 String sErrorMsg(ModuleRes(RID_STR_FIELD_DOESNT_EXIST));
698 sErrorMsg.SearchAndReplaceAscii("$name$",_sColumnName);
699 OSQLWarningBox( this, sErrorMsg ).Execute();
700 bError = sal_True;
702 else
704 pEntryTab = static_cast<OQueryTableWindow*>(_pEntry->GetTabWindow());
705 notifyTableFieldChanged(String(),_pEntry->GetAlias(),_bListAction,GetCurColumnId());
709 if ( pEntryTab ) // here we got a valid table
710 _pEntry->SetField(_sColumnName);
712 return bError;
714 // -----------------------------------------------------------------------------
715 sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction)
717 sal_Bool bError = sal_False;
719 OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
721 // first look if the name can be found in our tables
722 sal_uInt16 nTabCount = 0;
723 String sOldAlias = _pEntry->GetAlias();
724 if ( static_cast<OQueryTableView*>(getDesignView()->getTableView())->FindTableFromField(_sFieldName,_pEntry,nTabCount) )
726 // append undo action for the alias name
727 _pEntry->SetField(_sFieldName);
728 notifyTableFieldChanged(sOldAlias,_pEntry->GetAlias(),_bListAction,GetCurColumnId());
729 clearEntryFunctionField(_sFieldName,_pEntry,_bListAction,_pEntry->GetColumnId());
730 return bError;
733 Reference<XConnection> xConnection( rController.getConnection() );
734 Reference< XDatabaseMetaData > xMetaData;
735 if ( xConnection.is() )
736 xMetaData = xConnection->getMetaData();
737 OSL_ENSURE( xMetaData.is(), "OSelectionBrowseBox::saveField: invalid connection/meta data!" );
738 if ( !xMetaData.is() )
739 return sal_True;
741 ::rtl::OUString sErrorMsg;
742 // second test if the name can be set as select columns in a pseudo statement
743 // we have to look which entries we should quote
745 const ::rtl::OUString sFieldAlias = _pEntry->GetFieldAlias();
746 size_t nPass = 4;
747 ::connectivity::OSQLParser& rParser( rController.getParser() );
748 OSQLParseNode* pParseNode = NULL;
749 // 4 passes in trying to interprete the field name
750 // - don't quote the field name, parse internationally
751 // - don't quote the field name, parse en-US
752 // - quote the field name, parse internationally
753 // - quote the field name, parse en-US
756 bool bQuote = ( nPass <= 2 );
757 bool bInternational = ( nPass % 2 ) == 0;
759 ::rtl::OUString sSql;
760 sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT "));
761 if ( bQuote )
762 sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), _sFieldName );
763 else
764 sSql += _sFieldName;
765 if ( sFieldAlias.getLength() )
766 { // always quote the alias name there canbe no function in it
767 sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
768 sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), sFieldAlias );
770 sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM x"));
772 pParseNode = rParser.parseTree( sErrorMsg, sSql, bInternational );
774 while ( ( pParseNode == NULL ) && ( --nPass > 0 ) );
776 if ( pParseNode == NULL )
778 // something different which we have to check (may be a select statement)
779 String sErrorMessage( ModuleRes( STR_QRY_COLUMN_NOT_FOUND ) );
780 sErrorMessage.SearchAndReplaceAscii("$name$",_sFieldName);
781 OSQLWarningBox( this, sErrorMessage ).Execute();
782 return sal_True;
785 // we got a valid select column
786 // find what type of column has be inserted
787 ::connectivity::OSQLParseNode* pSelection = pParseNode->getChild(2);
788 if ( SQL_ISRULE(pSelection,selection) ) // we found the asterix
790 _pEntry->SetField(_sFieldName);
791 clearEntryFunctionField(_sFieldName,_pEntry,_bListAction,_pEntry->GetColumnId());
792 } // travel through the select column parse node
793 else
795 ::comphelper::UStringMixEqual bCase(xMetaData->supportsMixedCaseQuotedIdentifiers());
797 OTableFieldDescRef aSelEntry = _pEntry;
798 USHORT nColumnId = aSelEntry->GetColumnId();
800 sal_uInt32 nCount = pSelection->count();
801 for (sal_uInt32 i = 0; i < nCount; ++i)
803 if ( i > 0 ) // may we have to append more than one field
805 USHORT nColumnPostion;
806 aSelEntry = FindFirstFreeCol(nColumnPostion);
807 if ( !aSelEntry.isValid() )
809 AppendNewCol(1);
810 aSelEntry = FindFirstFreeCol(nColumnPostion);
812 ++nColumnPostion;
813 nColumnId = GetColumnId(nColumnPostion);
816 ::connectivity::OSQLParseNode* pChild = pSelection->getChild( i );
817 OSL_ENSURE(SQL_ISRULE(pChild,derived_column), "No derived column found!");
818 // get the column alias
819 ::rtl::OUString sColumnAlias = OSQLParseTreeIterator::getColumnAlias(pChild);
820 if ( sColumnAlias.getLength() ) // we found an as clause
822 String aSelectionAlias = aSelEntry->GetFieldAlias();
823 aSelEntry->SetFieldAlias( sColumnAlias );
824 // append undo
825 appendUndoAction(aSelectionAlias,aSelEntry->GetFieldAlias(),BROW_COLUMNALIAS_ROW,_bListAction);
826 if ( m_bVisibleRow[BROW_COLUMNALIAS_ROW] )
827 RowModified(GetBrowseRow(BROW_COLUMNALIAS_ROW), nColumnId);
830 ::connectivity::OSQLParseNode* pColumnRef = pChild->getChild(0);
831 if (
832 pColumnRef->count() == 3 &&
833 SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") &&
834 SQL_ISPUNCTUATION(pColumnRef->getChild(2),")")
836 pColumnRef = pColumnRef->getChild(1);
838 if ( SQL_ISRULE(pColumnRef,column_ref) ) // we found a valid column name or more column names
840 // look if we can find the corresponding table
841 bError = fillColumnRef( pColumnRef, xConnection, aSelEntry, _bListAction );
843 // we found a simple column so we must clear the function fields but only when the column name is '*'
844 // and the function is different to count
845 clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
847 else
849 // first check if we have a aggregate function and only a function
850 if ( SQL_ISRULE(pColumnRef,general_set_fct) )
852 String sLocalizedFunctionName;
853 if ( GetFunctionName(pColumnRef->getChild(0)->getTokenID(),sLocalizedFunctionName) )
855 String sOldLocalizedFunctionName = aSelEntry->GetFunction();
856 aSelEntry->SetFunction(sLocalizedFunctionName);
857 sal_uInt32 nFunCount = pColumnRef->count() - 1;
858 sal_Int32 nFunctionType = FKT_AGGREGATE;
859 sal_Bool bQuote = sal_False;
860 // may be there exists only one parameter which is a column, fill all information into our fields
861 if ( nFunCount == 4 && SQL_ISRULE(pColumnRef->getChild(3),column_ref) )
862 bError = fillColumnRef( pColumnRef->getChild(3), xConnection, aSelEntry, _bListAction );
863 else if ( nFunCount == 3 ) // we have a COUNT(*) here, so take the first table
864 bError = fillColumnRef( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*")), ::rtl::OUString(), xMetaData, aSelEntry, _bListAction );
865 else
867 nFunctionType |= FKT_NUMERIC;
868 bQuote = sal_True;
869 aSelEntry->SetDataType(DataType::DOUBLE);
870 aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
873 // now parse the parameters
874 ::rtl::OUString sParameters;
875 for(sal_uInt32 function = 2; function < nFunCount; ++function) // we only want to parse the parameters of the function
876 pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, bQuote );
878 aSelEntry->SetFunctionType(nFunctionType);
879 aSelEntry->SetField(sParameters);
880 if ( aSelEntry->IsGroupBy() )
882 sOldLocalizedFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1);
883 aSelEntry->SetGroupBy(sal_False);
886 // append undo action
887 notifyFunctionFieldChanged(sOldLocalizedFunctionName,sLocalizedFunctionName,_bListAction, nColumnId);
889 else
890 OSL_ENSURE(0,"Unsupported function inserted!");
893 else if( SQL_ISRULEOR2(pColumnRef,position_exp,extract_exp) ||
894 SQL_ISRULEOR2(pColumnRef,fold,char_substring_fct) ||
895 SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
896 // a calculation has been found ( can be calc and function )
898 // append the whole text as field name
899 // so we first clear the function field
900 clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
901 sal_Bool bQuote = sal_True;
902 sal_Int32 nDataType = DataType::DOUBLE;
903 OSQLParseNode* pFunctionName = pColumnRef->getChild(0);
904 if ( !SQL_ISPUNCTUATION(pFunctionName,"{") )
906 if ( SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
907 pFunctionName = pFunctionName->getChild(0);
909 if ( pFunctionName )
911 ::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
912 if ( !sFunctionName.getLength() )
913 sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_MS_1252);
915 nDataType = OSQLParser::getFunctionReturnType(
916 sFunctionName
917 ,&rController.getParser().getContext());
918 aSelEntry->SetDataType(nDataType);
923 // now parse the whole statement
924 sal_uInt32 nFunCount = pColumnRef->count();
925 ::rtl::OUString sParameters;
926 for(sal_uInt32 function = 0; function < nFunCount; ++function)
927 pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, bQuote );
929 ::rtl::OUString aSelectionAlias = aSelEntry->GetAlias();
930 aSelEntry->SetAlias(::rtl::OUString());
932 sal_Int32 nNewFunctionType = aSelEntry->GetFunctionType() | FKT_NUMERIC | FKT_OTHER;
933 aSelEntry->SetFunctionType(nNewFunctionType);
936 aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
938 aSelEntry->SetTabWindow(NULL);
940 aSelEntry->SetField(sParameters);
941 notifyTableFieldChanged(aSelectionAlias,aSelEntry->GetAlias(),_bListAction, nColumnId);
943 else
945 clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
947 ::rtl::OUString aColumns;
948 pColumnRef->parseNodeToStr( aColumns,
949 xConnection,
950 &rController.getParser().getContext(),
951 sal_True,
952 sal_True);
953 // get the type out of the funtion name
954 sal_Int32 nDataType = DataType::DOUBLE;
955 aSelEntry->SetDataType(nDataType);
956 aSelEntry->SetField(aColumns);
957 aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
958 aSelEntry->SetTabWindow(NULL);
959 aSelEntry->SetAlias(::rtl::OUString());
960 aSelEntry->SetFieldAlias(sColumnAlias);
961 aSelEntry->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
963 notifyTableFieldChanged(sOldAlias,aSelEntry->GetAlias(),_bListAction, nColumnId);
966 if ( i > 0 && InsertField(aSelEntry,BROWSER_INVALIDID,sal_True,sal_False).isEmpty() ) // may we have to append more than one field
967 { // the field could not be isnerted
968 String sErrorMessage( ModuleRes( RID_STR_FIELD_DOESNT_EXIST ) );
969 sErrorMessage.SearchAndReplaceAscii("$name$",aSelEntry->GetField());
970 OSQLWarningBox( this, sErrorMessage ).Execute();
971 bError = sal_True;
975 delete pParseNode;
977 return bError;
979 //------------------------------------------------------------------------------
980 sal_Bool OSelectionBrowseBox::SaveModified()
982 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
983 OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
984 OTableFieldDescRef pEntry = NULL;
985 USHORT nCurrentColumnPos = GetColumnPos(GetCurColumnId());
986 if(getFields().size() > static_cast<USHORT>(nCurrentColumnPos - 1))
987 pEntry = getEntry(nCurrentColumnPos - 1);
989 sal_Bool bWasEmpty = pEntry.isValid() ? pEntry->IsEmpty() : sal_False;
990 sal_Bool bError = sal_False;
991 sal_Bool bListAction = sal_False;
993 if (pEntry.isValid() && Controller().Is() && Controller()->IsModified())
995 // fuer die Undo-Action
996 String strOldCellContents,sNewValue;
997 long nRow = GetRealRow(GetCurRow());
998 sal_Bool bAppendRow = sal_False;
999 switch (nRow)
1001 case BROW_VIS_ROW:
1003 sal_Bool bOldValue = m_pVisibleCell->GetBox().GetSavedValue() != STATE_NOCHECK;
1004 strOldCellContents = bOldValue ? g_strOne : g_strZero;
1005 sNewValue = !bOldValue ? g_strOne : g_strZero;
1007 if((m_bOrderByUnRelated || pEntry->GetOrderDir() == ORDER_NONE) &&
1008 (m_bGroupByUnRelated || !pEntry->IsGroupBy()))
1010 pEntry->SetVisible(m_pVisibleCell->GetBox().IsChecked());
1012 else
1014 pEntry->SetVisible(sal_True);
1015 m_pVisibleCell->GetBox().Check();
1017 break;
1019 case BROW_FIELD_ROW:
1021 String aFieldName(m_pFieldCell->GetText());
1024 if (!aFieldName.Len())
1026 OTableFieldDescRef pNewEntry = new OTableFieldDesc();
1027 pNewEntry->SetColumnId( pEntry->GetColumnId() );
1028 ::std::replace(getFields().begin(),getFields().end(),pEntry,pNewEntry);
1029 sal_uInt16 nCol = GetCurColumnId();
1030 for (int i = 0; i < m_nVisibleCount; i++) // Spalte neu zeichnen
1031 RowModified(i,nCol);
1033 else
1035 strOldCellContents = pEntry->GetField();
1036 bListAction = sal_True;
1037 if ( !m_bInUndoMode )
1038 rController.getUndoMgr()->EnterListAction(String(),String());
1040 USHORT nPos = m_pFieldCell->GetEntryPos(aFieldName);
1041 String aAliasName = pEntry->GetAlias();
1042 if ( nPos != COMBOBOX_ENTRY_NOTFOUND && !aAliasName.Len() && aFieldName.GetTokenCount('.') > 1 )
1043 { // special case, we have a table field so we must cut the table name
1044 String sTableAlias = aFieldName.GetToken(0,'.');
1045 pEntry->SetAlias(sTableAlias);
1046 String sColumnName = aFieldName.Copy(sTableAlias.Len()+1,aFieldName.Len() - sTableAlias.Len() -1);
1047 Reference<XConnection> xConnection = rController.getConnection();
1048 if ( !xConnection.is() )
1049 return sal_False;
1050 bError = fillColumnRef( sColumnName, sTableAlias, xConnection->getMetaData(), pEntry, bListAction );
1052 else
1053 bError = sal_True;
1055 if ( bError )
1056 bError = saveField(aFieldName,pEntry,bListAction);
1059 catch(Exception&)
1061 bError = sal_True;
1063 if ( bError )
1065 sNewValue = aFieldName;
1066 if ( !m_bInUndoMode )
1067 static_cast<OQueryController&>(getDesignView()->getController()).getUndoMgr()->LeaveListAction();
1068 bListAction = sal_False;
1070 else
1071 sNewValue = pEntry->GetField();
1072 rController.InvalidateFeature( ID_BROWSER_QUERY_EXECUTE );
1074 break;
1076 case BROW_TABLE_ROW:
1078 String aAliasName = m_pTableCell->GetSelectEntry();
1079 strOldCellContents = pEntry->GetAlias();
1080 if ( m_pTableCell->GetSelectEntryPos() != 0 )
1082 pEntry->SetAlias(aAliasName);
1083 // we have to set the table name as well as the table window
1084 OJoinTableView::OTableWindowMap* pTabWinList = getDesignView()->getTableView()->GetTabWinMap();
1085 if (pTabWinList)
1087 OJoinTableView::OTableWindowMapIterator aIter = pTabWinList->find(aAliasName);
1088 if(aIter != pTabWinList->end())
1090 OQueryTableWindow* pEntryTab = static_cast<OQueryTableWindow*>(aIter->second);
1091 if (pEntryTab)
1093 pEntry->SetTable(pEntryTab->GetTableName());
1094 pEntry->SetTabWindow(pEntryTab);
1099 else
1101 pEntry->SetAlias(::rtl::OUString());
1102 pEntry->SetTable(::rtl::OUString());
1103 pEntry->SetTabWindow(NULL);
1105 sNewValue = pEntry->GetAlias();
1107 } break;
1109 case BROW_ORDER_ROW:
1111 strOldCellContents = String::CreateFromInt32((sal_uInt16)pEntry->GetOrderDir());
1112 sal_uInt16 nIdx = m_pOrderCell->GetSelectEntryPos();
1113 if (nIdx == sal_uInt16(-1))
1114 nIdx = 0;
1115 pEntry->SetOrderDir(EOrderDir(nIdx));
1116 if(!m_bOrderByUnRelated)
1118 pEntry->SetVisible(sal_True);
1119 m_pVisibleCell->GetBox().Check();
1120 RowModified(GetBrowseRow(BROW_VIS_ROW), GetCurColumnId());
1122 sNewValue = String::CreateFromInt32((sal_uInt16)pEntry->GetOrderDir());
1123 } break;
1125 case BROW_COLUMNALIAS_ROW:
1126 strOldCellContents = pEntry->GetFieldAlias();
1127 pEntry->SetFieldAlias(m_pTextCell->GetText());
1128 sNewValue = pEntry->GetFieldAlias();
1129 break;
1130 case BROW_FUNCTION_ROW:
1132 strOldCellContents = pEntry->GetFunction();
1133 sal_uInt16 nPos = m_pFunctionCell->GetSelectEntryPos();
1134 // Diese Funktionen stehen nur unter CORE zur Verfügung
1135 String sFunctionName = m_pFunctionCell->GetEntry(nPos);
1136 String sGroupFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1);
1137 sal_Bool bGroupBy = sal_False;
1138 if ( sGroupFunctionName.Equals(sFunctionName) ) // check if the function name is GROUP
1140 bGroupBy = sal_True;
1142 if ( !m_bGroupByUnRelated && !pEntry->IsVisible() )
1144 // we have to change the visblie flag, so we must append also an undo action
1145 pEntry->SetVisible(sal_True);
1146 m_pVisibleCell->GetBox().Check();
1147 appendUndoAction(g_strZero,g_strOne,BROW_VIS_ROW,bListAction);
1148 RowModified(GetBrowseRow(BROW_VIS_ROW), GetCurColumnId());
1151 pEntry->SetFunction(String());
1152 pEntry->SetFunctionType(pEntry->GetFunctionType() & ~FKT_AGGREGATE );
1154 else if ( nPos ) // we found an aggregate function
1156 pEntry->SetFunctionType(pEntry->GetFunctionType() | FKT_AGGREGATE );
1157 pEntry->SetFunction(sFunctionName);
1159 else
1161 sFunctionName = String();
1162 pEntry->SetFunction(String());
1163 pEntry->SetFunctionType(pEntry->GetFunctionType() & ~FKT_AGGREGATE );
1166 pEntry->SetGroupBy(bGroupBy);
1168 sNewValue = sFunctionName;
1170 break;
1171 default:
1173 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
1174 if(!xConnection.is())
1175 break;
1177 sal_uInt16 nIdx = sal_uInt16(nRow - BROW_CRIT1_ROW);
1178 String aText = m_pTextCell->GetText();
1180 aText.EraseLeadingChars();
1181 ::rtl::OUString aCrit;
1182 if(aText.Len())
1184 ::rtl::OUString aErrorMsg;
1185 Reference<XPropertySet> xColumn;
1186 OSQLParseNode* pParseNode = getDesignView()->getPredicateTreeFromEntry(pEntry,aText,aErrorMsg,xColumn);
1188 if (pParseNode)
1190 pParseNode->parseNodeToPredicateStr(aCrit,
1191 xConnection,
1192 static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
1193 xColumn,
1194 getDesignView()->getLocale(),
1195 static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()),
1196 &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext()));
1197 delete pParseNode;
1199 else
1201 if(xColumn.is())
1203 sal_Int32 nType = 0;
1204 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nType;
1205 switch(nType)
1207 case DataType::CHAR:
1208 case DataType::VARCHAR:
1209 case DataType::LONGVARCHAR:
1210 if(aText.GetChar(0) != '\'' || aText.GetChar(aText.Len() -1) != '\'')
1212 aText.SearchAndReplaceAll(String::CreateFromAscii("'"),String::CreateFromAscii("''"));
1213 String aTmp(String::CreateFromAscii("'"));
1214 (aTmp += aText) += String::CreateFromAscii("'");
1215 aText = aTmp;
1217 break;
1218 default:
1221 ::connectivity::OSQLParser& rParser = static_cast<OQueryController&>(getDesignView()->getController()).getParser();
1222 pParseNode = rParser.predicateTree(aErrorMsg,
1223 aText,
1224 static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
1225 xColumn);
1226 if (pParseNode)
1228 pParseNode->parseNodeToPredicateStr(aCrit,
1229 xConnection,
1230 static_cast<OQueryController&>(getDesignView()->getController()).getNumberFormatter(),
1231 xColumn,
1232 getDesignView()->getLocale(),
1233 static_cast<sal_Char>(getDesignView()->getDecimalSeparator().toChar()),
1234 &(static_cast<OQueryController&>(getDesignView()->getController()).getParser().getContext()));
1235 delete pParseNode;
1237 else
1239 if ( !m_bDisableErrorBox )
1241 OSQLWarningBox( this, aErrorMsg ).Execute();
1243 bError = sal_True;
1246 else
1248 if ( !m_bDisableErrorBox )
1250 OSQLWarningBox( this, aErrorMsg ).Execute();
1252 bError = sal_True;
1255 // }
1257 strOldCellContents = pEntry->GetCriteria(nIdx);
1258 pEntry->SetCriteria(nIdx, aCrit);
1259 sNewValue = pEntry->GetCriteria(nIdx);
1260 if(aCrit.getLength() && nRow >= (GetRowCount()-1))
1261 bAppendRow = sal_True;
1264 if(!bError && Controller())
1265 Controller()->ClearModified();
1267 RowModified(GetCurRow(), GetCurColumnId());
1269 if ( bAppendRow )
1271 RowInserted( GetRowCount()-1, 1, TRUE );
1272 m_bVisibleRow.push_back(sal_True);
1273 ++m_nVisibleCount;
1276 if(!bError)
1278 // und noch die Undo-Action fuer das Ganze
1279 appendUndoAction(strOldCellContents,sNewValue,nRow);
1284 // habe ich Daten in einer FieldDescription gespeichert, die vorher leer war und es nach den Aenderungen nicht mehr ist ?
1285 if ( pEntry.isValid() && bWasEmpty && !pEntry->IsEmpty() && !bError )
1287 // Default auf sichtbar
1288 pEntry->SetVisible(sal_True);
1289 appendUndoAction(g_strZero,g_strOne,BROW_VIS_ROW,bListAction);
1290 RowModified(BROW_VIS_ROW, GetCurColumnId());
1292 // wenn noetig neue freie Spalten anlegen
1293 USHORT nDummy;
1294 CheckFreeColumns(nDummy);
1297 if ( bListAction && !m_bInUndoMode )
1298 static_cast<OQueryController&>(getDesignView()->getController()).getUndoMgr()->LeaveListAction();
1300 return pEntry != NULL && !bError;
1303 //------------------------------------------------------------------------------
1304 sal_Bool OSelectionBrowseBox::SeekRow(long nRow)
1306 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1307 sal_Bool bRet = sal_False;
1309 m_nSeekRow = nRow;
1310 if (nRow < m_nVisibleCount )
1311 bRet = sal_True;
1313 return bRet;
1316 //------------------------------------------------------------------------------
1317 void OSelectionBrowseBox::PaintCell(OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId) const
1319 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1320 rDev.SetClipRegion( rRect );
1322 OTableFieldDescRef pEntry = NULL;
1323 USHORT nPos = GetColumnPos(nColumnId);
1324 if(getFields().size() > sal_uInt16(nPos - 1))
1325 pEntry = getFields()[nPos - 1];
1327 if (!pEntry.isValid())
1328 return;
1330 long nRow = GetRealRow(m_nSeekRow);
1331 if (nRow == BROW_VIS_ROW)
1332 PaintTristate(rDev, rRect, pEntry->IsVisible() ? STATE_CHECK : STATE_NOCHECK);
1333 else
1334 rDev.DrawText(rRect, GetCellText(nRow, nColumnId),TEXT_DRAW_VCENTER);
1336 rDev.SetClipRegion( );
1339 //------------------------------------------------------------------------------
1340 void OSelectionBrowseBox::PaintStatusCell(OutputDevice& rDev, const Rectangle& rRect) const
1342 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1343 Rectangle aRect(rRect);
1344 aRect.TopLeft().Y() -= 2;
1345 String aLabel(ModuleRes(STR_QUERY_HANDLETEXT));
1347 // ab BROW_CRIT2_ROW werden alle Zeilen mit "oder" angegeben
1348 xub_StrLen nToken = (xub_StrLen) (m_nSeekRow >= GetBrowseRow(BROW_CRIT2_ROW))
1350 xub_StrLen(BROW_CRIT2_ROW) : xub_StrLen(GetRealRow(m_nSeekRow));
1351 rDev.DrawText(aRect, aLabel.GetToken(nToken),TEXT_DRAW_VCENTER);
1354 //------------------------------------------------------------------------------
1355 void OSelectionBrowseBox::RemoveColumn(USHORT _nColumnId)
1357 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1358 OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
1360 USHORT nPos = GetColumnPos(_nColumnId);
1361 // das Control sollte immer genau eine Spalte mehr haben, naemlich die HandleColumn
1362 DBG_ASSERT((nPos == 0) || (nPos <= getFields().size()), "OSelectionBrowseBox::RemoveColumn : invalid parameter nColId");
1363 // ColId ist bei mir gleichbedeutend mit Position, und da sollte die Bedingung natuerlich zutreffen
1365 sal_uInt16 nCurCol = GetCurColumnId();
1366 long nCurrentRow = GetCurRow();
1368 DeactivateCell();
1370 getFields().erase( getFields().begin() + (nPos - 1) );
1371 OTableFieldDescRef pEntry = new OTableFieldDesc();
1372 pEntry->SetColumnId(_nColumnId);
1373 getFields().push_back(pEntry);
1375 EditBrowseBox::RemoveColumn( _nColumnId );
1376 InsertDataColumn( _nColumnId , String(), DEFAULT_SIZE, HIB_STDSTYLE, HEADERBAR_APPEND);
1378 // Neuzeichnen
1379 Rectangle aInvalidRect = GetInvalidRect( _nColumnId );
1380 Invalidate( aInvalidRect );
1382 ActivateCell( nCurrentRow, nCurCol );
1384 rController.setModified();
1386 invalidateUndoRedo();
1389 //------------------------------------------------------------------------------
1390 void OSelectionBrowseBox::RemoveField(sal_uInt16 nColumnId )
1392 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1393 OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
1395 USHORT nPos = GetColumnPos(nColumnId);
1396 OSL_ENSURE(getFields().size() > sal_uInt16(nPos-1),"ID is to great!");
1398 OTableFieldDescRef pDesc = getEntry((sal_uInt32)(nPos - 1)) ;
1399 pDesc->SetColWidth( (sal_uInt16)GetColumnWidth(nColumnId) ); // hat er sich vorher leider nicht gemerkt
1401 // UndoAction erzeugen
1402 if ( !m_bInUndoMode )
1404 OTabFieldDelUndoAct* pUndoAction = new OTabFieldDelUndoAct( this );
1405 pUndoAction->SetTabFieldDescr(pDesc);
1406 pUndoAction->SetColumnPosition(nPos);
1407 rController.addUndoActionAndInvalidate( pUndoAction );
1410 RemoveColumn(nColumnId);
1412 invalidateUndoRedo();
1415 //------------------------------------------------------------------------------
1416 void OSelectionBrowseBox::adjustSelectionMode( sal_Bool _bClickedOntoHeader, sal_Bool _bClickedOntoHandleCol )
1418 // wenn ein Header selectiert wird, muß die selection angezeigt werden, sonst nicht)
1419 if ( _bClickedOntoHeader )
1421 if (0 == GetSelectColumnCount() )
1422 // wenn es schon eine selektierte Spalte gibt, bin ich schon im richtigen Modus
1423 if ( BROWSER_HIDESELECT == ( m_nMode & BROWSER_HIDESELECT ) )
1425 m_nMode &= ~BROWSER_HIDESELECT;
1426 m_nMode |= BROWSER_MULTISELECTION;
1427 SetMode( m_nMode );
1430 else if ( BROWSER_HIDESELECT != ( m_nMode & BROWSER_HIDESELECT ) )
1432 if ( GetSelectColumnCount() != 0 )
1433 SetNoSelection();
1435 if ( _bClickedOntoHandleCol )
1437 m_nMode |= BROWSER_HIDESELECT;
1438 m_nMode &= ~BROWSER_MULTISELECTION;
1439 SetMode( m_nMode );
1444 //------------------------------------------------------------------------------
1445 void OSelectionBrowseBox::MouseButtonDown(const BrowserMouseEvent& rEvt)
1447 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1448 if( rEvt.IsLeft() )
1450 sal_Bool bOnHandle = HANDLE_ID == rEvt.GetColumnId();
1451 sal_Bool bOnHeader = ( rEvt.GetRow() < 0 ) && !bOnHandle;
1452 adjustSelectionMode( bOnHeader, bOnHandle );
1454 EditBrowseBox::MouseButtonDown(rEvt);
1457 //------------------------------------------------------------------------------
1458 void OSelectionBrowseBox::MouseButtonUp(const BrowserMouseEvent& rEvt)
1460 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1461 EditBrowseBox::MouseButtonUp( rEvt );
1462 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( ID_BROWSER_QUERY_EXECUTE );
1465 //------------------------------------------------------------------------------
1466 void OSelectionBrowseBox::KeyInput( const KeyEvent& rEvt )
1468 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1469 if (IsColumnSelected(GetCurColumnId()))
1471 if (rEvt.GetKeyCode().GetCode() == KEY_DELETE && // Delete rows
1472 !rEvt.GetKeyCode().IsShift() &&
1473 !rEvt.GetKeyCode().IsMod1())
1475 RemoveField(GetCurColumnId());
1476 return;
1479 EditBrowseBox::KeyInput(rEvt);
1483 //------------------------------------------------------------------------------
1484 sal_Int8 OSelectionBrowseBox::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
1486 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1487 sal_Int8 nDropAction = DND_ACTION_NONE;
1488 if ( rEvt.GetRow() >= -1 )
1490 if ( IsEditing() )
1492 // #100271# OJ allow the asterix again
1493 m_bDisableErrorBox = sal_True;
1494 SaveModified();
1495 m_bDisableErrorBox = sal_False;
1496 DeactivateCell();
1498 // check if the format is already supported, if not deactivate the current cell and try again
1499 if ( OJoinExchObj::isFormatAvailable(GetDataFlavors()) )
1500 nDropAction = DND_ACTION_LINK;
1503 return nDropAction;
1506 //------------------------------------------------------------------------------
1507 sal_Int8 OSelectionBrowseBox::ExecuteDrop( const BrowserExecuteDropEvent& _rEvt )
1509 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1511 TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
1512 if (!OJoinExchObj::isFormatAvailable(aDropped.GetDataFlavorExVector()))
1514 DBG_ERROR("OSelectionBrowseBox::ExecuteDrop: this should never have passed AcceptDrop!");
1515 return DND_ACTION_NONE;
1518 OTableFieldDesc aInfo;
1519 // Einfuegen des Feldes an der gewuenschten Position
1520 OJoinExchangeData jxdSource = OJoinExchObj::GetSourceDescription(_rEvt.maDropEvent.Transferable);
1521 InsertField(jxdSource);
1523 return DND_ACTION_LINK;
1526 //------------------------------------------------------------------------------
1527 OTableFieldDescRef OSelectionBrowseBox::AppendNewCol( sal_uInt16 nCnt)
1529 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1530 // es koennen mehrere angelegt werden, aber der Erste
1531 // wird returnt
1532 sal_uInt32 nCount = getFields().size();
1533 for (sal_uInt16 i=0 ; i<nCnt ; i++)
1535 OTableFieldDescRef pEmptyEntry = new OTableFieldDesc();
1536 getFields().push_back(pEmptyEntry);
1537 USHORT nColumnId = sal::static_int_cast< USHORT >(getFields().size());
1538 pEmptyEntry->SetColumnId( nColumnId );
1540 InsertDataColumn( nColumnId , String(), DEFAULT_SIZE, HIB_STDSTYLE, HEADERBAR_APPEND);
1543 return getFields()[nCount];
1546 //------------------------------------------------------------------------------
1547 void OSelectionBrowseBox::DeleteFields(const String& rAliasName)
1549 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1550 if (!getFields().empty())
1552 sal_uInt16 nColId = GetCurColumnId();
1553 sal_uInt32 nRow = GetCurRow();
1555 sal_Bool bWasEditing = IsEditing();
1556 if (bWasEditing)
1557 DeactivateCell();
1559 OTableFields::reverse_iterator aIter = getFields().rbegin();
1560 OTableFieldDescRef pEntry = NULL;
1561 for(USHORT nPos=sal::static_int_cast< USHORT >(getFields().size());aIter != getFields().rend();++aIter,--nPos)
1563 pEntry = *aIter;
1564 if ( pEntry->GetAlias().equals( rAliasName ) )
1566 RemoveField( GetColumnId( nPos ) );
1567 break;
1571 if (bWasEditing)
1572 ActivateCell(nRow , nColId);
1576 //------------------------------------------------------------------------------
1577 void OSelectionBrowseBox::SetColWidth(sal_uInt16 nColId, long nNewWidth)
1579 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1580 sal_Bool bWasEditing = IsEditing();
1581 if (bWasEditing)
1582 DeactivateCell();
1584 // die Basisklasse machen lassen
1585 SetColumnWidth(nColId, nNewWidth);
1587 // der FieldDescription Bescheid sagen
1588 OTableFieldDescRef pEntry = getEntry(GetColumnPos(nColId) - 1);
1589 if (pEntry.isValid())
1590 pEntry->SetColWidth(sal_uInt16(GetColumnWidth(nColId)));
1592 if (bWasEditing)
1593 ActivateCell(GetCurRow(), GetCurColumnId());
1596 //------------------------------------------------------------------------------
1597 Rectangle OSelectionBrowseBox::GetInvalidRect( sal_uInt16 nColId )
1599 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1600 //////////////////////////////////////////////////////////////////////
1601 // Rechteck ist erst einmal der gesamte Outputbereich des Fensters
1602 Rectangle aInvalidRect( Point(0,0), GetOutputSizePixel() );
1604 //////////////////////////////////////////////////////////////////////
1605 // Dann wird die linke Seite angepasst
1606 Rectangle aFieldRect(GetCellRect( 0, nColId )); // used instead of GetFieldRectPixel
1607 aInvalidRect.Left() = aFieldRect.Left();
1609 return aInvalidRect;
1612 //------------------------------------------------------------------------------
1613 void OSelectionBrowseBox::InsertColumn(OTableFieldDescRef pEntry, USHORT& _nColumnPostion)
1615 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1616 // das Control sollte immer genau eine Spalte mehr haben, naemlich die HandleColumn
1617 DBG_ASSERT(_nColumnPostion == BROWSER_INVALIDID || (_nColumnPostion <= (long)getFields().size()), "OSelectionBrowseBox::InsertColumn : invalid parameter nColId.");
1618 // -1 heisst ganz hinten, Count heisst ganz hinten, der Rest bezeichnet eine richtige Position
1620 sal_uInt16 nCurCol = GetCurColumnId();
1621 long nCurrentRow = GetCurRow();
1623 DeactivateCell();
1625 // remember the column id of the current positon
1626 USHORT nColumnId = GetColumnId(_nColumnPostion);
1627 // Wenn zu klein oder zu gross, auf Ende der Liste setzen
1628 if ((_nColumnPostion == BROWSER_INVALIDID) || (_nColumnPostion >= getFields().size())) // Anhaengen des Feldes
1630 if (FindFirstFreeCol(_nColumnPostion) == NULL) // keine freie Column mehr
1632 AppendNewCol(1);
1633 _nColumnPostion = sal::static_int_cast< USHORT >(
1634 getFields().size());
1636 else
1637 ++_nColumnPostion; // innerhalb der vorgegebenen Liste
1638 nColumnId = GetColumnId(_nColumnPostion);
1639 pEntry->SetColumnId( nColumnId );
1640 getFields()[ _nColumnPostion - 1] = pEntry;
1643 // check if the column ids are identical, if not we have to move
1644 if ( pEntry->GetColumnId() != nColumnId )
1646 USHORT nOldPosition = GetColumnPos(pEntry->GetColumnId());
1647 OSL_ENSURE( nOldPosition != 0,"Old position was 0. Not possible!");
1648 SetColumnPos(pEntry->GetColumnId(),_nColumnPostion);
1649 // we have to delete an empty field for the fields list, because the columns must have equal length
1650 if ( nOldPosition > 0 && nOldPosition <= getFields().size() )
1651 getFields()[nOldPosition - 1] = pEntry;
1653 ColumnMoved(pEntry->GetColumnId(),FALSE);
1654 } // if ( pEntry->GetColumnId() != nColumnId )
1656 if ( pEntry->GetFunctionType() & (FKT_AGGREGATE) )
1658 String sFunctionName = pEntry->GetFunction();
1659 if ( GetFunctionName(sal_uInt32(-1),sFunctionName) )
1660 pEntry->SetFunction(sFunctionName);
1663 nColumnId = pEntry->GetColumnId();
1665 SetColWidth(nColumnId,getDesignView()->getColWidth(GetColumnPos(nColumnId)-1));
1666 // Neuzeichnen
1667 Rectangle aInvalidRect = GetInvalidRect( nColumnId );
1668 Invalidate( aInvalidRect );
1670 ActivateCell( nCurrentRow, nCurCol );
1671 static_cast<OQueryController&>(getDesignView()->getController()).setModified();
1673 invalidateUndoRedo();
1676 //------------------------------------------------------------------------------
1677 OTableFieldDescRef OSelectionBrowseBox::InsertField(const OJoinExchangeData& jxdSource, USHORT _nColumnPostion, sal_Bool bVis, sal_Bool bActivate)
1679 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1680 OQueryTableWindow* pSourceWin = static_cast<OQueryTableWindow*>(jxdSource.pListBox->GetTabWin());
1681 if (!pSourceWin)
1682 return NULL;
1684 // Namen/Position des selektierten Feldes
1685 String aFieldName = jxdSource.pListBox->GetEntryText(jxdSource.pEntry);
1686 sal_uInt32 nFieldIndex = jxdSource.pListBox->GetModel()->GetAbsPos(jxdSource.pEntry);
1687 OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(jxdSource.pEntry->GetUserData());
1689 // eine DragInfo aufbauen, damit ich mich auf das andere InsertField zurueckziehen kann
1690 OTableFieldDescRef aInfo = new OTableFieldDesc(pSourceWin->GetTableName(),aFieldName);
1691 aInfo->SetTabWindow(pSourceWin);
1692 aInfo->SetFieldIndex(nFieldIndex);
1693 aInfo->SetFieldType(pInf->GetKeyType());
1694 aInfo->SetAlias(pSourceWin->GetAliasName());
1696 aInfo->SetDataType(pInf->GetDataType());
1697 aInfo->SetVisible(bVis);
1699 return InsertField(aInfo, _nColumnPostion, bVis, bActivate);
1702 //------------------------------------------------------------------------------
1703 OTableFieldDescRef OSelectionBrowseBox::InsertField(const OTableFieldDescRef& _rInfo, USHORT _nColumnPostion, sal_Bool bVis, sal_Bool bActivate)
1705 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1707 if(m_nMaxColumns && m_nMaxColumns <= FieldsCount())
1708 return NULL;
1709 if (bActivate)
1710 SaveModified();
1712 // Neue Spaltenbeschreibung
1713 OTableFieldDescRef pEntry = _rInfo;
1714 pEntry->SetVisible(bVis);
1716 // Spalte einfuegen
1717 InsertColumn( pEntry, _nColumnPostion );
1719 if ( !m_bInUndoMode )
1721 // UndoAction erzeugen
1722 OTabFieldCreateUndoAct* pUndoAction = new OTabFieldCreateUndoAct( this );
1723 pUndoAction->SetTabFieldDescr( pEntry );
1724 pUndoAction->SetColumnPosition(_nColumnPostion);
1725 getDesignView()->getController().addUndoActionAndInvalidate( pUndoAction );
1728 return pEntry;
1731 //------------------------------------------------------------------------------
1732 sal_uInt16 OSelectionBrowseBox::FieldsCount()
1734 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1735 OTableFields::iterator aIter = getFields().begin();
1736 sal_uInt16 nCount = 0;
1738 while (aIter != getFields().end())
1740 if ((*aIter).isValid() && !(*aIter)->IsEmpty())
1741 ++nCount;
1742 ++aIter;
1745 return nCount;
1748 //------------------------------------------------------------------------------
1749 OTableFieldDescRef OSelectionBrowseBox::FindFirstFreeCol(USHORT& _rColumnPosition )
1751 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1752 OTableFields::iterator aIter = getFields().begin();
1753 OTableFields::iterator aEnd = getFields().end();
1755 _rColumnPosition = BROWSER_INVALIDID;
1757 while ( aIter != aEnd )
1759 ++_rColumnPosition;
1760 OTableFieldDescRef pEntry = (*aIter);
1761 if ( pEntry.isValid() && pEntry->IsEmpty() )
1762 return pEntry;
1763 ++aIter;
1766 return NULL;
1769 //------------------------------------------------------------------------------
1770 void OSelectionBrowseBox::CheckFreeColumns(USHORT& _rColumnPosition)
1772 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1773 if (FindFirstFreeCol(_rColumnPosition) == NULL)
1775 // es ist voll, also einen Packen Spalten anhaengen
1776 AppendNewCol(DEFAULT_QUERY_COLS);
1777 OSL_VERIFY(FindFirstFreeCol(_rColumnPosition).isValid());
1780 //------------------------------------------------------------------------------
1781 void OSelectionBrowseBox::AddGroupBy( const OTableFieldDescRef& rInfo , sal_uInt32 /*_nCurrentPos*/)
1783 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
1784 if(!xConnection.is())
1785 return;
1786 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1787 DBG_ASSERT(!rInfo->IsEmpty(),"AddGroupBy:: OTableFieldDescRef sollte nicht Empty sein!");
1788 OTableFieldDescRef pEntry;
1789 const Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
1790 const ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
1791 //sal_Bool bAppend = sal_False;
1793 OTableFields& rFields = getFields();
1794 OTableFields::iterator aIter = rFields.begin();
1795 OTableFields::iterator aEnd = rFields.end();
1796 for(;aIter != aEnd;++aIter)
1798 pEntry = *aIter;
1799 OSL_ENSURE(pEntry.isValid(),"OTableFieldDescRef was null!");
1801 const ::rtl::OUString aField = pEntry->GetField();
1802 const ::rtl::OUString aAlias = pEntry->GetAlias();
1804 if (bCase(aField,rInfo->GetField()) &&
1805 bCase(aAlias,rInfo->GetAlias()) &&
1806 pEntry->GetFunctionType() == rInfo->GetFunctionType() &&
1807 pEntry->GetFunction() == rInfo->GetFunction())
1809 /*sal_uInt32 nPos = aIter - rFields.begin();
1810 bAppend = _nCurrentPos > nPos && (rInfo->IsGroupBy() != pEntry->IsGroupBy());
1811 if ( bAppend )
1812 aIter = rFields.end();
1813 else*/
1815 if ( pEntry->isNumericOrAggreateFunction() && rInfo->IsGroupBy() )
1817 pEntry->SetGroupBy(sal_False);
1818 aIter = rFields.end();
1820 else
1822 pEntry->SetGroupBy(rInfo->IsGroupBy());
1823 if(!m_bGroupByUnRelated && pEntry->IsGroupBy())
1824 pEntry->SetVisible(sal_True);
1827 break;
1831 if (aIter == rFields.end())
1833 OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, sal_False, sal_False );
1834 if ( (pTmp->isNumericOrAggreateFunction() && rInfo->IsGroupBy()) ) // das GroupBy wird bereits von rInfo "ubernommen
1835 pTmp->SetGroupBy(sal_False);
1838 //------------------------------------------------------------------------------
1839 void OSelectionBrowseBox::AddCondition( const OTableFieldDescRef& rInfo, const String& rValue, const sal_uInt16 nLevel,bool _bAddOrOnOneLine )
1841 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
1842 if(!xConnection.is())
1843 return;
1844 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1845 DBG_ASSERT(rInfo.isValid() && !rInfo->IsEmpty(),"AddCondition:: OTableFieldDescRef sollte nicht Empty sein!");
1847 OTableFieldDescRef pLastEntry;
1848 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
1849 ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
1851 OTableFields& rFields = getFields();
1852 OTableFields::iterator aIter = rFields.begin();
1853 OTableFields::iterator aEnd = rFields.end();
1854 for(;aIter != aEnd;++aIter)
1856 OTableFieldDescRef pEntry = *aIter;
1857 const ::rtl::OUString aField = pEntry->GetField();
1858 const ::rtl::OUString aAlias = pEntry->GetAlias();
1860 if (bCase(aField,rInfo->GetField()) &&
1861 bCase(aAlias,rInfo->GetAlias()) &&
1862 pEntry->GetFunctionType() == rInfo->GetFunctionType() &&
1863 pEntry->GetFunction() == rInfo->GetFunction())
1865 if ( pEntry->isNumericOrAggreateFunction() && rInfo->IsGroupBy() )
1866 pEntry->SetGroupBy(sal_False);
1867 else
1869 pEntry->SetGroupBy(rInfo->IsGroupBy());
1870 if(!m_bGroupByUnRelated && pEntry->IsGroupBy())
1871 pEntry->SetVisible(sal_True);
1873 if (!pEntry->GetCriteria(nLevel).getLength() )
1875 pEntry->SetCriteria( nLevel, rValue);
1876 if(nLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1))
1878 RowInserted( GetRowCount()-1, 1, TRUE );
1879 m_bVisibleRow.push_back(sal_True);
1880 ++m_nVisibleCount;
1882 m_bVisibleRow[BROW_CRIT1_ROW + nLevel] = sal_True;
1883 break;
1884 } // if (!pEntry->GetCriteria(nLevel).getLength() )
1885 if ( _bAddOrOnOneLine )
1887 pLastEntry = pEntry;
1890 } // for(;aIter != getFields().end();++aIter)
1891 if ( pLastEntry.isValid() )
1893 String sCriteria = rValue;
1894 String sOldCriteria = pLastEntry->GetCriteria( nLevel );
1895 if ( sOldCriteria.Len() )
1897 sCriteria = String(RTL_CONSTASCII_USTRINGPARAM("( "));
1898 sCriteria += sOldCriteria;
1899 sCriteria += String(RTL_CONSTASCII_USTRINGPARAM(" OR "));
1900 sCriteria += rValue;
1901 sCriteria += String(RTL_CONSTASCII_USTRINGPARAM(" )"));
1903 pLastEntry->SetCriteria( nLevel, sCriteria);
1904 if(nLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1))
1906 RowInserted( GetRowCount()-1, 1, TRUE );
1907 m_bVisibleRow.push_back(sal_True);
1908 ++m_nVisibleCount;
1910 m_bVisibleRow[BROW_CRIT1_ROW + nLevel] = sal_True;
1913 else if (aIter == getFields().end())
1915 OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, sal_False, sal_False );
1916 if ( pTmp->isNumericOrAggreateFunction() && rInfo->IsGroupBy() ) // das GroupBy wird bereits von rInfo "ubernommen
1917 pTmp->SetGroupBy(sal_False);
1918 if ( pTmp.isValid() )
1920 pTmp->SetCriteria( nLevel, rValue);
1921 if(nLevel == (m_nVisibleCount-BROW_CRIT1_ROW-1))
1923 RowInserted( GetRowCount()-1, 1, TRUE );
1924 m_bVisibleRow.push_back(sal_True);
1925 ++m_nVisibleCount;
1931 //------------------------------------------------------------------------------
1932 void OSelectionBrowseBox::AddOrder( const OTableFieldDescRef& rInfo, const EOrderDir eDir, sal_uInt32 _nCurrentPos)
1934 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
1935 if(!xConnection.is())
1936 return;
1937 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1938 DBG_ASSERT(!rInfo->IsEmpty(),"AddOrder:: OTableFieldDescRef sollte nicht Empty sein!");
1939 OTableFieldDescRef pEntry;
1940 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
1941 ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
1943 sal_Bool bAppend = sal_False;
1944 OTableFields& rFields = getFields();
1945 OTableFields::iterator aIter = rFields.begin();
1946 OTableFields::iterator aEnd = rFields.end();
1947 for(;aIter != aEnd;++aIter)
1949 pEntry = *aIter;
1950 ::rtl::OUString aField = pEntry->GetField();
1951 ::rtl::OUString aAlias = pEntry->GetAlias();
1953 if (bCase(aField,rInfo->GetField()) &&
1954 bCase(aAlias,rInfo->GetAlias()))
1956 sal_uInt32 nPos = aIter - rFields.begin();
1957 bAppend = _nCurrentPos > nPos;
1958 if ( bAppend )
1959 aIter = rFields.end();
1960 else
1962 if ( !m_bOrderByUnRelated )
1963 pEntry->SetVisible(sal_True);
1964 pEntry->SetOrderDir( eDir );
1966 break;
1970 if (aIter == rFields.end())
1972 OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, sal_False, sal_False );
1973 if(pTmp.isValid())
1975 if ( !m_bOrderByUnRelated && !bAppend )
1976 pTmp->SetVisible(sal_True);
1977 pTmp->SetOrderDir( eDir );
1982 //------------------------------------------------------------------------------
1983 void OSelectionBrowseBox::ArrangeControls(sal_uInt16& nX, sal_uInt16 nY)
1985 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1986 EditBrowseBox::ArrangeControls(nX, nY);
1989 //------------------------------------------------------------------------------
1990 sal_Bool OSelectionBrowseBox::Save()
1992 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
1993 sal_Bool bRet = sal_True;
1994 if (IsModified())
1995 bRet = SaveModified();
1996 return bRet;
1999 //------------------------------------------------------------------------------
2000 void OSelectionBrowseBox::CellModified()
2002 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2003 long nRow = GetRealRow(GetCurRow());
2004 switch (nRow)
2006 case BROW_VIS_ROW:
2008 OTableFieldDescRef pEntry = getEntry(GetColumnPos(GetCurColumnId()) - 1);
2010 sal_uInt16 nIdx = m_pOrderCell->GetSelectEntryPos();
2011 if(!m_bOrderByUnRelated && nIdx > 0 &&
2012 nIdx != sal_uInt16(-1) &&
2013 !pEntry->IsEmpty() &&
2014 pEntry->GetOrderDir() != ORDER_NONE)
2016 m_pVisibleCell->GetBox().Check();
2017 pEntry->SetVisible(sal_True);
2019 else
2020 pEntry->SetVisible(m_pVisibleCell->GetBox().IsChecked());
2022 break;
2024 static_cast<OQueryController&>(getDesignView()->getController()).setModified();
2027 //------------------------------------------------------------------------------
2028 void OSelectionBrowseBox::Fill()
2030 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2031 DBG_ASSERT(ColCount() >= 1, "OSelectionBrowseBox::Fill : please call only after inserting the handle column !");
2033 sal_uInt16 nColCount = ColCount() - 1;
2034 if (nColCount < DEFAULT_QUERY_COLS)
2035 AppendNewCol(DEFAULT_QUERY_COLS - nColCount);
2038 //------------------------------------------------------------------------------
2039 Size OSelectionBrowseBox::CalcOptimalSize( const Size& _rAvailable )
2041 Size aReturn( _rAvailable.Width(), GetTitleHeight() );
2043 aReturn.Height() += ( m_nVisibleCount ? m_nVisibleCount : 15 ) * GetDataRowHeight();
2044 aReturn.Height() += 40; // just some space
2046 return aReturn;
2049 //------------------------------------------------------------------------------
2050 void OSelectionBrowseBox::Command(const CommandEvent& rEvt)
2052 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2053 switch (rEvt.GetCommand())
2055 case COMMAND_CONTEXTMENU:
2057 Point aMenuPos( rEvt.GetMousePosPixel() );
2059 if (!rEvt.IsMouseEvent())
2061 if ( 1 == GetSelectColumnCount() )
2063 sal_uInt16 nSelId = GetColumnId(
2064 sal::static_int_cast< USHORT >(
2065 FirstSelectedColumn() ) );
2066 ::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, sal_False ) );
2068 aMenuPos = aColRect.TopCenter();
2070 else
2072 EditBrowseBox::Command(rEvt);
2073 return;
2077 sal_uInt16 nColId = GetColumnId(GetColumnAtXPosPixel( aMenuPos.X() ));
2078 long nRow = GetRowAtYPosPixel( aMenuPos.Y() );
2080 if (nRow < 0 && nColId > HANDLE_ID )
2082 if ( !IsColumnSelected( nColId ) )
2084 adjustSelectionMode( sal_True /* clicked onto a header */ , sal_False /* not onto the handle col */ );
2085 SelectColumnId( nColId );
2088 if (!static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
2090 PopupMenu aContextMenu( ModuleRes( RID_QUERYCOLPOPUPMENU ) );
2091 switch (aContextMenu.Execute(this, aMenuPos))
2093 case SID_DELETE:
2094 RemoveField(nColId);
2095 break;
2097 case ID_BROWSER_COLWIDTH:
2098 adjustBrowseBoxColumnWidth( this, nColId );
2099 break;
2103 else if(nRow >= 0 && nColId <= HANDLE_ID)
2105 if (!static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
2107 PopupMenu aContextMenu(ModuleRes(RID_QUERYFUNCTION_POPUPMENU));
2108 aContextMenu.CheckItem( ID_QUERY_FUNCTION, m_bVisibleRow[BROW_FUNCTION_ROW]);
2109 aContextMenu.CheckItem( ID_QUERY_TABLENAME, m_bVisibleRow[BROW_TABLE_ROW]);
2110 aContextMenu.CheckItem( ID_QUERY_ALIASNAME, m_bVisibleRow[BROW_COLUMNALIAS_ROW]);
2111 aContextMenu.CheckItem( ID_QUERY_DISTINCT, static_cast<OQueryController&>(getDesignView()->getController()).isDistinct());
2113 switch (aContextMenu.Execute(this, aMenuPos))
2115 case ID_QUERY_FUNCTION:
2116 SetRowVisible(BROW_FUNCTION_ROW, !IsRowVisible(BROW_FUNCTION_ROW));
2117 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_VIEW_FUNCTIONS );
2118 break;
2119 case ID_QUERY_TABLENAME:
2120 SetRowVisible(BROW_TABLE_ROW, !IsRowVisible(BROW_TABLE_ROW));
2121 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_VIEW_TABLES );
2122 break;
2123 case ID_QUERY_ALIASNAME:
2124 SetRowVisible(BROW_COLUMNALIAS_ROW, !IsRowVisible(BROW_COLUMNALIAS_ROW));
2125 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_VIEW_ALIASES );
2126 break;
2127 case ID_QUERY_DISTINCT:
2128 static_cast<OQueryController&>(getDesignView()->getController()).setDistinct(!static_cast<OQueryController&>(getDesignView()->getController()).isDistinct());
2129 static_cast<OQueryController&>(getDesignView()->getController()).setModified();
2130 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature( SID_QUERY_DISTINCT_VALUES );
2131 break;
2134 static_cast<OQueryController&>(getDesignView()->getController()).setModified();
2137 else
2139 EditBrowseBox::Command(rEvt);
2140 return;
2143 default:
2144 EditBrowseBox::Command(rEvt);
2148 //------------------------------------------------------------------------------
2149 sal_Bool OSelectionBrowseBox::IsRowVisible(sal_uInt16 _nWhich) const
2151 DBG_ASSERT(_nWhich<(m_bVisibleRow.size()), "OSelectionBrowseBox::IsRowVisible : invalid parameter !");
2152 return m_bVisibleRow[_nWhich];
2155 //------------------------------------------------------------------------------
2156 void OSelectionBrowseBox::SetRowVisible(sal_uInt16 _nWhich, sal_Bool _bVis)
2158 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2159 DBG_ASSERT(_nWhich<m_bVisibleRow.size(), "OSelectionBrowseBox::SetRowVisible : invalid parameter !");
2161 sal_Bool bWasEditing = IsEditing();
2162 if (bWasEditing)
2163 DeactivateCell();
2165 // do this before removing or inserting rows, as this triggers ActivateCell-calls, which rely on m_bVisibleRow
2166 m_bVisibleRow[_nWhich] = !m_bVisibleRow[_nWhich];
2168 long nId = GetBrowseRow(_nWhich);
2169 if (_bVis)
2171 RowInserted(nId,1);
2172 ++m_nVisibleCount;
2174 else
2176 RowRemoved(nId,1);
2177 --m_nVisibleCount;
2180 if (bWasEditing)
2181 ActivateCell();
2184 //------------------------------------------------------------------------------
2185 long OSelectionBrowseBox::GetBrowseRow(long nRowId) const
2187 USHORT nCount(0);
2188 for(USHORT i = 0 ; i < nRowId ; ++i)
2190 if ( m_bVisibleRow[i] )
2191 ++nCount;
2193 return nCount;
2195 //------------------------------------------------------------------------------
2196 long OSelectionBrowseBox::GetRealRow(long nRowId) const
2198 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2199 long nErg=0,i;
2200 const long nCount = m_bVisibleRow.size();
2201 for(i=0;i < nCount; ++i)
2203 if(m_bVisibleRow[i])
2205 if(nErg++ == nRowId)
2206 break;
2209 DBG_ASSERT(nErg <= long(m_bVisibleRow.size()),"nErg kann nicht groesser als BROW_ROW_CNT sein!");
2210 return i;
2212 static long nVisibleRowMask[] =
2214 0x0001,
2215 0x0002,
2216 0x0004,
2217 0x0008,
2218 0x0010,
2219 0x0020,
2220 0x0040,
2221 0x0080,
2222 0x0100,
2223 0x0200,
2224 0x0400,
2225 0x0800
2227 //------------------------------------------------------------------------------
2228 sal_Int32 OSelectionBrowseBox::GetNoneVisibleRows() const
2230 sal_Int32 nErg(0);
2231 // only the first 11 row are interesting
2232 sal_Int32 nSize = sizeof(nVisibleRowMask) / sizeof(nVisibleRowMask[0]);
2233 for(sal_Int32 i=0;i<nSize;i++)
2235 if(!m_bVisibleRow[i])
2236 nErg |= nVisibleRowMask[i];
2238 return nErg;
2240 //------------------------------------------------------------------------------
2241 void OSelectionBrowseBox::SetNoneVisbleRow(long nRows)
2243 // only the first 11 row are interesting
2244 sal_Int32 nSize = sizeof(nVisibleRowMask) / sizeof(nVisibleRowMask[0]);
2245 for(sal_Int32 i=0;i< nSize;i++)
2246 m_bVisibleRow[i] = !(nRows & nVisibleRowMask[i]);
2248 //------------------------------------------------------------------------------
2249 String OSelectionBrowseBox::GetCellText(long nRow, sal_uInt16 nColId) const
2251 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2253 USHORT nPos = GetColumnPos(nColId);
2255 OTableFieldDescRef pEntry = getFields()[nPos-1];
2256 DBG_ASSERT(pEntry != NULL, "OSelectionBrowseBox::GetCellText : invalid column id, prepare for GPF ... ");
2257 if ( pEntry->IsEmpty() )
2258 return String();
2260 String aText;
2261 switch (nRow)
2263 case BROW_TABLE_ROW:
2264 aText = pEntry->GetAlias();
2265 break;
2266 case BROW_FIELD_ROW:
2268 String aField = pEntry->GetField();
2269 if (aField.GetChar(0) == '*') // * durch alias.* ersetzen
2271 aField = pEntry->GetAlias();
2272 if(aField.Len())
2273 aField += '.';
2274 aField += '*';
2276 aText = aField;
2277 } break;
2278 case BROW_ORDER_ROW:
2279 if (pEntry->GetOrderDir() != ORDER_NONE)
2280 aText = String(ModuleRes(STR_QUERY_SORTTEXT) ).GetToken(sal::static_int_cast< USHORT >(pEntry->GetOrderDir()));
2281 break;
2282 case BROW_VIS_ROW:
2283 break;
2284 case BROW_COLUMNALIAS_ROW:
2285 aText = pEntry->GetFieldAlias();
2286 break;
2287 case BROW_FUNCTION_ROW:
2288 // we always show the group function at first
2289 if ( pEntry->IsGroupBy() )
2290 aText = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1);
2291 else if ( pEntry->isNumericOrAggreateFunction() )
2292 aText = pEntry->GetFunction();
2293 break;
2294 default:
2295 aText = pEntry->GetCriteria(sal_uInt16(nRow - BROW_CRIT1_ROW));
2297 return aText;
2299 //------------------------------------------------------------------------------
2300 sal_Bool OSelectionBrowseBox::GetFunctionName(sal_uInt32 _nFunctionTokenId,String& rFkt)
2302 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2303 sal_Bool bErg=sal_True;
2304 String aText;
2305 switch(_nFunctionTokenId)
2307 case SQL_TOKEN_COUNT:
2308 rFkt = (m_pFunctionCell->GetEntryCount() < 3) ? m_pFunctionCell->GetEntry(1) : m_pFunctionCell->GetEntry(2);
2309 break;
2310 case SQL_TOKEN_AVG:
2311 rFkt = m_pFunctionCell->GetEntry(1);
2312 break;
2313 case SQL_TOKEN_MAX:
2314 rFkt = m_pFunctionCell->GetEntry(3);
2315 break;
2316 case SQL_TOKEN_MIN:
2317 rFkt = m_pFunctionCell->GetEntry(4);
2318 break;
2319 case SQL_TOKEN_SUM:
2320 rFkt = m_pFunctionCell->GetEntry(5);
2321 break;
2322 case SQL_TOKEN_EVERY:
2323 rFkt = m_pFunctionCell->GetEntry(6);
2324 break;
2325 case SQL_TOKEN_ANY:
2326 rFkt = m_pFunctionCell->GetEntry(7);
2327 break;
2328 case SQL_TOKEN_SOME:
2329 rFkt = m_pFunctionCell->GetEntry(8);
2330 break;
2331 case SQL_TOKEN_STDDEV_POP:
2332 rFkt = m_pFunctionCell->GetEntry(9);
2333 break;
2334 case SQL_TOKEN_STDDEV_SAMP:
2335 rFkt = m_pFunctionCell->GetEntry(10);
2336 break;
2337 case SQL_TOKEN_VAR_SAMP:
2338 rFkt = m_pFunctionCell->GetEntry(11);
2339 break;
2340 case SQL_TOKEN_VAR_POP:
2341 rFkt = m_pFunctionCell->GetEntry(12);
2342 break;
2343 case SQL_TOKEN_COLLECT:
2344 rFkt = m_pFunctionCell->GetEntry(13);
2345 break;
2346 case SQL_TOKEN_FUSION:
2347 rFkt = m_pFunctionCell->GetEntry(14);
2348 break;
2349 case SQL_TOKEN_INTERSECTION:
2350 rFkt = m_pFunctionCell->GetEntry(15);
2351 break;
2352 default:
2354 xub_StrLen nCount = m_aFunctionStrings.GetTokenCount();
2355 xub_StrLen i;
2356 for ( i = 0; i < nCount-1; i++) // Gruppierung wird nicht mit gez"ahlt
2358 if(rFkt.EqualsIgnoreCaseAscii(m_aFunctionStrings.GetToken(i)))
2360 rFkt = m_aFunctionStrings.GetToken(i);
2361 break;
2364 if(i == nCount-1)
2365 bErg = sal_False;
2369 return bErg;
2371 //------------------------------------------------------------------------------
2372 String OSelectionBrowseBox::GetCellContents(sal_Int32 nCellIndex, USHORT nColId)
2374 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2375 // DBG_ASSERT(nCellIndex < (GetRowCount()-1),"CellIndex ist zu gross");
2376 if ( GetCurColumnId() == nColId && !m_bInUndoMode )
2377 SaveModified();
2379 USHORT nPos = GetColumnPos(nColId);
2380 OTableFieldDescRef pEntry = getFields()[nPos - 1];
2381 DBG_ASSERT(pEntry != NULL, "OSelectionBrowseBox::GetCellContents : invalid column id, prepare for GPF ... ");
2383 switch (nCellIndex)
2385 case BROW_VIS_ROW :
2386 return pEntry->IsVisible() ? g_strOne : g_strZero;
2387 case BROW_ORDER_ROW:
2389 sal_uInt16 nIdx = m_pOrderCell->GetSelectEntryPos();
2390 if (nIdx == sal_uInt16(-1))
2391 nIdx = 0;
2392 return String(nIdx);
2394 default:
2395 return GetCellText(nCellIndex, nColId);
2399 //------------------------------------------------------------------------------
2400 void OSelectionBrowseBox::SetCellContents(sal_Int32 nRow, USHORT nColId, const String& strNewText)
2402 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2403 sal_Bool bWasEditing = IsEditing() && (GetCurColumnId() == nColId) && IsRowVisible(static_cast<USHORT>(nRow)) && (GetCurRow() == static_cast<USHORT>(GetBrowseRow(nRow)));
2404 if (bWasEditing)
2405 DeactivateCell();
2407 USHORT nPos = GetColumnPos(nColId);
2408 OTableFieldDescRef pEntry = getEntry(nPos - 1);
2409 DBG_ASSERT(pEntry != NULL, "OSelectionBrowseBox::SetCellContents : invalid column id, prepare for GPF ... ");
2412 switch (nRow)
2414 case BROW_VIS_ROW:
2415 pEntry->SetVisible(strNewText.Equals(g_strOne));
2416 break;
2417 case BROW_FIELD_ROW:
2418 pEntry->SetField(strNewText);
2419 break;
2420 case BROW_TABLE_ROW:
2421 pEntry->SetAlias(strNewText);
2422 break;
2423 case BROW_ORDER_ROW:
2425 sal_uInt16 nIdx = (sal_uInt16)strNewText.ToInt32();
2426 pEntry->SetOrderDir(EOrderDir(nIdx));
2427 } break;
2428 case BROW_COLUMNALIAS_ROW:
2429 pEntry->SetFieldAlias(strNewText);
2430 break;
2431 case BROW_FUNCTION_ROW:
2433 String sOldFunctionName = pEntry->GetFunction();
2434 String sGroupFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1);
2435 pEntry->SetFunction(strNewText);
2436 // first reset this two member
2437 sal_Int32 nFunctionType = pEntry->GetFunctionType();
2438 nFunctionType &= ~FKT_AGGREGATE;
2439 pEntry->SetFunctionType(nFunctionType);
2440 if ( pEntry->IsGroupBy() && !sGroupFunctionName.EqualsIgnoreCaseAscii(strNewText) )
2441 pEntry->SetGroupBy(sal_False);
2444 if ( sGroupFunctionName.EqualsIgnoreCaseAscii(strNewText) )
2445 pEntry->SetGroupBy(sal_True);
2446 else if ( strNewText.Len() )
2448 nFunctionType |= FKT_AGGREGATE;
2449 pEntry->SetFunctionType(nFunctionType);
2451 } break;
2452 default:
2453 pEntry->SetCriteria(sal_uInt16(nRow - BROW_CRIT1_ROW), strNewText);
2456 long nCellIndex = GetRealRow(nRow);
2457 if(IsRowVisible(static_cast<USHORT>(nRow)))
2458 RowModified(nCellIndex, nColId);
2460 // die entsprechende Feld-Beschreibung ist jetzt leer -> Visible auf sal_False (damit das konsistent mit normalen leeren Spalten ist)
2461 if (pEntry->IsEmpty())
2462 pEntry->SetVisible(sal_False);
2464 if (bWasEditing)
2465 ActivateCell(nCellIndex, nColId);
2467 static_cast<OQueryController&>(getDesignView()->getController()).setModified();
2469 //------------------------------------------------------------------------------
2470 sal_uInt32 OSelectionBrowseBox::GetTotalCellWidth(long nRow, sal_uInt16 nColId) const
2472 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2474 long nRowId = GetRealRow(nRow);
2475 if (nRowId == BROW_VIS_ROW)
2476 return CHECKBOX_SIZE;
2477 else
2478 return GetDataWindow().GetTextWidth(GetCellText(nRowId, nColId));
2481 //------------------------------------------------------------------------------
2482 void OSelectionBrowseBox::ColumnResized(sal_uInt16 nColId)
2484 if (static_cast<OQueryController&>(getDesignView()->getController()).isReadOnly())
2485 return;
2486 // The resizing of columns can't be suppressed (BrowseBox doesn't support that) so we have to do this
2487 // fake. It's not _that_ bad : the user may change column widths while in read-only mode to see all details
2488 // but the changes aren't permanent ...
2490 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2491 USHORT nPos = GetColumnPos(nColId);
2492 DBG_ASSERT(nPos <= getFields().size(),"ColumnResized:: nColId sollte nicht groesser als List::count sein!");
2493 OTableFieldDescRef pEntry = getEntry(nPos-1);
2494 DBG_ASSERT(pEntry.isValid(), "OSelectionBrowseBox::ColumnResized : keine FieldDescription !");
2495 static_cast<OQueryController&>(getDesignView()->getController()).setModified();
2496 EditBrowseBox::ColumnResized(nColId);
2498 if ( pEntry.isValid())
2500 if ( !m_bInUndoMode )
2502 // create the undo action
2503 OTabFieldSizedUndoAct* pUndo = new OTabFieldSizedUndoAct(this);
2504 pUndo->SetColumnPosition( nPos );
2505 pUndo->SetOriginalWidth(pEntry->GetColWidth());
2506 getDesignView()->getController().addUndoActionAndInvalidate(pUndo);
2508 pEntry->SetColWidth(sal_uInt16(GetColumnWidth(nColId)));
2512 //------------------------------------------------------------------------------
2513 sal_uInt32 OSelectionBrowseBox::GetTotalCellWidth(long nRowId, sal_uInt16 nColId)
2515 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2516 USHORT nPos = GetColumnPos(nColId);
2517 DBG_ASSERT((nPos == 0) || (nPos <= getFields().size()), "OSelectionBrowseBox::GetTotalCellWidth : invalid parameter nColId");
2519 OTableFieldDescRef pEntry = getFields()[nPos-1];
2520 DBG_ASSERT(pEntry.isValid(), "OSelectionBrowseBox::GetTotalCellWidth : invalid FieldDescription !");
2522 long nRow = GetRealRow(nRowId);
2523 String strText(GetCellText(nRow, nColId));
2524 return GetDataWindow().LogicToPixel(Size(GetDataWindow().GetTextWidth(strText),0)).Width();
2527 //------------------------------------------------------------------------------
2528 sal_uInt16 OSelectionBrowseBox::GetDefaultColumnWidth(const String& /*rName*/) const
2530 DBG_CHKTHIS(OSelectionBrowseBox,NULL);
2531 // die Baissklasse macht das von dem Text abhaengig, ich habe aber keine Spaltenueberschriften, daher haette ich
2532 // hier gern einen anderen Default-Wert
2533 return static_cast<sal_uInt16>(DEFAULT_SIZE);
2535 //------------------------------------------------------------------------------
2536 sal_Bool OSelectionBrowseBox::isCutAllowed()
2538 sal_Bool bCutAllowed = sal_False;
2539 long nRow = GetRealRow(GetCurRow());
2540 switch (nRow)
2542 case BROW_VIS_ROW:
2543 case BROW_ORDER_ROW:
2544 case BROW_TABLE_ROW:
2545 case BROW_FUNCTION_ROW:
2546 break;
2547 case BROW_FIELD_ROW:
2548 bCutAllowed = m_pFieldCell->GetSelected().Len() != 0;
2549 break;
2550 default:
2551 bCutAllowed = m_pTextCell->GetSelected().Len() != 0;
2552 break;
2554 return bCutAllowed;
2556 // -----------------------------------------------------------------------------
2557 void OSelectionBrowseBox::cut()
2559 String sOldValue = GetCellContents(GetRealRow(GetCurRow()),GetCurColumnId());
2560 long nRow = GetRealRow(GetCurRow());
2561 switch (nRow)
2563 case BROW_FIELD_ROW:
2564 m_pFieldCell->Cut();
2565 m_pFieldCell->SetModifyFlag();
2566 break;
2567 default:
2568 m_pTextCell->Cut();
2569 m_pTextCell->SetModifyFlag();
2571 SaveModified();
2572 RowModified(GetBrowseRow(nRow), GetCurColumnId());
2574 invalidateUndoRedo();
2576 // -----------------------------------------------------------------------------
2577 void OSelectionBrowseBox::paste()
2579 long nRow = GetRealRow(GetCurRow());
2580 switch (nRow)
2582 case BROW_FIELD_ROW:
2583 m_pFieldCell->Paste();
2584 m_pFieldCell->SetModifyFlag();
2585 break;
2586 default:
2587 m_pTextCell->Paste();
2588 m_pTextCell->SetModifyFlag();
2590 RowModified(GetBrowseRow(nRow), GetCurColumnId());
2591 invalidateUndoRedo();
2593 // -----------------------------------------------------------------------------
2594 sal_Bool OSelectionBrowseBox::isPasteAllowed()
2596 sal_Bool bPasteAllowed = sal_True;
2597 long nRow = GetRealRow(GetCurRow());
2598 switch (nRow)
2600 case BROW_VIS_ROW:
2601 case BROW_ORDER_ROW:
2602 case BROW_TABLE_ROW:
2603 case BROW_FUNCTION_ROW:
2604 bPasteAllowed = sal_False;
2605 break;
2607 return bPasteAllowed;
2609 // -----------------------------------------------------------------------------
2610 sal_Bool OSelectionBrowseBox::isCopyAllowed()
2612 return isCutAllowed();
2614 // -----------------------------------------------------------------------------
2615 void OSelectionBrowseBox::copy()
2617 long nRow = GetRealRow(GetCurRow());
2618 switch (nRow)
2620 case BROW_FIELD_ROW:
2621 m_pFieldCell->Copy();
2622 break;
2623 default:
2624 m_pTextCell->Copy();
2627 // -----------------------------------------------------------------------------
2628 void OSelectionBrowseBox::appendUndoAction(const String& _rOldValue,const String& _rNewValue,sal_Int32 _nRow,sal_Bool& _bListAction)
2630 if ( !m_bInUndoMode && !_rNewValue.Equals(_rOldValue) )
2632 if ( !_bListAction )
2634 _bListAction = sal_True;
2635 static_cast<OQueryController&>(getDesignView()->getController()).getUndoMgr()->EnterListAction(String(),String());
2637 appendUndoAction(_rOldValue,_rNewValue,_nRow);
2640 // -----------------------------------------------------------------------------
2641 void OSelectionBrowseBox::appendUndoAction(const String& _rOldValue,const String& _rNewValue,sal_Int32 _nRow)
2643 if ( !m_bInUndoMode && !_rNewValue.Equals(_rOldValue) )
2645 OTabFieldCellModifiedUndoAct* pUndoAct = new OTabFieldCellModifiedUndoAct(this);
2646 pUndoAct->SetCellIndex(_nRow);
2647 OSL_ENSURE(GetColumnPos(GetCurColumnId()) != BROWSER_INVALIDID,"Current position isn't valid!");
2648 pUndoAct->SetColumnPosition( GetColumnPos(GetCurColumnId()) );
2649 pUndoAct->SetCellContents(_rOldValue);
2650 getDesignView()->getController().addUndoActionAndInvalidate(pUndoAct);
2653 // -----------------------------------------------------------------------------
2654 IMPL_LINK(OSelectionBrowseBox, OnInvalidateTimer, void*, EMPTYARG)
2656 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature(SID_CUT);
2657 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature(SID_COPY);
2658 static_cast<OQueryController&>(getDesignView()->getController()).InvalidateFeature(SID_PASTE);
2659 if(!m_bStopTimer)
2660 m_timerInvalidate.Start();
2661 return 0L;
2663 // -----------------------------------------------------------------------------
2664 void OSelectionBrowseBox::stopTimer()
2666 m_bStopTimer = sal_True;
2667 if (m_timerInvalidate.IsActive())
2668 m_timerInvalidate.Stop();
2670 // -----------------------------------------------------------------------------
2671 void OSelectionBrowseBox::startTimer()
2673 m_bStopTimer = sal_False;
2674 if (!m_timerInvalidate.IsActive())
2675 m_timerInvalidate.Start();
2677 // -----------------------------------------------------------------------------
2678 OTableFields& OSelectionBrowseBox::getFields() const
2680 OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
2681 return rController.getTableFieldDesc();
2683 // -----------------------------------------------------------------------------
2684 void OSelectionBrowseBox::enableControl(const OTableFieldDescRef& _rEntry,Window* _pControl)
2686 BOOL bEnable = !_rEntry->isCondition();
2687 _pControl->Enable(bEnable);
2688 _pControl->EnableInput(bEnable);
2690 // -----------------------------------------------------------------------------
2691 void OSelectionBrowseBox::setTextCellContext(const OTableFieldDescRef& _rEntry,const String& _sText,ULONG _nHelpId)
2693 m_pTextCell->SetText(_sText);
2694 m_pTextCell->ClearModifyFlag();
2695 if (!m_pTextCell->HasFocus())
2696 m_pTextCell->GrabFocus();
2698 enableControl(_rEntry,m_pTextCell);
2700 if (m_pTextCell->GetHelpId() != _nHelpId)
2701 // da TextCell in verschiedenen Kontexten verwendet wird, muss ich den gecachten HelpText loeschen
2702 m_pTextCell->SetHelpText(String());
2703 m_pTextCell->SetHelpId(_nHelpId);
2705 // -----------------------------------------------------------------------------
2706 void OSelectionBrowseBox::invalidateUndoRedo()
2708 OQueryController& rController = static_cast<OQueryController&>(getDesignView()->getController());
2709 rController.InvalidateFeature( ID_BROWSER_UNDO );
2710 rController.InvalidateFeature( ID_BROWSER_REDO );
2711 rController.InvalidateFeature( ID_BROWSER_QUERY_EXECUTE );
2713 // -----------------------------------------------------------------------------
2714 OTableFieldDescRef OSelectionBrowseBox::getEntry(OTableFields::size_type _nPos)
2716 // we have to check if we need a new entry at this position
2717 OTableFields& aFields = getFields();
2718 OSL_ENSURE(aFields.size() > _nPos,"ColID is to great!");
2720 OTableFieldDescRef pEntry = aFields[_nPos];
2721 OSL_ENSURE(pEntry.isValid(),"Invalid entry!");
2722 if ( !pEntry.isValid() )
2724 pEntry = new OTableFieldDesc();
2725 pEntry->SetColumnId(
2726 GetColumnId(sal::static_int_cast< USHORT >(_nPos+1)));
2727 aFields[_nPos] = pEntry;
2729 return pEntry;
2731 // -----------------------------------------------------------------------------
2732 void OSelectionBrowseBox::GetFocus()
2734 if(!IsEditing() && !m_bWasEditing)
2735 ActivateCell();
2736 EditBrowseBox::GetFocus();
2738 // -----------------------------------------------------------------------------
2739 void OSelectionBrowseBox::DeactivateCell(sal_Bool _bUpdate)
2741 m_bWasEditing = sal_True;
2742 EditBrowseBox::DeactivateCell(_bUpdate);
2743 m_bWasEditing = sal_False;
2745 // -----------------------------------------------------------------------------
2746 ::rtl::OUString OSelectionBrowseBox::GetRowDescription( sal_Int32 _nRow ) const
2748 String aLabel(ModuleRes(STR_QUERY_HANDLETEXT));
2750 // ab BROW_CRIT2_ROW werden alle Zeilen mit "oder" angegeben
2751 xub_StrLen nToken = (xub_StrLen) (_nRow >= GetBrowseRow(BROW_CRIT2_ROW))
2753 xub_StrLen(BROW_CRIT2_ROW) : xub_StrLen(GetRealRow(_nRow));
2754 return ::rtl::OUString(aLabel.GetToken(nToken));
2756 // -----------------------------------------------------------------------------
2757 ::rtl::OUString OSelectionBrowseBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eObjType,sal_Int32 _nPosition) const
2759 ::rtl::OUString sRetText;
2760 switch( _eObjType )
2762 case ::svt::BBTYPE_ROWHEADERCELL:
2763 sRetText = GetRowDescription(_nPosition);
2764 break;
2765 default:
2766 sRetText = EditBrowseBox::GetAccessibleObjectDescription(_eObjType,_nPosition);
2768 return sRetText;
2770 // -----------------------------------------------------------------------------
2771 sal_Bool OSelectionBrowseBox::fillEntryTable(OTableFieldDescRef& _pEntry,const ::rtl::OUString& _sTableName)
2773 sal_Bool bRet = sal_False;
2774 OJoinTableView::OTableWindowMap* pTabWinList = getDesignView()->getTableView()->GetTabWinMap();
2775 if (pTabWinList)
2777 OJoinTableView::OTableWindowMapIterator aIter = pTabWinList->find(_sTableName);
2778 if(aIter != pTabWinList->end())
2780 OQueryTableWindow* pEntryTab = static_cast<OQueryTableWindow*>(aIter->second);
2781 if (pEntryTab)
2783 _pEntry->SetTable(pEntryTab->GetTableName());
2784 _pEntry->SetTabWindow(pEntryTab);
2785 bRet = sal_True;
2789 return bRet;
2791 // -----------------------------------------------------------------------------
2792 void OSelectionBrowseBox::setFunctionCell(OTableFieldDescRef& _pEntry)
2794 Reference< XConnection> xConnection = static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
2795 if ( xConnection.is() )
2797 // Diese Funktionen stehen nur unter CORE zur Verfügung
2798 if ( lcl_SupportsCoreSQLGrammar(xConnection) )
2800 // if we have an asterix, no other function than count is allowed
2801 m_pFunctionCell->Clear();
2802 m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(0));
2803 if ( isFieldNameAsterix(_pEntry->GetField()) )
2804 m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(2)); // 2 -> COUNT
2805 else
2807 xub_StrLen nCount = m_aFunctionStrings.GetTokenCount();
2808 if ( _pEntry->isNumeric() )
2809 --nCount;
2810 for (xub_StrLen nIdx = 1; nIdx < nCount; nIdx++)
2811 m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(nIdx));
2814 if ( _pEntry->IsGroupBy() )
2816 OSL_ENSURE(!_pEntry->isNumeric(),"Not allowed to combine group by and numeric values!");
2817 m_pFunctionCell->SelectEntry(m_pFunctionCell->GetEntry(m_pFunctionCell->GetEntryCount() - 1));
2819 else if ( m_pFunctionCell->GetEntryPos(String(_pEntry->GetFunction())) != COMBOBOX_ENTRY_NOTFOUND )
2820 m_pFunctionCell->SelectEntry(String(_pEntry->GetFunction()));
2821 else
2822 m_pFunctionCell->SelectEntryPos(0);
2824 enableControl(_pEntry,m_pFunctionCell);
2826 else
2828 // nur COUNT(*) erlaubt
2829 sal_Bool bCountRemoved = !isFieldNameAsterix(_pEntry->GetField());
2830 if ( bCountRemoved )
2831 m_pFunctionCell->RemoveEntry(1);
2833 if ( !bCountRemoved && m_pFunctionCell->GetEntryCount() < 2)
2834 m_pFunctionCell->InsertEntry(m_aFunctionStrings.GetToken(2)); // 2 -> COUNT
2836 if(m_pFunctionCell->GetEntryPos(String(_pEntry->GetFunction())) != COMBOBOX_ENTRY_NOTFOUND)
2837 m_pFunctionCell->SelectEntry(_pEntry->GetFunction());
2838 else
2839 m_pFunctionCell->SelectEntryPos(0);
2843 // -----------------------------------------------------------------------------
2844 Reference< XAccessible > OSelectionBrowseBox::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
2846 OTableFieldDescRef pEntry = NULL;
2847 if(getFields().size() > sal_uInt16(_nColumnPos - 1))
2848 pEntry = getFields()[_nColumnPos - 1];
2850 if ( _nRow == BROW_VIS_ROW && pEntry.isValid() )
2851 return EditBrowseBox::CreateAccessibleCheckBoxCell( _nRow, _nColumnPos,pEntry->IsVisible() ? STATE_CHECK : STATE_NOCHECK );
2853 return EditBrowseBox::CreateAccessibleCell( _nRow, _nColumnPos );
2855 // -----------------------------------------------------------------------------
2856 bool OSelectionBrowseBox::HasFieldByAliasName(const ::rtl::OUString& rFieldName, OTableFieldDescRef& rInfo) const
2858 OTableFields& aFields = getFields();
2859 OTableFields::iterator aIter = aFields.begin();
2860 OTableFields::iterator aEnd = aFields.end();
2862 for(;aIter != aEnd;++aIter)
2864 if ( (*aIter)->GetFieldAlias() == rFieldName )
2866 rInfo = *aIter;
2867 break;
2870 return aIter != aEnd;
2872 // -----------------------------------------------------------------------------