1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
39 #include "dociter.hxx"
40 #include "inputhdl.hxx"
41 #include "document.hxx"
43 //==================================================================
45 String
ScTabViewShell::GetSelectionText( sal_Bool bWholeWord
)
49 if ( pEditShell
&& pEditShell
== GetMySubShell() )
51 aStrSelection
= pEditShell
->GetSelectionText( bWholeWord
);
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() );
69 if ( aIter
.GetNext( nCol
, nRow
) )
71 aRange
.aStart
.SetCol( nCol
);
72 aRange
.aStart
.SetRow( nRow
);
73 aRange
.aEnd
.SetRow( nRow
);
76 aRange
.aEnd
= aRange
.aStart
;
80 // #i111531# with 1M rows it was necessary to limit the range
81 // to the actually used data area.
85 aRange
.GetVars( nCol1
, nRow1
, nTab1
, nCol2
, nRow2
, nTab2
);
87 pDoc
->ShrinkToUsedDataArea( bShrunk
, nTab1
, nCol1
, nRow1
, nCol2
, nRow2
, false);
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() )
111 while ( (nAt
= aStrSelection
.Search( CHAR_CR
)) != STRING_NOTFOUND
)
112 aStrSelection
.SetChar( nAt
, ' ' );
113 while ( (nAt
= aStrSelection
.Search( '\t' )) != STRING_NOTFOUND
)
114 aStrSelection
.SetChar( nAt
, ' ' );
116 aStrSelection
= comphelper::string::stripEnd(aStrSelection
, ' ');
121 return aStrSelection
;
124 //------------------------------------------------------------------------
126 void ScTabViewShell::InsertURL( const String
& rName
, const String
& rURL
, const String
& rTarget
,
129 SvxLinkInsertMode eMode
= (SvxLinkInsertMode
) nMode
;
130 sal_Bool bAsText
= ( eMode
!= HLINK_BUTTON
); // Default ist jetzt Text
134 if ( GetViewData()->IsActive() )
136 // if the view is active, always use InsertURLField, which starts EditMode
137 // and selects the URL, so it can be changed from the URL bar / dialog
139 InsertURLField( rName
, rURL
, rTarget
);
143 // if the view is not active, InsertURLField doesn't work
144 // -> use InsertBookmark to directly manipulate cell content
145 // bTryReplace=sal_True -> if cell contains only one URL, replace it
147 SCCOL nPosX
= GetViewData()->GetCurX();
148 SCROW nPosY
= GetViewData()->GetCurY();
149 InsertBookmark( rName
, rURL
, nPosX
, nPosY
, &rTarget
, sal_True
);
154 SC_MOD()->InputEnterHandler();
155 InsertURLButton( rName
, rURL
, rTarget
);
159 //------------------------------------------------------------------------
161 static void lcl_SelectFieldAfterInsert( EditView
& rView
)
163 ESelection aSel
= rView
.GetSelection();
164 if ( aSel
.nStartPos
== aSel
.nEndPos
&& aSel
.nStartPos
> 0 )
166 // Cursor is behind the inserted field -> extend selection to the left
169 rView
.SetSelection( aSel
);
173 void ScTabViewShell::InsertURLField( const String
& rName
, const String
& rURL
, const String
& rTarget
)
175 SvxURLField
aURLField( rURL
, rName
, SVXURLFORMAT_REPR
);
176 aURLField
.SetTargetFrame( rTarget
);
177 SvxFieldItem
aURLItem( aURLField
, EE_FEATURE_FIELD
);
179 ScViewData
* pViewData
= GetViewData();
180 ScModule
* pScMod
= SC_MOD();
181 ScInputHandler
* pHdl
= pScMod
->GetInputHdl( pViewData
->GetViewShell() );
183 sal_Bool bSelectFirst
= false;
184 if ( !pScMod
->IsEditMode() )
186 if ( !SelectionEditable() )
188 // no error message (may be called from drag&drop)
192 // single url in cell is shown in the dialog and replaced
193 bSelectFirst
= HasBookmarkAtCursor( NULL
);
194 pScMod
->SetInputMode( SC_INPUT_TABLE
);
197 EditView
* pTopView
= pHdl
->GetTopView();
198 EditView
* pTableView
= pHdl
->GetTableView();
199 OSL_ENSURE( pTopView
|| pTableView
, "No EditView" );
204 pTopView
->SetSelection( ESelection(0,0,0,1) );
206 pTableView
->SetSelection( ESelection(0,0,0,1) );
209 pHdl
->DataChanging();
213 pTopView
->InsertField( aURLItem
);
214 lcl_SelectFieldAfterInsert( *pTopView
);
218 pTableView
->InsertField( aURLItem
);
219 lcl_SelectFieldAfterInsert( *pTableView
);
225 void ScTabViewShell::ExecSearch( SfxRequest
& rReq
)
227 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
228 sal_uInt16 nSlot
= rReq
.GetSlot();
229 const SfxPoolItem
* pItem
;
236 SFX_ITEM_SET
== pReqArgs
->GetItemState(SID_SEARCH_ITEM
, false, &pItem
) )
238 OSL_ENSURE( pItem
->ISA(SvxSearchItem
), "falsches Item" );
239 const SvxSearchItem
* pSearchItem
= (const SvxSearchItem
*) pItem
;
241 ScGlobal::SetSearchItem( *pSearchItem
);
242 SearchAndReplace( pSearchItem
, sal_True
, rReq
.IsAPI() );
248 case SID_SEARCH_ITEM
:
249 if (pReqArgs
&& SFX_ITEM_SET
==
250 pReqArgs
->GetItemState(SID_SEARCH_ITEM
, false, &pItem
))
252 // Search-Item merken
253 OSL_ENSURE( pItem
->ISA(SvxSearchItem
), "falsches Item" );
254 ScGlobal::SetSearchItem( *(const SvxSearchItem
*) pItem
);
258 OSL_FAIL("SID_SEARCH_ITEM ohne Parameter");
263 case FID_REPLACE_ALL
:
266 if (pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState(nSlot
, false, &pItem
))
270 SvxSearchItem aSearchItem
= ScGlobal::GetSearchItem();
272 // SearchItem fuellen
274 aSearchItem
.SetSearchString(((SfxStringItem
*)pItem
)->GetValue());
275 if(SFX_ITEM_SET
== pReqArgs
->GetItemState(FN_PARAM_1
, false, &pItem
))
276 aSearchItem
.SetReplaceString(((SfxStringItem
*)pItem
)->GetValue());
278 if (nSlot
== FID_SEARCH
)
279 aSearchItem
.SetCommand(SVX_SEARCHCMD_FIND
);
280 else if(nSlot
== FID_REPLACE
)
281 aSearchItem
.SetCommand(SVX_SEARCHCMD_REPLACE
);
282 else if(nSlot
== FID_REPLACE_ALL
)
283 aSearchItem
.SetCommand(SVX_SEARCHCMD_REPLACE_ALL
);
285 aSearchItem
.SetCommand(SVX_SEARCHCMD_FIND_ALL
);
287 // Request ausfuehren (dabei wird das SearchItem gespeichert)
289 aSearchItem
.SetWhich(SID_SEARCH_ITEM
);
290 GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW
,
291 rReq
.IsAPI() ? SFX_CALLMODE_API
|SFX_CALLMODE_SYNCHRON
:
292 SFX_CALLMODE_STANDARD
,
297 GetViewData()->GetDispatcher().Execute(
298 SID_SEARCH_DLG
, SFX_CALLMODE_ASYNCHRON
|SFX_CALLMODE_RECORD
);
302 case FID_REPEAT_SEARCH
:
304 // nochmal mit ScGlobal::GetSearchItem()
306 SvxSearchItem aSearchItem
= ScGlobal::GetSearchItem();
307 aSearchItem
.SetWhich(SID_SEARCH_ITEM
);
308 GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW
,
309 rReq
.IsAPI() ? SFX_CALLMODE_API
|SFX_CALLMODE_SYNCHRON
:
310 SFX_CALLMODE_STANDARD
,
314 // case FID_SEARCH_COUNT:
318 //--------------------------------------------------------------------
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */