fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / tabvwshe.cxx
blobd2298c25cd93602ec32a33f5c24298470c35ec5f
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 <comphelper/string.hxx>
21 #include <editeng/eeitem.hxx>
23 #include "scitems.hxx"
24 #include <editeng/editview.hxx>
25 #include <editeng/flditem.hxx>
26 #include <svx/hlnkitem.hxx>
27 #include <svl/srchitem.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/objface.hxx>
32 #include <svl/stritem.hxx>
34 #include "tabvwsh.hxx"
35 #include "sc.hrc"
36 #include "scmod.hxx"
37 #include "impex.hxx"
38 #include "editsh.hxx"
39 #include "dociter.hxx"
40 #include "inputhdl.hxx"
41 #include <svx/srchdlg.hxx>
42 #include "document.hxx"
43 #include <gridwin.hxx>
45 OUString ScTabViewShell::GetSelectionText( bool bWholeWord )
47 OUString aStrSelection;
49 if ( pEditShell && pEditShell == GetMySubShell() )
51 aStrSelection = pEditShell->GetSelectionText( bWholeWord );
53 else
55 ScRange aRange;
57 if ( GetViewData().GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
59 ScDocument* pDoc = GetViewData().GetDocument();
60 if ( bInFormatDialog && aRange.aStart.Row() != aRange.aEnd.Row() )
62 // Range auf eine Datenzeile begrenzen
63 // (nur wenn der Aufruf aus einem Format-Dialog kommt)
64 ScHorizontalCellIterator aIter( pDoc, aRange.aStart.Tab(),
65 aRange.aStart.Col(), aRange.aStart.Row(),
66 aRange.aEnd.Col(), aRange.aEnd.Row() );
67 SCCOL nCol;
68 SCROW nRow;
69 if ( aIter.GetNext( nCol, nRow ) )
71 aRange.aStart.SetCol( nCol );
72 aRange.aStart.SetRow( nRow );
73 aRange.aEnd.SetRow( nRow );
75 else
76 aRange.aEnd = aRange.aStart;
78 else
80 // #i111531# with 1M rows it was necessary to limit the range
81 // to the actually used data area.
82 SCCOL nCol1, nCol2;
83 SCROW nRow1, nRow2;
84 SCTAB nTab1, nTab2;
85 aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
86 bool bShrunk;
87 pDoc->ShrinkToUsedDataArea( bShrunk, nTab1, nCol1, nRow1, nCol2, nRow2, false);
88 if (bShrunk)
90 aRange.aStart.SetCol( nCol1 );
91 aRange.aStart.SetRow( nRow1 );
92 aRange.aEnd.SetCol( nCol2 );
93 aRange.aEnd.SetRow( nRow2 );
97 ScImportExport aObj( pDoc, aRange );
98 aObj.SetFormulas( GetViewData().GetOptions().GetOption( VOPT_FORMULAS ) );
99 OUString aExportOUString;
100 aObj.ExportString( aExportOUString );
101 aStrSelection = convertLineEnd(aExportOUString, LINEEND_CR);
103 // Tab/CR durch Space ersetzen, wenn fuer Dialog oder per Basic/SelectionTextExt,
104 // oder wenn es eine einzelne Zeile ist.
105 // Sonst mehrzeilig mit Tabs beibehalten (z.B. Mail oder Basic/SelectionText).
106 // Fuer Mail werden die Tabs dann spaeter in (mehrere) Spaces gewandelt.
108 if ( bInFormatDialog || bWholeWord || aRange.aEnd.Row() == aRange.aStart.Row() )
110 aStrSelection = aStrSelection.replaceAll(OUString(CHAR_CR), " ");
111 aStrSelection = aStrSelection.replaceAll("\t", " ");
112 aStrSelection = comphelper::string::stripEnd(aStrSelection, ' ');
117 return aStrSelection;
120 void ScTabViewShell::InsertURL( const OUString& rName, const OUString& rURL, const OUString& rTarget,
121 sal_uInt16 nMode )
123 SvxLinkInsertMode eMode = (SvxLinkInsertMode) nMode;
124 bool bAsText = ( eMode != HLINK_BUTTON ); // Default ist jetzt Text
126 if ( bAsText )
128 if ( GetViewData().IsActive() )
130 // if the view is active, always use InsertURLField, which starts EditMode
131 // and selects the URL, so it can be changed from the URL bar / dialog
133 InsertURLField( rName, rURL, rTarget );
135 else
137 // if the view is not active, InsertURLField doesn't work
138 // -> use InsertBookmark to directly manipulate cell content
139 // bTryReplace=sal_True -> if cell contains only one URL, replace it
141 SCCOL nPosX = GetViewData().GetCurX();
142 SCROW nPosY = GetViewData().GetCurY();
143 InsertBookmark( rName, rURL, nPosX, nPosY, &rTarget, true );
146 else
148 SC_MOD()->InputEnterHandler();
149 InsertURLButton( rName, rURL, rTarget );
153 static void lcl_SelectFieldAfterInsert( EditView& rView )
155 ESelection aSel = rView.GetSelection();
156 if ( aSel.nStartPos == aSel.nEndPos && aSel.nStartPos > 0 )
158 // Cursor is behind the inserted field -> extend selection to the left
160 --aSel.nStartPos;
161 rView.SetSelection( aSel );
165 void ScTabViewShell::InsertURLField( const OUString& rName, const OUString& rURL, const OUString& rTarget )
167 SvxURLField aURLField( rURL, rName, SVXURLFORMAT_REPR );
168 aURLField.SetTargetFrame( rTarget );
169 SvxFieldItem aURLItem( aURLField, EE_FEATURE_FIELD );
171 ScViewData& rViewData = GetViewData();
172 ScModule* pScMod = SC_MOD();
173 ScInputHandler* pHdl = pScMod->GetInputHdl( rViewData.GetViewShell() );
175 bool bSelectFirst = false;
176 if ( !pScMod->IsEditMode() )
178 if ( !SelectionEditable() )
180 // no error message (may be called from drag&drop)
181 return;
184 // single url in cell is shown in the dialog and replaced
185 bSelectFirst = HasBookmarkAtCursor( NULL );
186 pScMod->SetInputMode( SC_INPUT_TABLE );
189 EditView* pTopView = pHdl->GetTopView();
190 EditView* pTableView = pHdl->GetTableView();
191 OSL_ENSURE( pTopView || pTableView, "No EditView" );
193 if ( bSelectFirst )
195 if ( pTopView )
196 pTopView->SetSelection( ESelection(0,0,0,1) );
197 if ( pTableView )
198 pTableView->SetSelection( ESelection(0,0,0,1) );
201 pHdl->DataChanging();
203 if ( pTopView )
205 pTopView->InsertField( aURLItem );
206 lcl_SelectFieldAfterInsert( *pTopView );
208 if ( pTableView )
210 pTableView->InsertField( aURLItem );
211 lcl_SelectFieldAfterInsert( *pTableView );
214 pHdl->DataChanged();
217 void ScTabViewShell::ExecSearch( SfxRequest& rReq )
219 const SfxItemSet* pReqArgs = rReq.GetArgs();
220 sal_uInt16 nSlot = rReq.GetSlot();
221 const SfxPoolItem* pItem;
223 switch ( nSlot )
225 case FID_SEARCH_NOW:
227 if ( pReqArgs &&
228 SfxItemState::SET == pReqArgs->GetItemState(SID_SEARCH_ITEM, false, &pItem) )
230 OSL_ENSURE( pItem->ISA(SvxSearchItem), "falsches Item" );
231 const SvxSearchItem* pSearchItem = static_cast<const SvxSearchItem*>(pItem);
233 ScGlobal::SetSearchItem( *pSearchItem );
234 bool bSuccess = SearchAndReplace( pSearchItem, true, rReq.IsAPI() );
235 const SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
236 SvxSearchDialogWrapper::GetChildWindowId());
237 if (pChildWindow)
239 SvxSearchDialog* pSearchDlg = static_cast<SvxSearchDialog*>(pChildWindow->GetWindow());
240 if( pSearchDlg )
242 ScTabView* pTabView = GetViewData().GetView();
243 if( pTabView )
245 vcl::Window* pWin = pTabView->GetActiveWin();
246 if( pWin )
248 pSearchDlg->SetDocWin( pWin );
249 pSearchDlg->SetSrchFlag( bSuccess );
254 rReq.Done();
257 break;
259 case SID_SEARCH_ITEM:
260 if (pReqArgs && SfxItemState::SET ==
261 pReqArgs->GetItemState(SID_SEARCH_ITEM, false, &pItem))
263 // Search-Item merken
264 OSL_ENSURE( pItem->ISA(SvxSearchItem), "falsches Item" );
265 ScGlobal::SetSearchItem( *static_cast<const SvxSearchItem*>(pItem ));
267 else
269 OSL_FAIL("SID_SEARCH_ITEM ohne Parameter");
271 break;
272 case FID_SEARCH:
273 case FID_REPLACE:
274 case FID_REPLACE_ALL:
275 case FID_SEARCH_ALL:
277 if (pReqArgs && SfxItemState::SET == pReqArgs->GetItemState(nSlot, false, &pItem))
279 // SearchItem holen
281 SvxSearchItem aSearchItem = ScGlobal::GetSearchItem();
283 // SearchItem fuellen
285 aSearchItem.SetSearchString(static_cast<const SfxStringItem*>(pItem)->GetValue());
286 if(SfxItemState::SET == pReqArgs->GetItemState(FN_PARAM_1, false, &pItem))
287 aSearchItem.SetReplaceString(static_cast<const SfxStringItem*>(pItem)->GetValue());
289 if (nSlot == FID_SEARCH)
290 aSearchItem.SetCommand(SvxSearchCmd::FIND);
291 else if(nSlot == FID_REPLACE)
292 aSearchItem.SetCommand(SvxSearchCmd::REPLACE);
293 else if(nSlot == FID_REPLACE_ALL)
294 aSearchItem.SetCommand(SvxSearchCmd::REPLACE_ALL);
295 else
296 aSearchItem.SetCommand(SvxSearchCmd::FIND_ALL);
298 // Request ausfuehren (dabei wird das SearchItem gespeichert)
300 aSearchItem.SetWhich(SID_SEARCH_ITEM);
301 GetViewData().GetDispatcher().Execute( FID_SEARCH_NOW,
302 rReq.IsAPI() ? SfxCallMode::API|SfxCallMode::SYNCHRON :
303 SfxCallMode::RECORD,
304 &aSearchItem, 0L );
305 const SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
306 SvxSearchDialogWrapper::GetChildWindowId());
307 if (pChildWindow)
309 SvxSearchDialog* pSearchDlg = static_cast<SvxSearchDialog*>(pChildWindow->GetWindow());
310 if( pSearchDlg )
312 ScTabView* pTabView = GetViewData().GetView();
313 if( pTabView )
315 vcl::Window* pWin = pTabView->GetActiveWin();
316 if( pWin )
318 pSearchDlg->SetDocWin( pWin );
319 pSearchDlg->SetSrchFlag();
325 else
327 GetViewData().GetDispatcher().Execute(
328 SID_SEARCH_DLG, SfxCallMode::ASYNCHRON|SfxCallMode::RECORD );
331 break;
332 case FID_REPEAT_SEARCH:
334 // nochmal mit ScGlobal::GetSearchItem()
336 SvxSearchItem aSearchItem = ScGlobal::GetSearchItem();
337 aSearchItem.SetWhich(SID_SEARCH_ITEM);
338 GetViewData().GetDispatcher().Execute( FID_SEARCH_NOW,
339 rReq.IsAPI() ? SfxCallMode::API|SfxCallMode::SYNCHRON :
340 SfxCallMode::RECORD,
341 &aSearchItem, 0L );
343 break;
344 // case FID_SEARCH_COUNT:
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */