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