Update ooo320-m1
[ooovba.git] / sc / source / ui / view / tabvwshe.cxx
blobf52b9906655e42f76869783f778a247140134da2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabvwshe.cxx,v $
10 * $Revision: 1.14 $
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"
52 #include "sc.hrc"
53 #include "scmod.hxx"
54 #include "impex.hxx"
55 #include "editsh.hxx"
56 #include "dociter.hxx"
57 #include "inputhdl.hxx"
59 //==================================================================
61 String __EXPORT ScTabViewShell::GetSelectionText( BOOL bWholeWord )
63 String aStrSelection;
65 if ( pEditShell && pEditShell == GetMySubShell() )
67 aStrSelection = pEditShell->GetSelectionText( bWholeWord );
69 else
71 ScRange aRange;
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() );
83 SCCOL nCol;
84 SCROW nRow;
85 if ( aIter.GetNext( nCol, nRow ) )
87 aRange.aStart.SetCol( nCol );
88 aRange.aStart.SetRow( nRow );
89 aRange.aEnd.SetRow( nRow );
91 else
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() )
110 xub_StrLen nAt;
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,
127 USHORT nMode )
129 SvxLinkInsertMode eMode = (SvxLinkInsertMode) nMode;
130 BOOL bAsText = ( eMode != HLINK_BUTTON ); // Default ist jetzt Text
132 if ( bAsText )
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 );
141 else
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 );
152 else
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
170 --aSel.nStartPos;
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)
191 Sound::Beep();
192 return;
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" );
204 if ( bSelectFirst )
206 if ( pTopView )
207 pTopView->SetSelection( ESelection(0,0,0,1) );
208 if ( pTableView )
209 pTableView->SetSelection( ESelection(0,0,0,1) );
212 pHdl->DataChanging();
214 if ( pTopView )
216 pTopView->InsertField( aURLItem );
217 lcl_SelectFieldAfterInsert( *pTopView );
219 if ( pTableView )
221 pTableView->InsertField( aURLItem );
222 lcl_SelectFieldAfterInsert( *pTableView );
225 pHdl->DataChanged();
228 void ScTabViewShell::ExecSearch( SfxRequest& rReq )
230 const SfxItemSet* pReqArgs = rReq.GetArgs();
231 USHORT nSlot = rReq.GetSlot();
232 const SfxPoolItem* pItem;
234 switch ( nSlot )
236 case FID_SEARCH_NOW:
238 if ( pReqArgs &&
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() );
246 rReq.Done();
249 break;
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 );
259 else
261 DBG_ERROR("SID_SEARCH_ITEM ohne Parameter");
263 break;
264 case FID_SEARCH:
265 case FID_REPLACE:
266 case FID_REPLACE_ALL:
267 case FID_SEARCH_ALL:
269 if (pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState(nSlot, FALSE, &pItem))
271 // SearchItem holen
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);
287 else
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,
296 &aSearchItem, 0L );
298 else
300 GetViewData()->GetDispatcher().Execute(
301 SID_SEARCH_DLG, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD );
304 break;
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,
314 &aSearchItem, 0L );
316 break;
317 // case FID_SEARCH_COUNT:
321 //--------------------------------------------------------------------