LibreOffice Module sc (master)  1
foptmgr.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
21 
22 #include <rangeutl.hxx>
23 #include <dbdata.hxx>
24 #include <viewdata.hxx>
25 #include <document.hxx>
26 #include <queryparam.hxx>
27 #include <globalnames.hxx>
28 
29 #include <foptmgr.hxx>
30 #include <formula/funcutl.hxx>
31 
32 // ScFilterOptionsMgr (.ui's option helper)
33 
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 )
49 
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 )
65 {
66  Init();
67 }
68 
70 {
71 //moggi:TODO
72  OSL_ENSURE( pViewData && pDoc, "Init failed :-/" );
73 
74  pLbCopyArea->connect_changed( LINK( this, ScFilterOptionsMgr, LbAreaSelHdl ) );
75  pEdCopyArea->SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdAreaModifyHdl ) );
76  pBtnCopyResult->connect_toggled( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
77 
82 
83  if ( pViewData && pDoc )
84  {
85  OUString theAreaStr;
86  ScRange theCurArea ( ScAddress( rQueryData.nCol1,
88  pViewData->GetTabNo() ),
91  pViewData->GetTabNo() ) );
92  ScDBCollection* pDBColl = pDoc->GetDBCollection();
93  OUString theDbArea;
94  OUString theDbName(STR_DB_LOCAL_NONAME);
96 
97  theAreaStr = theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv);
98 
99  // fill the target area list
100 
101  pLbCopyArea->clear();
103 
104  ScAreaNameIterator aIter( *pDoc );
105  OUString aName;
106  ScRange aRange;
107  while ( aIter.Next( aName, aRange ) )
108  {
109  OUString aRefStr(aRange.aStart.Format(ScRefFlags::ADDR_ABS_3D, pDoc, eConv));
110  pLbCopyArea->append(aRefStr, aName);
111  }
112 
113  pBtnDestPers->set_active(true); // always on when called
114  pLbCopyArea->set_active( 0 );
115  pEdCopyArea->SetText( OUString() );
116 
117  /*
118  * Check whether the transferred area is a database area:
119  */
120 
121  theDbArea = theAreaStr;
122 
123  if ( pDBColl )
124  {
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());
129 
130  if ( pDBData )
131  {
132  pBtnHeader->set_active( pDBData->HasHeader() );
133  theDbName = pDBData->GetName();
134 
136  }
137  }
138 
139  if ( theDbName != STR_DB_LOCAL_NONAME )
140  {
141  theDbArea += " (" + theDbName + ")";
142 
143  pFtDbArea->set_label( theDbArea );
144  }
145  else
146  {
147  pFtDbAreaLabel->set_label( OUString() );
148  pFtDbArea->set_label( OUString() );
149  }
150 
151  // position to copy to:
152 
153  if ( !rQueryData.bInplace )
154  {
155  OUString aString =
160 
161  pBtnCopyResult->set_active(true);
162  pEdCopyArea->SetText( aString );
163  EdAreaModifyHdl( *pEdCopyArea );
164  pLbCopyArea->set_sensitive(true);
168  }
169  else
170  {
171  pBtnCopyResult->set_active( false );
172  pEdCopyArea->SetText( OUString() );
173  pLbCopyArea->set_sensitive(false);
176  pBtnDestPers->set_sensitive(false);
177  }
178  }
179  else
180  pEdCopyArea->SetText( OUString() );
181 }
182 
183 bool ScFilterOptionsMgr::VerifyPosStr( const OUString& rPosStr ) const
184 {
185  OUString aPosStr( rPosStr );
186  sal_Int32 nColonPos = aPosStr.indexOf( ':' );
187 
188  if ( -1 != nColonPos )
189  aPosStr = aPosStr.copy( 0, nColonPos );
190 
191  ScRefFlags nResult = ScAddress().Parse( aPosStr, *pDoc, pDoc->GetAddressConvention() );
192 
193  return (nResult & ScRefFlags::VALID) == ScRefFlags::VALID;
194 }
195 
196 // Handler:
197 
198 IMPL_LINK( ScFilterOptionsMgr, LbAreaSelHdl, weld::ComboBox&, rLb, void )
199 {
200  if ( &rLb == pLbCopyArea )
201  {
202  OUString aString;
203  const sal_Int32 nSelPos = pLbCopyArea->get_active();
204 
205  if ( nSelPos > 0 )
206  aString = pLbCopyArea->get_id(nSelPos);
207 
208  pEdCopyArea->SetText( aString );
209  }
210 }
211 
212 IMPL_LINK( ScFilterOptionsMgr, EdAreaModifyHdl, formula::RefEdit&, rEd, void )
213 {
214  if ( &rEd != pEdCopyArea )
215  return;
216 
217  OUString theCurPosStr = rEd.GetText();
218  ScRefFlags nResult = ScAddress().Parse( theCurPosStr, *pDoc, pDoc->GetAddressConvention() );
219 
220  if ( (nResult & ScRefFlags::VALID) == ScRefFlags::VALID)
221  {
222  const sal_Int32 nCount = pLbCopyArea->get_count();
223 
224  for ( sal_Int32 i=2; i<nCount; ++i )
225  {
226  OUString aStr = pLbCopyArea->get_id(i);
227  if (theCurPosStr == aStr)
228  {
229  pLbCopyArea->set_active( i );
230  return;
231  }
232  }
233 
234  }
235  pLbCopyArea->set_active( 0 );
236 }
237 
238 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, weld::Toggleable&, rBox, void )
239 {
240  if ( &rBox != pBtnCopyResult )
241  return;
242 
243  if ( rBox.get_active() )
244  {
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();
250  }
251  else
252  {
253  pBtnDestPers->set_sensitive(false);
254  pLbCopyArea->set_sensitive(false);
255  pEdCopyArea->GetWidget()->set_sensitive(false);
256  pRbCopyArea->GetWidget()->set_sensitive(false);
257  }
258 }
259 
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Next(OUString &rName, ScRange &rRange)
Definition: rangeutl.cxx:1007
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2074
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:825
ScAddress aStart
Definition: address.hxx:497
SCROW Row() const
Definition: address.hxx:274
weld::CheckButton * pBtnDestPers
Definition: foptmgr.hxx:62
bool HasHeader() const
Definition: dbdata.hxx:130
weld::CheckButton * pBtnRegExp
Definition: foptmgr.hxx:58
formula::RefButton * pRbCopyArea
Definition: foptmgr.hxx:65
formula::RefEdit * pEdCopyArea
Definition: foptmgr.hxx:64
ScDocument * pDoc
Definition: foptmgr.hxx:55
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScAddress aEnd
Definition: address.hxx:498
weld::CheckButton * pBtnCopyResult
Definition: foptmgr.hxx:61
void append(const OUString &rId, const OUString &rStr)
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
weld::CheckButton * pBtnHeader
Definition: foptmgr.hxx:59
weld::Button * GetWidget() const
int nCount
SCTAB Tab() const
Definition: address.hxx:283
virtual void connect_toggled(const Link< Toggleable &, void > &rLink)
const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: dbdata.cxx:1406
weld::Label * pFtDbAreaLabel
Definition: foptmgr.hxx:66
ScViewData * pViewData
Definition: foptmgr.hxx:54
void SetModifyHdl(const Link< RefEdit &, void > &rLink)
const ScQueryParam & rQueryData
Definition: foptmgr.hxx:71
int i
void connect_changed(const Link< ComboBox &, void > &rLink)
weld::ComboBox * pLbCopyArea
Definition: foptmgr.hxx:63
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2170
virtual void set_active(bool active)=0
void SetText(const OUString &rStr)
const OUString & GetName() const
Definition: dbdata.hxx:121
virtual void set_active(int pos)=0
constexpr OUStringLiteral STR_DB_LOCAL_NONAME
Definition: globalnames.hxx:14
virtual void clear()=0
weld::Entry * GetWidget() const
bool VerifyPosStr(const OUString &rPosStr) const
Definition: foptmgr.cxx:183
const OUString & rStrUndefined
Definition: foptmgr.hxx:69
IMPL_LINK(ScFilterOptionsMgr, LbAreaSelHdl, weld::ComboBox &, rLb, void)
Definition: foptmgr.cxx:198
SCCOL Col() const
Definition: address.hxx:279
virtual void set_label(const OUString &rText)=0
ScFilterOptionsMgr(ScViewData *ptrViewData, const ScQueryParam &refQueryData, weld::CheckButton *refBtnCase, weld::CheckButton *refBtnRegExp, weld::CheckButton *refBtnHeader, weld::CheckButton *refBtnUnique, weld::CheckButton *refBtnCopyResult, weld::CheckButton *refBtnDestPers, weld::ComboBox *refLbCopyArea, formula::RefEdit *refEdCopyArea, formula::RefButton *refRbCopyArea, weld::Label *refFtDbAreaLabel, weld::Label *refFtDbArea, const OUString &refStrUndefined)
Definition: foptmgr.cxx:34
OUString aName
weld::CheckButton * pBtnUnique
Definition: foptmgr.hxx:60
weld::Label * pFtDbArea
Definition: foptmgr.hxx:67
void append_text(const OUString &rStr)
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
Definition: address.cxx:1537
ScRefFlags
Definition: address.hxx:157
aStr
utl::SearchParam::SearchType eSearchType
Definition: queryparam.hxx:43
weld::CheckButton * pBtnCase
Definition: foptmgr.hxx:57
virtual void set_sensitive(bool sensitive)=0