LibreOffice Module sc (master)  1
crnrdlg.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 <reffact.hxx>
21 #include <document.hxx>
22 #include <globstr.hrc>
23 #include <scresid.hxx>
24 #include <docsh.hxx>
25 #include <crnrdlg.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/weld.hxx>
28 #include <memory>
29 
30 namespace
31 {
32  void ERRORBOX(weld::Window* pParent, const OUString& rString)
33  {
34  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent,
35  VclMessageType::Warning, VclButtonsType::Ok,
36  rString));
37  xBox->run();
38  }
39 
40  int QUERYBOX(weld::Window* pParent, const OUString& rString)
41  {
42  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent,
43  VclMessageType::Question, VclButtonsType::YesNo,
44  rString));
45  xBox->set_default_response(RET_YES);
46  return xBox->run();
47  }
48 
49 }
50 
54 
55 
56 // note: some of the initialisation is done in Init
58  SfxChildWindow* pCW,
59  weld::Window* pParent,
60  ScViewData& rViewData )
61 
62  : ScAnyRefDlgController(pB, pCW, pParent, "modules/scalc/ui/namerangesdialog.ui", "NameRangesDialog")
63  , m_rViewData(rViewData)
64  , rDoc(rViewData.GetDocument())
65  , bDlgLostFocus(false)
66  , m_pEdActive(nullptr)
67  , m_xLbRange(m_xBuilder->weld_tree_view("range"))
68  , m_xEdAssign(new formula::RefEdit(m_xBuilder->weld_entry("edassign")))
69  , m_xRbAssign(new formula::RefButton(m_xBuilder->weld_button("rbassign")))
70  , m_xBtnColHead(m_xBuilder->weld_radio_button("colhead"))
71  , m_xBtnRowHead(m_xBuilder->weld_radio_button("rowhead"))
72  , m_xEdAssign2(new formula::RefEdit(m_xBuilder->weld_entry("edassign2")))
73  , m_xRbAssign2(new formula::RefButton(m_xBuilder->weld_button("rbassign2")))
74  , m_xBtnOk(m_xBuilder->weld_button("ok"))
75  , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
76  , m_xBtnAdd(m_xBuilder->weld_button("add"))
77  , m_xBtnRemove(m_xBuilder->weld_button("delete"))
78  , m_xRangeFrame(m_xBuilder->weld_frame("rangeframe"))
79  , m_xRangeFT(m_xRangeFrame->weld_label_widget())
80  , m_xDataFT(m_xBuilder->weld_label("datarange"))
81 {
82  m_xRbAssign->SetReferences(this, m_xEdAssign.get());
83  m_xEdAssign->SetReferences(this, m_xRangeFT.get());
84  m_xRbAssign2->SetReferences(this, m_xEdAssign2.get());
85  m_xEdAssign2->SetReferences(this, m_xDataFT.get());
86 
89  Init();
90 }
91 
93 {
94 }
95 
96 // initialises event handlers and start parameters in the dialog
98 {
99  m_xBtnOk->connect_clicked ( LINK( this, ScColRowNameRangesDlg, OkBtnHdl ) );
100  m_xBtnCancel->connect_clicked ( LINK( this, ScColRowNameRangesDlg, CancelBtnHdl ) );
101  m_xBtnAdd->connect_clicked ( LINK( this, ScColRowNameRangesDlg, AddBtnHdl ) );
102  m_xBtnRemove->connect_clicked ( LINK( this, ScColRowNameRangesDlg, RemoveBtnHdl ) );
103  m_xLbRange->connect_changed( LINK( this, ScColRowNameRangesDlg, Range1SelectHdl ) );
104  m_xEdAssign->SetModifyHdl ( LINK( this, ScColRowNameRangesDlg, Range1DataModifyHdl ) );
105  m_xBtnColHead->connect_toggled ( LINK( this, ScColRowNameRangesDlg, ColRowToggleHdl ) );
106  m_xEdAssign2->SetModifyHdl ( LINK( this, ScColRowNameRangesDlg, Range2DataModifyHdl ) );
107 
108  Link<formula::RefEdit&,void> aEditLink = LINK( this, ScColRowNameRangesDlg, GetEditFocusHdl );
109  m_xEdAssign->SetGetFocusHdl( aEditLink );
110  m_xEdAssign2->SetGetFocusHdl( aEditLink );
111 
112  Link<formula::RefButton&,void> aButtonLink = LINK( this, ScColRowNameRangesDlg, GetButtonFocusHdl );
113  m_xRbAssign->SetGetFocusHdl( aButtonLink );
114  m_xRbAssign2->SetGetFocusHdl( aButtonLink );
115 
116  aEditLink = LINK( this, ScColRowNameRangesDlg, LoseEditFocusHdl );
117  m_xEdAssign->SetLoseFocusHdl( aEditLink );
118  m_xEdAssign2->SetLoseFocusHdl( aEditLink );
119 
120  aButtonLink = LINK( this, ScColRowNameRangesDlg, LoseButtonFocusHdl );
121  m_xRbAssign2->SetLoseFocusHdl( aButtonLink );
122  m_xRbAssign->SetLoseFocusHdl( aButtonLink );
123 
124  m_pEdActive = m_xEdAssign.get();
125 
126  UpdateNames();
127 
128  SCCOL nStartCol = 0;
129  SCROW nStartRow = 0;
130  SCTAB nStartTab = 0;
131  SCCOL nEndCol = 0;
132  SCROW nEndRow = 0;
133  SCTAB nEndTab = 0;
134  m_rViewData.GetSimpleArea(nStartCol, nStartRow, nStartTab,
135  nEndCol, nEndRow, nEndTab );
136  SetColRowData( ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab));
137 
138  m_xBtnColHead->set_sensitive(true);
139  m_xBtnRowHead->set_sensitive(true);
140  m_xEdAssign->GetWidget()->set_sensitive(true);
141  m_xEdAssign->GrabFocus();
142  m_xRbAssign->GetWidget()->set_sensitive(true);
143 
144  Range1SelectHdl( *m_xLbRange );
145 }
146 
147 // set data range of a labeled range to default values and set the
148 // form elements for the reference
149 void ScColRowNameRangesDlg::SetColRowData( const ScRange& rLabelRange, bool bRef)
150 {
151  theCurData = theCurArea = rLabelRange;
152  bool bValid = true;
153  SCCOL nCol1 = theCurArea.aStart.Col();
154  SCCOL nCol2 = theCurArea.aEnd.Col();
155  SCROW nRow1 = theCurArea.aStart.Row();
156  SCROW nRow2 = theCurArea.aEnd.Row();
157  if ( (static_cast<SCCOLROW>(nCol2 - nCol1) >= nRow2 - nRow1) || (nCol1 == 0 && nCol2 == rDoc.MaxCol()) )
158  { // Column headers and the limiting case of the whole sheet
159  m_xBtnColHead->set_active(true);
160  m_xBtnRowHead->set_active(false);
161  if ( nRow2 == rDoc.MaxRow() )
162  {
163  if ( nRow1 == 0 )
164  bValid = false; // limiting case of the whole sheet
165  else
166  { // Header at bottom, data above
167  theCurData.aStart.SetRow( 0 );
168  theCurData.aEnd.SetRow( nRow1 - 1 );
169  }
170  }
171  else
172  { // Header at top, data below
173  theCurData.aStart.SetRow( nRow2 + 1 );
175  }
176  }
177  else
178  { // Column headers
179  m_xBtnRowHead->set_active(true);
180  m_xBtnColHead->set_active(false);
181  if ( nCol2 == rDoc.MaxCol() )
182  { // Header at the right, data to the left
183  theCurData.aStart.SetCol( 0 );
184  theCurData.aEnd.SetCol( nCol2 - 1 );
185  }
186  else
187  { // Header at the left, data to the right
188  theCurData.aStart.SetCol( nCol2 + 1 );
190  }
191  }
192  if ( bValid )
193  {
196 
197  if(bRef)
198  m_xEdAssign->SetRefString( aStr );
199  else
200  m_xEdAssign->SetText( aStr );
201 
202  m_xEdAssign->SetCursorAtLast();
204 
205  if(bRef)
206  m_xEdAssign2->SetRefString( aStr );
207  else
208  m_xEdAssign2->SetText( aStr );
209  }
210  else
211  {
213 
214  if(bRef)
215  {
216  m_xEdAssign->SetRefString( EMPTY_OUSTRING );
217  m_xEdAssign2->SetRefString( EMPTY_OUSTRING );
218  }
219  else
220  {
221  m_xEdAssign->SetText( EMPTY_OUSTRING );
222  m_xEdAssign2->SetText( EMPTY_OUSTRING );
223  }
224 
225  m_xBtnColHead->set_sensitive(false);
226  m_xBtnRowHead->set_sensitive(false);
227  m_xEdAssign2->GetWidget()->set_sensitive(false);
228  m_xRbAssign2->GetWidget()->set_sensitive(false);
229  }
230 }
231 
232 // adjust label range and set the data reference form element
233 void ScColRowNameRangesDlg::AdjustColRowData( const ScRange& rDataRange, bool bRef)
234 {
235  theCurData = rDataRange;
236  if ( m_xBtnColHead->get_active() )
237  { // Data range is the same columns as the header
241  {
242  SCROW nRow1 = theCurArea.aStart.Row();
243  SCROW nRow2 = theCurArea.aEnd.Row();
244  if ( nRow1 > 0
245  && (theCurData.aEnd.Row() < nRow2 || nRow2 == rDoc.MaxRow()) )
246  { // Data above header
247  theCurData.aEnd.SetRow( nRow1 - 1 );
248  if ( theCurData.aStart.Row() > theCurData.aEnd.Row() )
250  }
251  else
252  { // Data below header
253  theCurData.aStart.SetRow( nRow2 + 1 );
254  if ( theCurData.aStart.Row() > theCurData.aEnd.Row() )
256  }
257  }
258  }
259  else
260  { // Data range in the same rows as header
264  {
265  SCCOL nCol1 = theCurArea.aStart.Col();
266  SCCOL nCol2 = theCurArea.aEnd.Col();
267  if ( nCol1 > 0
268  && (theCurData.aEnd.Col() < nCol2 || nCol2 == rDoc.MaxCol()) )
269  { // Data left of header
270  theCurData.aEnd.SetCol( nCol1 - 1 );
271  if ( theCurData.aStart.Col() > theCurData.aEnd.Col() )
273  }
274  else
275  { // Data right of header
276  theCurData.aStart.SetCol( nCol2 + 1 );
277  if ( theCurData.aStart.Col() > theCurData.aEnd.Col() )
279  }
280  }
281  }
283 
284  if(bRef)
285  m_xEdAssign2->SetRefString( aStr );
286  else
287  m_xEdAssign2->SetText( aStr );
288 
289  m_xEdAssign2->SetCursorAtLast();
290 }
291 
292 // Set the reference to a cell range selected with the mouse and update
293 // the selection form element
295 {
296  if ( !m_pEdActive )
297  return;
298 
299  if ( rRef.aStart != rRef.aEnd )
301 
302  if (m_pEdActive == m_xEdAssign.get())
303  SetColRowData( rRef, true );
304  else
305  AdjustColRowData( rRef, true );
306  m_xBtnColHead->set_sensitive(true);
307  m_xBtnRowHead->set_sensitive(true);
308  m_xBtnAdd->set_sensitive(true);
309  m_xBtnRemove->set_sensitive(false);
310 }
311 
313 {
314  DoClose( ScColRowNameRangesDlgWrapper::GetChildWindowId() );
315 }
316 
318 {
319  if ( bDlgLostFocus )
320  {
321  bDlgLostFocus = false;
322  if( m_pEdActive )
324  }
325  else
326  m_xDialog->grab_focus();
327 
328  if( m_pEdActive == m_xEdAssign.get() )
329  Range1DataModifyHdl( *m_xEdAssign );
330  else if( m_pEdActive == m_xEdAssign2.get() )
331  Range2DataModifyHdl( *m_xEdAssign2 );
332 
333  RefInputDone();
334 }
335 
337 {
338  m_xLbRange->freeze();
339 
340  m_xLbRange->clear();
341  aRangeMap.clear();
342  m_xEdAssign->SetText( EMPTY_OUSTRING );
343 
344  size_t nCount, j;
345 
346  SCCOL nCol1;
347  SCROW nRow1; //Extension for range names
348  SCTAB nTab1;
349  SCCOL nCol2;
350  SCROW nRow2;
351  SCTAB nTab2;
352  OUString rString;
353  const ScAddress::Details aDetails(rDoc.GetAddressConvention());
354 
355  OUString strDelim(" --- ");
356  OUString aString = strDelim + ScResId( STR_COLUMN ) + strDelim;
357  m_xLbRange->append(OUString::number(nEntryDataDelim), aString);
358  if ( xColNameRanges->size() > 0 )
359  {
360  std::vector<const ScRangePair*> aSortArray(xColNameRanges->CreateNameSortedArray(
361  rDoc ));
362  nCount = aSortArray.size();
363  for ( j=0; j < nCount; j++ )
364  {
365  const ScRange aRange(aSortArray[j]->GetRange(0));
366  aString = aRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, aDetails);
367 
368  //@008 get range parameters from document
369  aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
370  nCol2, nRow2, nTab2 );
371  SCCOL q=nCol1+3;
372  if(q>nCol2) q=nCol2;
373  //@008 construct string
374  OUStringBuffer strShow = " [";
375  rString = rDoc.GetString(nCol1, nRow1, nTab1);
376  strShow.append(rString);
377  for(SCCOL i=nCol1+1;i<=q;i++)
378  {
379  strShow.append(", ");
380  rString = rDoc.GetString(i, nRow1, nTab1);
381  strShow.append(rString);
382  }
383  if(q<nCol2) // Too long? Add ",..."
384  {
385  strShow.append(", ...");
386  }
387  strShow.append("]");
388 
389  //@008 Add string to listbox
390  OUString aInsStr = aString + strShow.makeStringAndClear();
391  aRangeMap.emplace( aInsStr, aRange );
392  m_xLbRange->append(OUString::number(nEntryDataCol), aInsStr);
393  }
394  }
395  aString = strDelim + ScResId( STR_ROW ) + strDelim;
396  m_xLbRange->append(OUString::number(nEntryDataDelim), aString);
397  if ( xRowNameRanges->size() > 0 )
398  {
399  std::vector<const ScRangePair*> aSortArray(xRowNameRanges->CreateNameSortedArray(
400  rDoc ));
401  nCount = aSortArray.size();
402  for ( j=0; j < nCount; j++ )
403  {
404  const ScRange aRange(aSortArray[j]->GetRange(0));
405  aString = aRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, aDetails);
406 
407  //@008 Build string for rows below
408  aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
409  nCol2, nRow2, nTab2 );
410  SCROW q=nRow1+3;
411  if(q>nRow2) q=nRow2;
412  OUStringBuffer strShow = " [";
413  rString = rDoc.GetString(nCol1, nRow1, nTab1);
414  strShow.append(rString);
415  for(SCROW i=nRow1+1;i<=q;i++)
416  {
417  strShow.append(", ");
418  rString = rDoc.GetString(nCol1, i, nTab1);
419  strShow.append(rString);
420  }
421  if(q<nRow2)
422  {
423  strShow.append(", ...");
424  }
425  strShow.append("]");
426 
427  OUString aInsStr = aString + strShow.makeStringAndClear();
428  aRangeMap.emplace( aInsStr, aRange );
429  m_xLbRange->append(OUString::number(nEntryDataRow), aInsStr);
430  }
431  }
432 
433  m_xLbRange->thaw();
434 }
435 
436 void ScColRowNameRangesDlg::UpdateRangeData( const ScRange& rRange, bool bColName )
437 {
438  ScRangePair* pPair = nullptr;
439  bool bFound = false;
440  if ( bColName && (pPair = xColNameRanges->Find( rRange )) != nullptr )
441  bFound = true;
442  else if ( !bColName && (pPair = xRowNameRanges->Find( rRange )) != nullptr )
443  bFound = true;
444 
445  if ( bFound )
446  {
448  theCurArea = rRange;
450  m_xEdAssign->SetText( aStr );
451  m_xBtnAdd->set_sensitive(false);
452  m_xBtnRemove->set_sensitive(true);
453  m_xBtnColHead->set_active(bColName);
454  m_xBtnRowHead->set_active(!bColName);
455  theCurData = pPair->GetRange(1);
457  m_xEdAssign2->SetText( aStr );
458  }
459  else
460  {
461  m_xBtnAdd->set_sensitive(true);
462  m_xBtnRemove->set_sensitive(false);
463  }
464  m_xBtnColHead->set_sensitive(true);
465  m_xBtnRowHead->set_sensitive(true);
466  m_xEdAssign2->GetWidget()->set_sensitive(true);
467  m_xRbAssign2->GetWidget()->set_sensitive(true);
468 }
469 
471 {
472  return (m_pEdActive != nullptr);
473 }
474 
475 // Handler:
476 
477 // handler called when OK is clicked, calls the add button handler before
478 // passing the range lists to the document
480 {
481  AddBtnHdl(*m_xBtnAdd);
482 
483  // assign RangeLists to the references in the document
484  rDoc.GetColNameRangesRef() = xColNameRanges;
485  rDoc.GetRowNameRangesRef() = xRowNameRanges;
486  // changed ranges need to take effect
487  rDoc.CompileColRowNameFormula();
488  ScDocShell* pDocShell = m_rViewData.GetDocShell();
489  pDocShell->PostPaint(ScRange(0, 0, 0, rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB), PaintPartFlags::Grid);
490  pDocShell->SetDocumentModified();
491 
492  response(RET_OK);
493 }
494 
496 {
497  response(RET_CANCEL);
498 }
499 
500 // handler called when add button clicked: set ranges and add to listbox
502 {
503  OUString aNewArea( m_xEdAssign->GetText() );
504  OUString aNewData( m_xEdAssign2->GetText() );
505 
506  if (aNewArea.isEmpty() || aNewData.isEmpty())
507  return;
508 
509  const formula::FormulaGrammar::AddressConvention eConv = rDoc.GetAddressConvention();
510  ScRange aRange1, aRange2;
511  bool bOk1 = (aRange1.ParseAny( aNewArea, rDoc, eConv ) & ScRefFlags::VALID) == ScRefFlags::VALID;
512  if ( bOk1 && (aRange2.ParseAny( aNewData, rDoc, eConv ) & ScRefFlags::VALID) == ScRefFlags::VALID)
513  {
514  theCurArea = aRange1;
515  AdjustColRowData( aRange2 );
516  ScRangePair* pPair;
517  if ( ( pPair = xColNameRanges->Find( theCurArea ) ) != nullptr )
518  {
519  xColNameRanges->Remove( *pPair );
520  }
521  if ( ( pPair = xRowNameRanges->Find( theCurArea ) ) != nullptr )
522  {
523  xRowNameRanges->Remove( *pPair );
524  }
525  if ( m_xBtnColHead->get_active() )
526  xColNameRanges->Join( ScRangePair( theCurArea, theCurData ) );
527  else
528  xRowNameRanges->Join( ScRangePair( theCurArea, theCurData ) );
529 
530  UpdateNames();
531 
532  m_xEdAssign->GrabFocus();
533  m_xBtnAdd->set_sensitive(false);
534  m_xBtnRemove->set_sensitive(false);
535  m_xEdAssign->SetText( EMPTY_OUSTRING );
536  m_xBtnColHead->set_active(true);
537  m_xBtnRowHead->set_active(false);
538  m_xEdAssign2->SetText( EMPTY_OUSTRING );
539  theCurArea = ScRange();
540  theCurData = theCurArea;
541  Range1SelectHdl( *m_xLbRange );
542  }
543  else
544  {
545  ERRORBOX(m_xDialog.get(), ScResId(STR_INVALIDTABNAME));
546  if ( !bOk1 )
547  m_xEdAssign->GrabFocus();
548  else
549  m_xEdAssign2->GrabFocus();
550  }
551 }
552 
554 {
555  OUString aRangeStr = m_xLbRange->get_selected_text();
556  sal_Int32 nSelectPos = m_xLbRange->get_selected_index();
557  bool bColName = nSelectPos != -1 && m_xLbRange->get_id(nSelectPos).toInt32() == nEntryDataCol;
558  NameRangeMap::const_iterator itr = aRangeMap.find(aRangeStr);
559  if (itr == aRangeMap.end())
560  return;
561  const ScRange& rRange = itr->second;
562 
563  ScRangePair* pPair = nullptr;
564  bool bFound = false;
565  if ( bColName && (pPair = xColNameRanges->Find( rRange )) != nullptr )
566  bFound = true;
567  else if ( !bColName && (pPair = xRowNameRanges->Find( rRange )) != nullptr )
568  bFound = true;
569  if ( !bFound )
570  return;
571 
572  OUString aStrDelMsg = ScResId( STR_QUERY_DELENTRY );
573  OUString aMsg = aStrDelMsg.getToken( 0, '#' )
574  + aRangeStr
575  + aStrDelMsg.getToken( 1, '#' );
576 
577  if (RET_YES != QUERYBOX(m_xDialog.get(), aMsg))
578  return;
579 
580  if ( bColName )
581  xColNameRanges->Remove( *pPair );
582  else
583  xRowNameRanges->Remove( *pPair );
584 
585  UpdateNames();
586  const sal_Int32 nCnt = m_xLbRange->n_children();
587  if ( nSelectPos >= nCnt )
588  {
589  if ( nCnt )
590  nSelectPos = nCnt - 1;
591  else
592  nSelectPos = 0;
593  }
594  m_xLbRange->select(nSelectPos);
595  if (nSelectPos && m_xLbRange->get_id(nSelectPos).toInt32() == nEntryDataDelim)
596  m_xLbRange->select( --nSelectPos ); // ---Row---
597 
598  m_xLbRange->grab_focus();
599  m_xBtnAdd->set_sensitive(false);
600  m_xBtnRemove->set_sensitive(false);
601  m_xEdAssign->SetText( EMPTY_OUSTRING );
602  theCurArea = theCurData = ScRange();
603  m_xBtnColHead->set_active(true);
604  m_xBtnRowHead->set_active(false);
605  m_xEdAssign2->SetText( EMPTY_OUSTRING );
606  Range1SelectHdl( *m_xLbRange );
607 }
608 
609 // handler called when a row in the listbox is selected, updates form input fields
611 {
612  sal_Int32 nSelectPos = m_xLbRange->get_selected_index();
613  const sal_Int32 nCnt = m_xLbRange->n_children();
614  sal_uInt16 nMoves = 0;
615  while (nSelectPos != -1 && nSelectPos < nCnt && m_xLbRange->get_id(nSelectPos).toInt32() == nEntryDataDelim)
616  { // skip Delimiter
617  ++nMoves;
618  ++nSelectPos;
619  }
620  OUString aRangeStr = m_xLbRange->get_selected_text();
621  if ( nMoves )
622  {
623  if ( nSelectPos > 1 && nSelectPos >= nCnt )
624  { // if entries exist before the " --- Row --- " Delimiter then
625  // do not stop at the delimiter
626  nSelectPos = nCnt - 2;
627  m_xLbRange->select(nSelectPos);
628  aRangeStr = m_xLbRange->get_selected_text();
629  }
630  else if ( nSelectPos > 2 && nSelectPos < nCnt && !aRangeStr.isEmpty()
631  && aRangeStr == m_xEdAssign->GetText() )
632  { // move upwards instead of below to the previous position
633  nSelectPos -= 2;
634  m_xLbRange->select( nSelectPos );
635  aRangeStr = m_xLbRange->get_selected_text();
636  }
637  else
638  m_xLbRange->select(nSelectPos);
639  }
640  NameRangeMap::const_iterator itr = aRangeMap.find(aRangeStr);
641  if ( itr != aRangeMap.end() )
642  {
643  bool bColName = m_xLbRange->get_id(nSelectPos).toInt32() == nEntryDataCol;
644  UpdateRangeData( itr->second, bColName );
645  m_xBtnAdd->set_sensitive(false);
646  m_xBtnRemove->set_sensitive(true);
647  }
648  else
649  {
650  if ( !m_xEdAssign->GetText().isEmpty() )
651  {
652  if ( !m_xEdAssign2->GetText().isEmpty() )
653  m_xBtnAdd->set_sensitive(true);
654  else
655  m_xBtnAdd->set_sensitive(false);
656  m_xBtnColHead->set_sensitive(true);
657  m_xBtnRowHead->set_sensitive(true);
658  m_xEdAssign2->GetWidget()->set_sensitive(true);
659  m_xRbAssign2->GetWidget()->set_sensitive(true);
660  }
661  else
662  {
663  m_xBtnAdd->set_sensitive(false);
664  m_xBtnColHead->set_sensitive(false);
665  m_xBtnRowHead->set_sensitive(false);
666  m_xEdAssign2->GetWidget()->set_sensitive(false);
667  m_xRbAssign2->GetWidget()->set_sensitive(false);
668  }
669  m_xBtnRemove->set_sensitive(false);
670  m_xEdAssign->GrabFocus();
671  }
672 
673  m_xEdAssign->GetWidget()->set_sensitive(true);
674  m_xRbAssign->GetWidget()->set_sensitive(true);
675 }
676 
677 // handler called when the label range has changed
679 {
680  OUString aNewArea( m_xEdAssign->GetText() );
681  bool bValid = false;
682  if (!aNewArea.isEmpty())
683  {
684  ScRange aRange;
685  if ( (aRange.ParseAny(aNewArea, rDoc, rDoc.GetAddressConvention() ) & ScRefFlags::VALID) == ScRefFlags::VALID)
686  {
687  SetColRowData( aRange );
688  bValid = true;
689  }
690  }
691  if ( bValid )
692  {
693  m_xBtnAdd->set_sensitive(true);
694  m_xBtnColHead->set_sensitive(true);
695  m_xBtnRowHead->set_sensitive(true);
696  m_xEdAssign2->GetWidget()->set_sensitive(true);
697  m_xRbAssign2->GetWidget()->set_sensitive(true);
698  }
699  else
700  {
701  m_xBtnAdd->set_sensitive(false);
702  m_xBtnColHead->set_sensitive(false);
703  m_xBtnRowHead->set_sensitive(false);
704  m_xEdAssign2->GetWidget()->set_sensitive(false);
705  m_xRbAssign2->GetWidget()->set_sensitive(false);
706  }
707  m_xBtnRemove->set_sensitive(false);
708 }
709 
710 // handler called when the data range has changed
712 {
713  OUString aNewData( m_xEdAssign2->GetText() );
714  if ( !aNewData.isEmpty() )
715  {
716  ScRange aRange;
717  if ( (aRange.ParseAny(aNewData, rDoc, rDoc.GetAddressConvention() ) & ScRefFlags::VALID) == ScRefFlags::VALID)
718  {
719  AdjustColRowData( aRange );
720  m_xBtnAdd->set_sensitive(true);
721  }
722  else
723  m_xBtnAdd->set_sensitive(false);
724  }
725  else
726  {
727  m_xBtnAdd->set_sensitive(false);
728  }
729 }
730 
732 {
733  if (m_xBtnColHead->get_active())
734  {
735  // handler for the radio button for columns, adjust ranges
736  if ( theCurArea.aStart.Row() == 0 && theCurArea.aEnd.Row() == rDoc.MaxRow() )
737  {
738  theCurArea.aEnd.SetRow( rDoc.MaxRow() - 1 );
739  OUString aStr(theCurArea.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention()));
740  m_xEdAssign->SetText( aStr );
741  }
742  ScRange aRange( theCurData );
743  aRange.aStart.SetRow( std::min( static_cast<tools::Long>(theCurArea.aEnd.Row() + 1), static_cast<tools::Long>(rDoc.MaxRow()) ) );
744  aRange.aEnd.SetRow( rDoc.MaxRow() );
745  AdjustColRowData( aRange );
746  }
747  else if (m_xBtnRowHead->get_active())
748  {
749  // handler for the radio button for columns, adjust range
750  if ( theCurArea.aStart.Col() == 0 && theCurArea.aEnd.Col() == rDoc.MaxCol() )
751  {
752  theCurArea.aEnd.SetCol( rDoc.MaxCol() - 1 );
753  OUString aStr(theCurArea.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention()));
754  m_xEdAssign->SetText( aStr );
755  }
756  ScRange aRange( theCurData );
757  aRange.aStart.SetCol( static_cast<SCCOL>(std::min( static_cast<tools::Long>(theCurArea.aEnd.Col() + 1), static_cast<tools::Long>(rDoc.MaxCol()) )) );
758  aRange.aEnd.SetCol( rDoc.MaxCol() );
759  AdjustColRowData( aRange );
760  }
761 }
762 
763 IMPL_LINK( ScColRowNameRangesDlg, GetEditFocusHdl, formula::RefEdit&, rCtrl, void )
764 {
765  if (&rCtrl == m_xEdAssign.get())
766  m_pEdActive = m_xEdAssign.get();
767  else if (&rCtrl == m_xEdAssign2.get())
768  m_pEdActive = m_xEdAssign2.get();
769  else
770  m_pEdActive = nullptr;
771 
772  if( m_pEdActive )
773  m_pEdActive->SelectAll();
774 }
775 
776 IMPL_LINK( ScColRowNameRangesDlg, GetButtonFocusHdl, formula::RefButton&, rCtrl, void )
777 {
778  if (&rCtrl == m_xRbAssign.get())
779  m_pEdActive = m_xEdAssign.get();
780  else if (&rCtrl == m_xRbAssign2.get())
781  m_pEdActive = m_xEdAssign2.get();
782  else
783  m_pEdActive = nullptr;
784 
785  if( m_pEdActive )
786  m_pEdActive->SelectAll();
787 }
788 
790 {
791  bDlgLostFocus = !m_xDialog->has_toplevel_focus();
792 }
793 
795 {
796  bDlgLostFocus = !m_xDialog->has_toplevel_focus();
797 }
798 
799 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1775
const sal_uLong nEntryDataDelim
Definition: crnrdlg.cxx:53
formula::RefEdit * m_pEdActive
Definition: crnrdlg.hxx:56
ScAddress aStart
Definition: address.hxx:499
#define EMPTY_OUSTRING
Definition: global.hxx:214
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
ScColRowNameRangesDlg(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
Definition: crnrdlg.cxx:57
SCROW Row() const
Definition: address.hxx:261
ScViewData & m_rViewData
Definition: crnrdlg.hxx:52
ScDocument & rDoc
Definition: crnrdlg.hxx:53
ScRangePairList * GetColNameRanges()
Definition: document.hxx:806
bool Intersects(const ScRange &rRange) const
Definition: address.cxx:1558
std::unique_ptr< weld::RadioButton > m_xBtnRowHead
Definition: crnrdlg.hxx:62
sal_uIntPtr sal_uLong
sal_Int32 toInt32(OUString const &rStr)
IMPL_LINK_NOARG(ScColRowNameRangesDlg, OkBtnHdl, weld::Button &, void)
Definition: crnrdlg.cxx:479
IMPL_LINK(ScColRowNameRangesDlg, GetEditFocusHdl, formula::RefEdit &, rCtrl, void)
Definition: crnrdlg.cxx:763
void SetDocumentModified()
Definition: docsh.cxx:2940
ScAddress aEnd
Definition: address.hxx:500
std::unique_ptr< weld::Button > m_xBtnOk
Definition: crnrdlg.hxx:66
RET_CANCEL
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
std::unique_ptr< weld::Label > m_xDataFT
Definition: crnrdlg.hxx:73
std::unique_ptr< formula::RefEdit > m_xEdAssign2
Definition: crnrdlg.hxx:63
std::unique_ptr< weld::Label > m_xRangeFT
Definition: crnrdlg.hxx:72
const sal_uLong nEntryDataCol
Definition: crnrdlg.cxx:51
RET_YES
void SetColRowData(const ScRange &rLabelRange, bool bRef=false)
Definition: crnrdlg.cxx:149
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override
Definition: crnrdlg.cxx:294
int nCount
SC_DLLPUBLIC OUString GetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScInterpreterContext *pContext=nullptr) const
Definition: document.cxx:3517
virtual bool IsRefInputMode() const override
Definition: crnrdlg.cxx:470
void SetRow(SCROW nRowP)
Definition: address.hxx:274
void SetCol(SCCOL nColP)
Definition: address.hxx:278
std::unique_ptr< weld::TreeView > m_xLbRange
Definition: crnrdlg.hxx:57
ScRangePairListRef xColNameRanges
Definition: crnrdlg.hxx:47
std::unique_ptr< formula::RefButton > m_xRbAssign2
Definition: crnrdlg.hxx:64
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
ScRangePairList * Clone() const
Definition: rangelst.cxx:1303
ScRangePairListRef xRowNameRanges
Definition: crnrdlg.hxx:48
int i
virtual void SetActive() override
Definition: crnrdlg.cxx:317
sal_Int16 SCCOL
Definition: types.hxx:21
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:2212
std::unique_ptr< weld::RadioButton > m_xBtnColHead
Definition: crnrdlg.hxx:61
const ScRange & GetRange(sal_uInt16 n) const
Definition: address.hxx:816
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
Definition: viewdata.cxx:1179
virtual void RefInputDone(bool bForced=false) override
Definition: anyrefdg.cxx:756
virtual ~ScColRowNameRangesDlg() override
Definition: crnrdlg.cxx:92
const SCTAB MAXTAB
Definition: address.hxx:70
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
SCCOL Col() const
Definition: address.hxx:266
sal_Int32 SCROW
Definition: types.hxx:17
ScRangePairList * GetRowNameRanges()
Definition: document.hxx:807
void AdjustColRowData(const ScRange &rDataRange, bool bRef=false)
Definition: crnrdlg.cxx:233
size_t size() const
Definition: rangelst.cxx:1228
RET_OK
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: crnrdlg.hxx:67
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::Button > m_xBtnAdd
Definition: crnrdlg.hxx:68
virtual void Close() override
Definition: crnrdlg.cxx:312
std::unique_ptr< formula::RefEdit > m_xEdAssign
Definition: crnrdlg.hxx:59
std::unique_ptr< weld::Button > m_xBtnRemove
Definition: crnrdlg.hxx:69
NameRangeMap aRangeMap
Definition: crnrdlg.hxx:51
std::vector< const ScRangePair * > CreateNameSortedArray(ScDocument &) const
Definition: rangelst.cxx:1522
std::unique_ptr< formula::RefButton > m_xRbAssign
Definition: crnrdlg.hxx:60
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:695
const sal_uLong nEntryDataRow
Definition: crnrdlg.cxx:52
void UpdateRangeData(const ScRange &rRange, bool bColName)
Definition: crnrdlg.cxx:436
aStr
ScRangePair * Find(const ScAddress &)
Definition: rangelst.cxx:1283
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
sal_Int16 SCTAB
Definition: types.hxx:22
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
Definition: anyrefdg.cxx:726