tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / dbgui / foptmgr.cxx
blobdecaa622ba63d0431b9e02affff1ae7b96da6a90
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 <osl/diagnose.h>
22 #include <rangeutl.hxx>
23 #include <dbdata.hxx>
24 #include <viewdata.hxx>
25 #include <document.hxx>
26 #include <queryparam.hxx>
27 #include <globalnames.hxx>
29 #include <foptmgr.hxx>
30 #include <formula/funcutl.hxx>
32 // ScFilterOptionsMgr (.ui's option helper)
34 ScFilterOptionsMgr::ScFilterOptionsMgr(
35 ScViewData* ptrViewData,
36 const ScQueryParam& refQueryData,
37 weld::CheckButton* refBtnCase,
38 weld::CheckButton* refBtnRegExp,
39 weld::CheckButton* refBtnHeader,
40 weld::CheckButton* refBtnUnique,
41 weld::CheckButton* refBtnCopyResult,
42 weld::CheckButton* refBtnDestPers,
43 weld::ComboBox* refLbCopyArea,
44 formula::RefEdit* refEdCopyArea,
45 formula::RefButton* refRbCopyArea,
46 weld::Label* refFtDbAreaLabel,
47 weld::Label* refFtDbArea,
48 const OUString& refStrUndefined )
50 : pViewData ( ptrViewData ),
51 pDoc ( ptrViewData ? &ptrViewData->GetDocument() : nullptr ),
52 pBtnCase ( refBtnCase ),
53 pBtnRegExp ( refBtnRegExp ),
54 pBtnHeader ( refBtnHeader ),
55 pBtnUnique ( refBtnUnique ),
56 pBtnCopyResult ( refBtnCopyResult ),
57 pBtnDestPers ( refBtnDestPers ),
58 pLbCopyArea ( refLbCopyArea ),
59 pEdCopyArea ( refEdCopyArea ),
60 pRbCopyArea ( refRbCopyArea ),
61 pFtDbAreaLabel ( refFtDbAreaLabel ),
62 pFtDbArea ( refFtDbArea ),
63 rStrUndefined ( refStrUndefined ),
64 rQueryData ( refQueryData )
66 Init();
69 void ScFilterOptionsMgr::Init()
71 //moggi:TODO
72 OSL_ENSURE( pViewData && pDoc, "Init failed :-/" );
74 pLbCopyArea->connect_changed( LINK( this, ScFilterOptionsMgr, LbAreaSelHdl ) );
75 pEdCopyArea->SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdAreaModifyHdl ) );
76 pBtnCopyResult->connect_toggled( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
78 pBtnCase->set_active( rQueryData.bCaseSens );
79 pBtnHeader->set_active( rQueryData.bHasHeader );
80 pBtnRegExp->set_active( rQueryData.eSearchType == utl::SearchParam::SearchType::Regexp );
81 pBtnUnique->set_active( !rQueryData.bDuplicate );
83 if ( pViewData && pDoc )
85 OUString theAreaStr;
86 ScRange theCurArea ( ScAddress( rQueryData.nCol1,
87 rQueryData.nRow1,
88 pViewData->GetTabNo() ),
89 ScAddress( rQueryData.nCol2,
90 rQueryData.nRow2,
91 pViewData->GetTabNo() ) );
92 ScDBCollection* pDBColl = pDoc->GetDBCollection();
93 OUString theDbArea;
94 OUString theDbName(STR_DB_LOCAL_NONAME);
95 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
97 theAreaStr = theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv);
99 // fill the target area list
101 pLbCopyArea->clear();
102 pLbCopyArea->append_text(rStrUndefined);
104 ScAreaNameIterator aIter( *pDoc );
105 OUString aName;
106 ScRange aRange;
107 while ( aIter.Next( aName, aRange ) )
109 OUString aRefStr(aRange.aStart.Format(ScRefFlags::ADDR_ABS_3D, pDoc, eConv));
110 pLbCopyArea->append(aRefStr, aName);
113 pBtnDestPers->set_active(true); // always on when called
114 pLbCopyArea->set_active( 0 );
115 pEdCopyArea->SetText( OUString() );
118 * Check whether the transferred area is a database area:
121 theDbArea = theAreaStr;
123 if ( pDBColl )
125 ScAddress& rStart = theCurArea.aStart;
126 ScAddress& rEnd = theCurArea.aEnd;
127 const ScDBData* pDBData = pDBColl->GetDBAtArea(
128 rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row());
130 if ( pDBData )
132 pBtnHeader->set_active( pDBData->HasHeader() );
133 theDbName = pDBData->GetName();
135 pBtnHeader->set_sensitive(theDbName == STR_DB_LOCAL_NONAME);
139 if ( theDbName != STR_DB_LOCAL_NONAME )
141 theDbArea += " (" + theDbName + ")";
143 pFtDbArea->set_label( theDbArea );
145 else
147 pFtDbAreaLabel->set_label( OUString() );
148 pFtDbArea->set_label( OUString() );
151 // position to copy to:
153 if ( !rQueryData.bInplace )
155 OUString aString =
156 ScAddress( rQueryData.nDestCol,
157 rQueryData.nDestRow,
158 rQueryData.nDestTab
159 ).Format(ScRefFlags::ADDR_ABS_3D, pDoc, eConv);
161 pBtnCopyResult->set_active(true);
162 pEdCopyArea->SetText( aString );
163 EdAreaModifyHdl( *pEdCopyArea );
164 pLbCopyArea->set_sensitive(true);
165 pEdCopyArea->GetWidget()->set_sensitive(true);
166 pRbCopyArea->GetWidget()->set_sensitive(true);
167 pBtnDestPers->set_sensitive(true);
169 else
171 pBtnCopyResult->set_active( false );
172 pEdCopyArea->SetText( OUString() );
173 pLbCopyArea->set_sensitive(false);
174 pEdCopyArea->GetWidget()->set_sensitive(false);
175 pRbCopyArea->GetWidget()->set_sensitive(false);
176 pBtnDestPers->set_sensitive(false);
179 else
180 pEdCopyArea->SetText( OUString() );
183 bool ScFilterOptionsMgr::VerifyPosStr( const OUString& rPosStr ) const
185 OUString aPosStr( rPosStr );
186 sal_Int32 nColonPos = aPosStr.indexOf( ':' );
188 if ( -1 != nColonPos )
189 aPosStr = aPosStr.copy( 0, nColonPos );
191 ScRefFlags nResult = ScAddress().Parse( aPosStr, *pDoc, pDoc->GetAddressConvention() );
193 return (nResult & ScRefFlags::VALID) == ScRefFlags::VALID;
196 // Handler:
198 IMPL_LINK( ScFilterOptionsMgr, LbAreaSelHdl, weld::ComboBox&, rLb, void )
200 if ( &rLb == pLbCopyArea )
202 OUString aString;
203 const sal_Int32 nSelPos = pLbCopyArea->get_active();
205 if ( nSelPos > 0 )
206 aString = pLbCopyArea->get_id(nSelPos);
208 pEdCopyArea->SetText( aString );
212 IMPL_LINK( ScFilterOptionsMgr, EdAreaModifyHdl, formula::RefEdit&, rEd, void )
214 if ( &rEd != pEdCopyArea )
215 return;
217 OUString theCurPosStr = rEd.GetText();
218 ScRefFlags nResult = ScAddress().Parse( theCurPosStr, *pDoc, pDoc->GetAddressConvention() );
220 if ( (nResult & ScRefFlags::VALID) == ScRefFlags::VALID)
222 const sal_Int32 nCount = pLbCopyArea->get_count();
224 for ( sal_Int32 i=2; i<nCount; ++i )
226 OUString aStr = pLbCopyArea->get_id(i);
227 if (theCurPosStr == aStr)
229 pLbCopyArea->set_active( i );
230 return;
235 pLbCopyArea->set_active( 0 );
238 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, weld::Toggleable&, rBox, void )
240 if ( &rBox != pBtnCopyResult )
241 return;
243 if ( rBox.get_active() )
245 pBtnDestPers->set_sensitive(true);
246 pLbCopyArea->set_sensitive(true);
247 pEdCopyArea->GetWidget()->set_sensitive(true);
248 pRbCopyArea->GetWidget()->set_sensitive(true);
249 pEdCopyArea->GrabFocus();
251 else
253 pBtnDestPers->set_sensitive(false);
254 pLbCopyArea->set_sensitive(false);
255 pEdCopyArea->GetWidget()->set_sensitive(false);
256 pRbCopyArea->GetWidget()->set_sensitive(false);
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */