fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / queryorder.cxx
blobd04714332942d387eaf14894ab3935c66f8c6677
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "dbu_tbl.hrc"
21 #include "queryorder.hxx"
22 #include "dbustrings.hrc"
23 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
24 #include <com/sun/star/sdbc/ColumnSearch.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <tools/debug.hxx>
27 #include "moduledbu.hxx"
28 #include <connectivity/sqliterator.hxx>
29 #include <connectivity/dbtools.hxx>
30 #include <comphelper/extract.hxx>
31 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
32 #include <tools/diagnose_ex.h>
33 #include <vcl/settings.hxx>
34 #include <algorithm>
36 using namespace dbaui;
37 using namespace connectivity;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::container;
40 using namespace ::com::sun::star::util;
41 using namespace ::com::sun::star::sdb;
42 using namespace ::com::sun::star::sdbc;
43 using namespace ::com::sun::star::sdbcx;
44 using namespace ::com::sun::star::beans;
47 DlgOrderCrit::DlgOrderCrit(vcl::Window * pParent,
48 const Reference< XConnection>& _rxConnection,
49 const Reference< XSingleSelectQueryComposer >& _rxComposer,
50 const Reference< XNameAccess>& _rxCols)
51 : ModalDialog(pParent, "SortDialog", "dbaccess/ui/sortdialog.ui")
52 , aSTR_NOENTRY(ModuleRes(STR_VALUE_NONE))
53 , m_xQueryComposer(_rxComposer)
54 , m_xColumns(_rxCols)
55 , m_xConnection(_rxConnection)
58 get(m_pLB_ORDERFIELD1, "field1");
59 get(m_pLB_ORDERVALUE1, "value1");
60 get(m_pLB_ORDERFIELD2, "field2");
61 get(m_pLB_ORDERVALUE2, "value2");
62 get(m_pLB_ORDERFIELD3, "field3");
63 get(m_pLB_ORDERVALUE3, "value3");
65 AllSettings aSettings( GetSettings() );
66 StyleSettings aStyle( aSettings.GetStyleSettings() );
67 aStyle.SetAutoMnemonic( false );
68 aSettings.SetStyleSettings( aStyle );
69 SetSettings( aSettings );
71 m_aColumnList[0] = m_pLB_ORDERFIELD1;
72 m_aColumnList[1] = m_pLB_ORDERFIELD2;
73 m_aColumnList[2] = m_pLB_ORDERFIELD3;
75 m_aValueList[0] = m_pLB_ORDERVALUE1;
76 m_aValueList[1] = m_pLB_ORDERVALUE2;
77 m_aValueList[2] = m_pLB_ORDERVALUE3;
79 for (int j=0; j < DOG_ROWS; ++j)
81 m_aColumnList[j]->InsertEntry( aSTR_NOENTRY );
84 for (int j=0; j < DOG_ROWS; ++j)
86 m_aColumnList[j]->SelectEntryPos(0);
87 m_aValueList[j]->SelectEntryPos(0);
89 try
91 // ... also the remaining fields
92 Sequence< OUString> aNames = m_xColumns->getElementNames();
93 const OUString* pIter = aNames.getConstArray();
94 const OUString* pEnd = pIter + aNames.getLength();
95 Reference<XPropertySet> xColumn;
96 for(;pIter != pEnd;++pIter)
98 xColumn.set(m_xColumns->getByName(*pIter),UNO_QUERY);
99 OSL_ENSURE(xColumn.is(),"Column is null!");
100 if ( xColumn.is() )
102 sal_Int32 nDataType = 0;
103 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
104 sal_Int32 eColumnSearch = dbtools::getSearchColumnFlag(m_xConnection,nDataType);
105 if(eColumnSearch != ColumnSearch::NONE)
107 for (int j=0; j < DOG_ROWS; ++j)
109 m_aColumnList[j]->InsertEntry(*pIter);
115 m_sOrgOrder = m_xQueryComposer->getOrder();
116 impl_initializeOrderList_nothrow();
118 catch(const Exception&)
120 DBG_UNHANDLED_EXCEPTION();
122 EnableLines();
124 m_pLB_ORDERFIELD1->SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
125 m_pLB_ORDERFIELD2->SetSelectHdl(LINK(this,DlgOrderCrit,FieldListSelectHdl));
128 DlgOrderCrit::~DlgOrderCrit()
130 disposeOnce();
133 void DlgOrderCrit::dispose()
135 m_pLB_ORDERFIELD1.clear();
136 m_pLB_ORDERVALUE1.clear();
137 m_pLB_ORDERFIELD2.clear();
138 m_pLB_ORDERVALUE2.clear();
139 m_pLB_ORDERFIELD3.clear();
140 m_pLB_ORDERVALUE3.clear();
141 for (auto a : m_aColumnList) a.clear();
142 for (auto a : m_aValueList) a.clear();
143 ModalDialog::dispose();
146 IMPL_LINK( DlgOrderCrit, FieldListSelectHdl, ListBox *, /*pListBox*/ )
148 EnableLines();
149 return 0;
152 void DlgOrderCrit::impl_initializeOrderList_nothrow()
156 const OUString sNameProperty = "Name";
157 const OUString sAscendingProperty = "IsAscending";
159 Reference< XIndexAccess > xOrderColumns( m_xQueryComposer->getOrderColumns(), UNO_QUERY_THROW );
160 sal_Int32 nColumns = xOrderColumns->getCount();
161 if ( nColumns > DOG_ROWS )
162 nColumns = DOG_ROWS;
164 for ( sal_Int32 i = 0; i < nColumns; ++i )
166 Reference< XPropertySet > xColumn( xOrderColumns->getByIndex( i ), UNO_QUERY_THROW );
168 OUString sColumnName;
169 bool bIsAscending( true );
171 xColumn->getPropertyValue( sNameProperty ) >>= sColumnName;
172 xColumn->getPropertyValue( sAscendingProperty ) >>= bIsAscending;
174 m_aColumnList[i]->SelectEntry( sColumnName );
175 m_aValueList[i]->SelectEntryPos( bIsAscending ? 0 : 1 );
178 catch( const Exception& )
180 DBG_UNHANDLED_EXCEPTION();
184 void DlgOrderCrit::EnableLines()
187 if ( m_pLB_ORDERFIELD1->GetSelectEntryPos() == 0 )
189 m_pLB_ORDERFIELD2->Disable();
190 m_pLB_ORDERVALUE2->Disable();
192 m_pLB_ORDERFIELD2->SelectEntryPos( 0 );
193 m_pLB_ORDERVALUE2->SelectEntryPos( 0 );
195 else
197 m_pLB_ORDERFIELD2->Enable();
198 m_pLB_ORDERVALUE2->Enable();
201 if ( m_pLB_ORDERFIELD2->GetSelectEntryPos() == 0 )
203 m_pLB_ORDERFIELD3->Disable();
204 m_pLB_ORDERVALUE3->Disable();
206 m_pLB_ORDERFIELD3->SelectEntryPos( 0 );
207 m_pLB_ORDERVALUE3->SelectEntryPos( 0 );
209 else
211 m_pLB_ORDERFIELD3->Enable();
212 m_pLB_ORDERVALUE3->Enable();
216 OUString DlgOrderCrit::GetOrderList( ) const
218 Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
219 OUString sQuote = xMetaData.is() ? xMetaData->getIdentifierQuoteString() : OUString();
220 static const char sDESC[] = " DESC ";
221 static const char sASC[] = " ASC ";
223 Reference< XNameAccess> xColumns = Reference< XColumnsSupplier >(m_xQueryComposer,UNO_QUERY)->getColumns();
225 OUString sOrder;
226 for( sal_uInt16 i=0 ; i<DOG_ROWS; i++ )
228 if(m_aColumnList[i]->GetSelectEntryPos() != 0)
230 if(!sOrder.isEmpty())
231 sOrder += ",";
233 OUString sName = m_aColumnList[i]->GetSelectEntry();
234 sOrder += ::dbtools::quoteName(sQuote,sName);
235 if(m_aValueList[i]->GetSelectEntryPos())
236 sOrder += sDESC;
237 else
238 sOrder += sASC;
241 return sOrder;
244 void DlgOrderCrit::BuildOrderPart()
246 m_xQueryComposer->setOrder(GetOrderList());
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */