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