1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabvwshe.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
37 #include <svx/eeitem.hxx>
39 #include "scitems.hxx"
40 #include <svx/editview.hxx>
41 #include <svx/flditem.hxx>
42 #include <svx/hlnkitem.hxx>
43 #include <svx/srchitem.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <sfx2/viewfrm.hxx>
46 #include <sfx2/request.hxx>
47 #include <sfx2/objface.hxx>
48 #include <svtools/stritem.hxx>
49 #include <vcl/sound.hxx>
51 #include "tabvwsh.hxx"
56 #include "dociter.hxx"
57 #include "inputhdl.hxx"
59 //==================================================================
61 String __EXPORT
ScTabViewShell::GetSelectionText( BOOL bWholeWord
)
65 if ( pEditShell
&& pEditShell
== GetMySubShell() )
67 aStrSelection
= pEditShell
->GetSelectionText( bWholeWord
);
73 if ( GetViewData()->GetSimpleArea( aRange
) == SC_MARK_SIMPLE
)
75 ScDocument
* pDoc
= GetViewData()->GetDocument();
76 if ( bInFormatDialog
&& aRange
.aStart
.Row() != aRange
.aEnd
.Row() )
78 // Range auf eine Datenzeile begrenzen
79 // (#48613# nur wenn der Aufruf aus einem Format-Dialog kommt)
80 ScHorizontalCellIterator
aIter( pDoc
, aRange
.aStart
.Tab(),
81 aRange
.aStart
.Col(), aRange
.aStart
.Row(),
82 aRange
.aEnd
.Col(), aRange
.aEnd
.Row() );
85 if ( aIter
.GetNext( nCol
, nRow
) )
87 aRange
.aStart
.SetCol( nCol
);
88 aRange
.aStart
.SetRow( nRow
);
89 aRange
.aEnd
.SetRow( nRow
);
92 aRange
.aEnd
= aRange
.aStart
;
95 ScImportExport
aObj( pDoc
, aRange
);
96 aObj
.SetFormulas( GetViewData()->GetOptions().GetOption( VOPT_FORMULAS
) );
97 rtl::OUString aExportOUString
;
98 aObj
.ExportString( aExportOUString
);
99 aStrSelection
= aExportOUString
;
101 aStrSelection
.ConvertLineEnd( 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
.EraseTrailingChars( ' ' );
121 return aStrSelection
;
124 //------------------------------------------------------------------------
126 void ScTabViewShell::InsertURL( const String
& rName
, const String
& rURL
, const String
& rTarget
,
129 SvxLinkInsertMode eMode
= (SvxLinkInsertMode
) nMode
;
130 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 // #91216# if the view is not active, InsertURLField doesn't work
144 // -> use InsertBookmark to directly manipulate cell content
145 // bTryReplace=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
, TRUE
);
154 SC_MOD()->InputEnterHandler();
155 InsertURLButton( rName
, rURL
, rTarget
);
159 //------------------------------------------------------------------------
161 // wenn CLOOKs: -> mit <editview.hxx> <flditem.hxx>in neue tabvwsh
163 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 BOOL bSelectFirst
= FALSE
;
186 if ( !pScMod
->IsEditMode() )
188 if ( !SelectionEditable() )
190 // no error message (may be called from drag&drop)
195 // single url in cell is shown in the dialog and replaced
196 bSelectFirst
= HasBookmarkAtCursor( NULL
);
197 pScMod
->SetInputMode( SC_INPUT_TABLE
);
200 EditView
* pTopView
= pHdl
->GetTopView();
201 EditView
* pTableView
= pHdl
->GetTableView();
202 DBG_ASSERT( pTopView
|| pTableView
, "No EditView" );
207 pTopView
->SetSelection( ESelection(0,0,0,1) );
209 pTableView
->SetSelection( ESelection(0,0,0,1) );
212 pHdl
->DataChanging();
216 pTopView
->InsertField( aURLItem
);
217 lcl_SelectFieldAfterInsert( *pTopView
);
221 pTableView
->InsertField( aURLItem
);
222 lcl_SelectFieldAfterInsert( *pTableView
);
228 void ScTabViewShell::ExecSearch( SfxRequest
& rReq
)
230 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
231 USHORT nSlot
= rReq
.GetSlot();
232 const SfxPoolItem
* pItem
;
239 SFX_ITEM_SET
== pReqArgs
->GetItemState(SID_SEARCH_ITEM
, FALSE
, &pItem
) )
241 DBG_ASSERT( pItem
->ISA(SvxSearchItem
), "falsches Item" );
242 const SvxSearchItem
* pSearchItem
= (const SvxSearchItem
*) pItem
;
244 ScGlobal::SetSearchItem( *pSearchItem
);
245 SearchAndReplace( pSearchItem
, TRUE
, rReq
.IsAPI() );
251 case SID_SEARCH_ITEM
:
252 if (pReqArgs
&& SFX_ITEM_SET
==
253 pReqArgs
->GetItemState(SID_SEARCH_ITEM
, FALSE
, &pItem
))
255 // Search-Item merken
256 DBG_ASSERT( pItem
->ISA(SvxSearchItem
), "falsches Item" );
257 ScGlobal::SetSearchItem( *(const SvxSearchItem
*) pItem
);
261 DBG_ERROR("SID_SEARCH_ITEM ohne Parameter");
266 case FID_REPLACE_ALL
:
269 if (pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState(nSlot
, FALSE
, &pItem
))
273 SvxSearchItem aSearchItem
= ScGlobal::GetSearchItem();
275 // SearchItem fuellen
277 aSearchItem
.SetSearchString(((SfxStringItem
*)pItem
)->GetValue());
278 if(SFX_ITEM_SET
== pReqArgs
->GetItemState(FN_PARAM_1
, FALSE
, &pItem
))
279 aSearchItem
.SetReplaceString(((SfxStringItem
*)pItem
)->GetValue());
281 if (nSlot
== FID_SEARCH
)
282 aSearchItem
.SetCommand(SVX_SEARCHCMD_FIND
);
283 else if(nSlot
== FID_REPLACE
)
284 aSearchItem
.SetCommand(SVX_SEARCHCMD_REPLACE
);
285 else if(nSlot
== FID_REPLACE_ALL
)
286 aSearchItem
.SetCommand(SVX_SEARCHCMD_REPLACE_ALL
);
288 aSearchItem
.SetCommand(SVX_SEARCHCMD_FIND_ALL
);
290 // Request ausfuehren (dabei wird das SearchItem gespeichert)
292 aSearchItem
.SetWhich(SID_SEARCH_ITEM
);
293 GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW
,
294 rReq
.IsAPI() ? SFX_CALLMODE_API
|SFX_CALLMODE_SYNCHRON
:
295 SFX_CALLMODE_STANDARD
,
300 GetViewData()->GetDispatcher().Execute(
301 SID_SEARCH_DLG
, SFX_CALLMODE_ASYNCHRON
|SFX_CALLMODE_RECORD
);
305 case FID_REPEAT_SEARCH
:
307 // nochmal mit ScGlobal::GetSearchItem()
309 SvxSearchItem aSearchItem
= ScGlobal::GetSearchItem();
310 aSearchItem
.SetWhich(SID_SEARCH_ITEM
);
311 GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW
,
312 rReq
.IsAPI() ? SFX_CALLMODE_API
|SFX_CALLMODE_SYNCHRON
:
313 SFX_CALLMODE_STANDARD
,
317 // case FID_SEARCH_COUNT:
321 //--------------------------------------------------------------------