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 rtl::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 // wenn CLOOKs: -> mit <editview.hxx> <flditem.hxx>in neue tabvwsh
163 static void lcl_SelectFieldAfterInsert( EditView
& rView
)
165 ESelection aSel
= rView
.GetSelection();
166 if ( aSel
.nStartPos
== aSel
.nEndPos
&& aSel
.nStartPos
> 0 )
168 // Cursor is behind the inserted field -> extend selection to the left
171 rView
.SetSelection( aSel
);
175 void ScTabViewShell::InsertURLField( const String
& rName
, const String
& rURL
, const String
& rTarget
)
177 SvxURLField
aURLField( rURL
, rName
, SVXURLFORMAT_REPR
);
178 aURLField
.SetTargetFrame( rTarget
);
179 SvxFieldItem
aURLItem( aURLField
, EE_FEATURE_FIELD
);
181 ScViewData
* pViewData
= GetViewData();
182 ScModule
* pScMod
= SC_MOD();
183 ScInputHandler
* pHdl
= pScMod
->GetInputHdl( pViewData
->GetViewShell() );
185 sal_Bool bSelectFirst
= false;
186 if ( !pScMod
->IsEditMode() )
188 if ( !SelectionEditable() )
190 // no error message (may be called from drag&drop)
194 // single url in cell is shown in the dialog and replaced
195 bSelectFirst
= HasBookmarkAtCursor( NULL
);
196 pScMod
->SetInputMode( SC_INPUT_TABLE
);
199 EditView
* pTopView
= pHdl
->GetTopView();
200 EditView
* pTableView
= pHdl
->GetTableView();
201 OSL_ENSURE( pTopView
|| pTableView
, "No EditView" );
206 pTopView
->SetSelection( ESelection(0,0,0,1) );
208 pTableView
->SetSelection( ESelection(0,0,0,1) );
211 pHdl
->DataChanging();
215 pTopView
->InsertField( aURLItem
);
216 lcl_SelectFieldAfterInsert( *pTopView
);
220 pTableView
->InsertField( aURLItem
);
221 lcl_SelectFieldAfterInsert( *pTableView
);
227 void ScTabViewShell::ExecSearch( SfxRequest
& rReq
)
229 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
230 sal_uInt16 nSlot
= rReq
.GetSlot();
231 const SfxPoolItem
* pItem
;
238 SFX_ITEM_SET
== pReqArgs
->GetItemState(SID_SEARCH_ITEM
, false, &pItem
) )
240 OSL_ENSURE( pItem
->ISA(SvxSearchItem
), "falsches Item" );
241 const SvxSearchItem
* pSearchItem
= (const SvxSearchItem
*) pItem
;
243 ScGlobal::SetSearchItem( *pSearchItem
);
244 SearchAndReplace( pSearchItem
, sal_True
, rReq
.IsAPI() );
250 case SID_SEARCH_ITEM
:
251 if (pReqArgs
&& SFX_ITEM_SET
==
252 pReqArgs
->GetItemState(SID_SEARCH_ITEM
, false, &pItem
))
254 // Search-Item merken
255 OSL_ENSURE( pItem
->ISA(SvxSearchItem
), "falsches Item" );
256 ScGlobal::SetSearchItem( *(const SvxSearchItem
*) pItem
);
260 OSL_FAIL("SID_SEARCH_ITEM ohne Parameter");
265 case FID_REPLACE_ALL
:
268 if (pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState(nSlot
, false, &pItem
))
272 SvxSearchItem aSearchItem
= ScGlobal::GetSearchItem();
274 // SearchItem fuellen
276 aSearchItem
.SetSearchString(((SfxStringItem
*)pItem
)->GetValue());
277 if(SFX_ITEM_SET
== pReqArgs
->GetItemState(FN_PARAM_1
, false, &pItem
))
278 aSearchItem
.SetReplaceString(((SfxStringItem
*)pItem
)->GetValue());
280 if (nSlot
== FID_SEARCH
)
281 aSearchItem
.SetCommand(SVX_SEARCHCMD_FIND
);
282 else if(nSlot
== FID_REPLACE
)
283 aSearchItem
.SetCommand(SVX_SEARCHCMD_REPLACE
);
284 else if(nSlot
== FID_REPLACE_ALL
)
285 aSearchItem
.SetCommand(SVX_SEARCHCMD_REPLACE_ALL
);
287 aSearchItem
.SetCommand(SVX_SEARCHCMD_FIND_ALL
);
289 // Request ausfuehren (dabei wird das SearchItem gespeichert)
291 aSearchItem
.SetWhich(SID_SEARCH_ITEM
);
292 GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW
,
293 rReq
.IsAPI() ? SFX_CALLMODE_API
|SFX_CALLMODE_SYNCHRON
:
294 SFX_CALLMODE_STANDARD
,
299 GetViewData()->GetDispatcher().Execute(
300 SID_SEARCH_DLG
, SFX_CALLMODE_ASYNCHRON
|SFX_CALLMODE_RECORD
);
304 case FID_REPEAT_SEARCH
:
306 // nochmal mit ScGlobal::GetSearchItem()
308 SvxSearchItem aSearchItem
= ScGlobal::GetSearchItem();
309 aSearchItem
.SetWhich(SID_SEARCH_ITEM
);
310 GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW
,
311 rReq
.IsAPI() ? SFX_CALLMODE_API
|SFX_CALLMODE_SYNCHRON
:
312 SFX_CALLMODE_STANDARD
,
316 // case FID_SEARCH_COUNT:
320 //--------------------------------------------------------------------
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */