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 }
72 
74 {
75 //moggi:TODO
76  OSL_ENSURE( pViewData && pDoc, "Init failed :-/" );
77 
78  pLbCopyArea->connect_changed( LINK( this, ScFilterOptionsMgr, LbAreaSelHdl ) );
79  pEdCopyArea->SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdAreaModifyHdl ) );
80  pBtnCopyResult->connect_toggled( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
81 
86 
87  if ( pViewData && pDoc )
88  {
89  OUString theAreaStr;
90  ScRange theCurArea ( ScAddress( rQueryData.nCol1,
92  pViewData->GetTabNo() ),
95  pViewData->GetTabNo() ) );
96  ScDBCollection* pDBColl = pDoc->GetDBCollection();
97  OUString theDbArea;
98  OUString theDbName(STR_DB_LOCAL_NONAME);
100 
101  theAreaStr = theCurArea.Format(*pDoc, ScRefFlags::RANGE_ABS_3D, eConv);
102 
103  // fill the target area list
104 
105  pLbCopyArea->clear();
107 
108  ScAreaNameIterator aIter( pDoc );
109  OUString aName;
110  ScRange aRange;
111  while ( aIter.Next( aName, aRange ) )
112  {
113  OUString aRefStr(aRange.aStart.Format(ScRefFlags::ADDR_ABS_3D, pDoc, eConv));
114  pLbCopyArea->append(aRefStr, aName);
115  }
116 
117  pBtnDestPers->set_active(true); // always on when called
118  pLbCopyArea->set_active( 0 );
120 
121  /*
122  * Check whether the transferred area is a database area:
123  */
124 
125  theDbArea = theAreaStr;
126 
127  if ( pDBColl )
128  {
129  ScAddress& rStart = theCurArea.aStart;
130  ScAddress& rEnd = theCurArea.aEnd;
131  const ScDBData* pDBData = pDBColl->GetDBAtArea(
132  rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row());
133 
134  if ( pDBData )
135  {
136  pBtnHeader->set_active( pDBData->HasHeader() );
137  theDbName = pDBData->GetName();
138 
140  }
141  }
142 
143  if ( theDbName != STR_DB_LOCAL_NONAME )
144  {
145  theDbArea += " (" + theDbName + ")";
146 
147  pFtDbArea->set_label( theDbArea );
148  }
149  else
150  {
151  pFtDbAreaLabel->set_label( OUString() );
152  pFtDbArea->set_label( OUString() );
153  }
154 
155  // position to copy to:
156 
157  if ( !rQueryData.bInplace )
158  {
159  OUString aString =
164 
165  pBtnCopyResult->set_active(true);
166  pEdCopyArea->SetText( aString );
167  EdAreaModifyHdl( *pEdCopyArea );
168  pLbCopyArea->set_sensitive(true);
172  }
173  else
174  {
175  pBtnCopyResult->set_active( false );
177  pLbCopyArea->set_sensitive(false);
180  pBtnDestPers->set_sensitive(false);
181  }
182  }
183  else
185 }
186 
187 bool ScFilterOptionsMgr::VerifyPosStr( const OUString& rPosStr ) const
188 {
189  OUString aPosStr( rPosStr );
190  sal_Int32 nColonPos = aPosStr.indexOf( ':' );
191 
192  if ( -1 != nColonPos )
193  aPosStr = aPosStr.copy( 0, nColonPos );
194 
195  ScRefFlags nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
196 
197  return (nResult & ScRefFlags::VALID) == ScRefFlags::VALID;
198 }
199 
200 // Handler:
201 
202 IMPL_LINK( ScFilterOptionsMgr, LbAreaSelHdl, weld::ComboBox&, rLb, void )
203 {
204  if ( &rLb == pLbCopyArea )
205  {
206  OUString aString;
207  const sal_Int32 nSelPos = pLbCopyArea->get_active();
208 
209  if ( nSelPos > 0 )
210  aString = pLbCopyArea->get_id(nSelPos);
211 
212  pEdCopyArea->SetText( aString );
213  }
214 }
215 
216 IMPL_LINK( ScFilterOptionsMgr, EdAreaModifyHdl, formula::RefEdit&, rEd, void )
217 {
218  if ( &rEd != pEdCopyArea )
219  return;
220 
221  OUString theCurPosStr = rEd.GetText();
222  ScRefFlags nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
223 
224  if ( (nResult & ScRefFlags::VALID) == ScRefFlags::VALID)
225  {
226  const sal_Int32 nCount = pLbCopyArea->get_count();
227 
228  for ( sal_Int32 i=2; i<nCount; ++i )
229  {
230  OUString aStr = pLbCopyArea->get_id(i);
231  if (theCurPosStr == aStr)
232  {
233  pLbCopyArea->set_active( i );
234  return;
235  }
236  }
237 
238  }
239  pLbCopyArea->set_active( 0 );
240 }
241 
242 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, weld::ToggleButton&, rBox, void )
243 {
244  if ( &rBox != pBtnCopyResult )
245  return;
246 
247  if ( rBox.get_active() )
248  {
249  pBtnDestPers->set_sensitive(true);
250  pLbCopyArea->set_sensitive(true);
251  pEdCopyArea->GetWidget()->set_sensitive(true);
252  pRbCopyArea->GetWidget()->set_sensitive(true);
253  pEdCopyArea->GrabFocus();
254  }
255  else
256  {
257  pBtnDestPers->set_sensitive(false);
258  pLbCopyArea->set_sensitive(false);
259  pEdCopyArea->GetWidget()->set_sensitive(false);
260  pRbCopyArea->GetWidget()->set_sensitive(false);
261  }
262 }
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Next(OUString &rName, ScRange &rRange)
Definition: rangeutl.cxx:949
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2111
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:819
ScAddress aStart
Definition: address.hxx:500
#define EMPTY_OUSTRING
Definition: global.hxx:214
SCROW Row() const
Definition: address.hxx:262
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
#define STR_DB_LOCAL_NONAME
Definition: globalnames.hxx:13
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:501
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:475
virtual void connect_toggled(const Link< ToggleButton &, void > &rLink)
weld::CheckButton * pBtnHeader
Definition: foptmgr.hxx:59
weld::Button * GetWidget() const
int nCount
SCTAB Tab() const
Definition: address.hxx:271
virtual void set_active(bool active)=0
const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: dbdata.cxx:1344
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
SC_DLLPUBLIC 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:2207
void SetText(const OUString &rStr)
const OUString & GetName() const
Definition: dbdata.hxx:122
virtual void set_active(int pos)=0
virtual void clear()=0
weld::Entry * GetWidget() const
bool VerifyPosStr(const OUString &rPosStr) const
Definition: foptmgr.cxx:187
const OUString & rStrUndefined
Definition: foptmgr.hxx:69
IMPL_LINK(ScFilterOptionsMgr, LbAreaSelHdl, weld::ComboBox &, rLb, void)
Definition: foptmgr.cxx:202
SCCOL Col() const
Definition: address.hxx:267
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)
ScRefFlags
Definition: address.hxx:145
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument *=nullptr, 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:1543
aStr
utl::SearchParam::SearchType eSearchType
Definition: queryparam.hxx:44
weld::CheckButton * pBtnCase
Definition: foptmgr.hxx:57
virtual void set_sensitive(bool sensitive)=0