Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include <hintids.hxx>
22 : : #include <com/sun/star/util/SearchOptions.hpp>
23 : : #include <com/sun/star/util/SearchFlags.hpp>
24 : : #include <com/sun/star/i18n/TransliterationModules.hpp>
25 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
26 : : #include <unotools/tempfile.hxx>
27 : : #include <tools/urlobj.hxx>
28 : : #include <vcl/print.hxx>
29 : : #include <vcl/msgbox.hxx>
30 : : #include <vcl/wrkwin.hxx>
31 : : #include <vcl/metric.hxx>
32 : : #include <svtools/ctrltool.hxx>
33 : : #include <svl/intitem.hxx>
34 : : #include <svl/stritem.hxx>
35 : : #include <unotools/pathoptions.hxx>
36 : : #include <svl/undo.hxx>
37 : : #include <svtools/txtcmp.hxx>
38 : : #include <svl/eitem.hxx>
39 : : #include <svl/whiter.hxx>
40 : : #include <unotools/saveopt.hxx>
41 : : #include <svtools/transfer.hxx>
42 : : #include <svtools/svtools.hrc>
43 : : #include <svtools/svtresid.hxx>
44 : : #include <svx/svxids.hrc>
45 : : #include <svtools/htmlcfg.hxx>
46 : : #include <sfx2/app.hxx>
47 : : #include <sfx2/objface.hxx>
48 : : #include <sfx2/viewfrm.hxx>
49 : : #include <sfx2/bindings.hxx>
50 : : #include <sfx2/docfilt.hxx>
51 : : #include <sfx2/fcontnr.hxx>
52 : : #include <sfx2/request.hxx>
53 : : #include <sfx2/prnmon.hxx>
54 : : #include <sfx2/docfile.hxx>
55 : : #include <editeng/fhgtitem.hxx>
56 : : #include <svx/srchdlg.hxx>
57 : : #include <svl/srchitem.hxx>
58 : : #include <editeng/fontitem.hxx>
59 : : #include <editeng/flstitem.hxx>
60 : : #include "editeng/unolingu.hxx"
61 : : #include <sfx2/sfxhtml.hxx>
62 : : #include <swtypes.hxx>
63 : : #include <swmodule.hxx>
64 : : #include <docsh.hxx>
65 : : #include <wdocsh.hxx>
66 : : #include <srcview.hxx>
67 : : #include <viewfunc.hxx>
68 : : #include <doc.hxx>
69 : : #include <sfx2/msg.hxx>
70 : : #include <shellio.hxx>
71 : :
72 : : #include <cmdid.h> // FN_ ...
73 : : #include <helpid.h>
74 : : #include <globals.hrc>
75 : : #include <shells.hrc>
76 : : #include <popup.hrc>
77 : : #include <web.hrc>
78 : : #include <view.hrc>
79 : : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
80 : : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
81 : : #include <sfx2/filedlghelper.hxx>
82 : : #define SwSrcView
83 : : #include "swslots.hxx"
84 : :
85 : : #include <unomid.h>
86 : :
87 : : #include <com/sun/star/document/XDocumentProperties.hpp>
88 : : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
89 : :
90 : : using namespace ::com::sun::star;
91 : : using namespace ::com::sun::star::i18n;
92 : : using namespace ::com::sun::star::lang;
93 : : using namespace ::com::sun::star::uno;
94 : : using namespace ::com::sun::star::ui::dialogs;
95 : : using namespace ::com::sun::star::i18n;
96 : : using namespace ::com::sun::star::lang;
97 : : using namespace ::sfx2;
98 : : using ::rtl::OUString;
99 : : using ::com::sun::star::util::SearchOptions;
100 : :
101 : :
102 : : #define SWSRCVIEWFLAGS ( SFX_VIEW_CAN_PRINT|\
103 : : SFX_VIEW_NO_NEWWINDOW )
104 : :
105 : : #define SRC_SEARCHOPTIONS (0xFFFF & ~(SEARCH_OPTIONS_FORMAT|SEARCH_OPTIONS_FAMILIES|SEARCH_OPTIONS_SEARCH_ALL))
106 : :
107 : : // Druckraender -> wie Basic - Ide
108 : : #define LMARGPRN 1700
109 : : #define RMARGPRN 900
110 : : #define TMARGPRN 2000
111 : : #define BMARGPRN 1000
112 : : #define BORDERPRN 300
113 : :
114 [ + - ][ # # ]: 67 : SFX_IMPL_NAMED_VIEWFACTORY(SwSrcView, "SourceView")
115 : : {
116 : 67 : SFX_VIEW_REGISTRATION(SwWebDocShell);
117 : 67 : }
118 : :
119 [ + + ][ + - ]: 365 : SFX_IMPL_INTERFACE( SwSrcView, SfxViewShell, SW_RES(0) )
[ + - ][ + - ]
120 : : {
121 [ + - ][ + - ]: 73 : SFX_POPUPMENU_REGISTRATION(SW_RES(MN_SRCVIEW_POPUPMENU));
122 [ + - ]: 73 : SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS|
123 : : SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
124 [ + - ]: 73 : SW_RES(RID_WEBTOOLS_TOOLBOX) );
125 : 73 : SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
126 : 73 : }
127 : :
128 [ # # ][ # # ]: 54 : TYPEINIT1(SwSrcView, SfxViewShell)
129 : :
130 : 0 : void lcl_PrintHeader( OutputDevice &rOutDev, sal_uInt16 nPages, sal_uInt16 nCurPage, const String& rTitle )
131 : : {
132 : 0 : short nLeftMargin = LMARGPRN;
133 [ # # ]: 0 : Size aSz = rOutDev.GetOutputSize();
134 : 0 : short nBorder = BORDERPRN;
135 : :
136 : 0 : Color aOldFillColor( rOutDev.GetFillColor() );
137 [ # # ]: 0 : Font aOldFont( rOutDev.GetFont() );
138 : :
139 [ # # ]: 0 : rOutDev.SetFillColor( Color(COL_TRANSPARENT) );
140 : :
141 [ # # ]: 0 : Font aFont( aOldFont );
142 [ # # ]: 0 : aFont.SetWeight( WEIGHT_BOLD );
143 [ # # ]: 0 : aFont.SetAlign( ALIGN_BOTTOM );
144 [ # # ]: 0 : rOutDev.SetFont( aFont );
145 : :
146 [ # # ]: 0 : long nFontHeight = rOutDev.GetTextHeight();
147 : :
148 : : // 1.Border => Strich, 2+3 Border = Freiraum.
149 : 0 : long nYTop = TMARGPRN-3*nBorder-nFontHeight;
150 : :
151 : 0 : long nXLeft = nLeftMargin-nBorder;
152 : 0 : long nXRight = aSz.Width()-RMARGPRN+nBorder;
153 : :
154 : : rOutDev.DrawRect( Rectangle(
155 : : Point( nXLeft, nYTop ),
156 [ # # ][ # # ]: 0 : Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) );
157 : :
158 : :
159 : 0 : long nY = TMARGPRN-2*nBorder;
160 : 0 : Point aPos( nLeftMargin, nY );
161 [ # # ]: 0 : rOutDev.DrawText( aPos, rTitle );
162 [ # # ]: 0 : if ( nPages != 1 )
163 : : {
164 [ # # ]: 0 : aFont.SetWeight( WEIGHT_NORMAL );
165 [ # # ]: 0 : rOutDev.SetFont( aFont );
166 [ # # ]: 0 : String aPageStr( rtl::OUString(" [") );
167 [ # # ][ # # ]: 0 : aPageStr += String( SW_RES( STR_PAGE ) );
[ # # ]
168 [ # # ]: 0 : aPageStr += ' ';
169 [ # # ][ # # ]: 0 : aPageStr += String::CreateFromInt32( nCurPage );
[ # # ]
170 [ # # ]: 0 : aPageStr += ']';
171 [ # # ]: 0 : aPos.X() += rOutDev.GetTextWidth( rTitle );
172 [ # # ][ # # ]: 0 : rOutDev.DrawText( aPos, aPageStr );
173 : : }
174 : :
175 : :
176 : 0 : nY = TMARGPRN-nBorder;
177 : :
178 [ # # ]: 0 : rOutDev.DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
179 : :
180 [ # # ]: 0 : rOutDev.SetFont( aOldFont );
181 [ # # ][ # # ]: 0 : rOutDev.SetFillColor( aOldFillColor );
[ # # ]
182 : 0 : }
183 : :
184 : 0 : rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding)
185 : : {
186 : 0 : rtl_TextEncoding eRet = eLoadEncoding;
187 [ # # ]: 0 : if(RTL_TEXTENCODING_DONTKNOW == eRet)
188 : : {
189 : 0 : SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
190 : : const sal_Char *pCharSet =
191 : 0 : rtl_getBestMimeCharsetFromTextEncoding( rHtmlOptions.GetTextEncoding() );
192 : 0 : eRet = rtl_getTextEncodingFromMimeCharset( pCharSet );
193 : : }
194 : 0 : return eRet;
195 : : }
196 : :
197 : 0 : void lcl_ConvertTabsToSpaces( String& rLine )
198 : : {
199 [ # # ]: 0 : if ( rLine.Len() )
200 : : {
201 : 0 : sal_uInt16 nPos = 0;
202 : 0 : sal_uInt16 nMax = rLine.Len();
203 [ # # ]: 0 : while ( nPos < nMax )
204 : : {
205 [ # # ]: 0 : if ( rLine.GetChar(nPos) == '\t' )
206 : : {
207 : : // Nicht 4 Blanks, sondern an 4er TabPos:
208 [ # # ]: 0 : String aBlanker;
209 [ # # ]: 0 : aBlanker.Fill( ( 4 - ( nPos % 4 ) ), ' ' );
210 [ # # ]: 0 : rLine.Erase( nPos, 1 );
211 [ # # ]: 0 : rLine.Insert( aBlanker, nPos );
212 [ # # ]: 0 : nMax = rLine.Len();
213 : : }
214 : 0 : nPos++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
215 : : }
216 : : }
217 : 0 : }
218 : :
219 : 0 : SwSrcView::SwSrcView(SfxViewFrame* pViewFrame, SfxViewShell*) :
220 : : SfxViewShell( pViewFrame, SWSRCVIEWFLAGS ),
221 [ # # ]: 0 : aEditWin( &pViewFrame->GetWindow(), this ),
222 : : pSearchItem(0),
223 : : bSourceSaved(sal_False),
224 [ # # ]: 0 : eLoadEncoding(RTL_TEXTENCODING_DONTKNOW)
225 : : {
226 [ # # ]: 0 : Init();
227 : 0 : }
228 : :
229 [ # # ]: 0 : SwSrcView::~SwSrcView()
230 : : {
231 [ # # ]: 0 : SwDocShell* pDocShell = GetDocShell();
232 : : OSL_ENSURE(PTR_CAST(SwWebDocShell, pDocShell), "Wieso keine WebDocShell?");
233 [ # # ]: 0 : const TextSelection& rSel = aEditWin.GetTextView()->GetSelection();
234 : 0 : ((SwWebDocShell*)pDocShell)->SetSourcePara( static_cast< sal_uInt16 >( rSel.GetStart().GetPara() ) );
235 : :
236 : : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
237 [ # # ][ # # ]: 0 : pDocShell->GetModel(), uno::UNO_QUERY_THROW);
238 : : uno::Reference<document::XDocumentProperties> xDocProps
239 [ # # ][ # # ]: 0 : = xDPS->getDocumentProperties();
240 [ # # ][ # # ]: 0 : ::rtl::OUString url = xDocProps->getAutoloadURL();
241 [ # # ][ # # ]: 0 : sal_Int32 delay = xDocProps->getAutoloadSecs();
242 : : pDocShell->SetAutoLoad(INetURLObject(url), delay,
243 [ # # ][ # # ]: 0 : (delay != 0) || !url.isEmpty());
[ # # ][ # # ]
[ # # ]
244 [ # # ]: 0 : EndListening(*pDocShell);
245 [ # # ][ # # ]: 0 : delete pSearchItem;
246 [ # # ]: 0 : }
247 : :
248 : 0 : void SwSrcView::SaveContentTo(SfxMedium& rMed)
249 : : {
250 : 0 : SvStream* pOutStream = rMed.GetOutStream();
251 : 0 : pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
252 : 0 : aEditWin.Write( *pOutStream );
253 : 0 : }
254 : :
255 : 0 : void SwSrcView::Init()
256 : : {
257 : 0 : SetHelpId(SW_SRC_VIEWSHELL);
258 [ # # ][ # # ]: 0 : SetName(rtl::OUString("Source"));
[ # # ]
259 : 0 : SetWindow( &aEditWin );
260 : 0 : SwDocShell* pDocShell = GetDocShell();
261 : : // wird das Doc noch geladen, dann muss die DocShell das Load
262 : : // anwerfen, wenn das Laden abgeschlossen ist
263 [ # # ]: 0 : if(!pDocShell->IsLoading())
264 : 0 : Load(pDocShell);
265 : : else
266 : : {
267 : 0 : aEditWin.SetReadonly(sal_True);
268 : : }
269 : :
270 : 0 : SetNewWindowAllowed( sal_False );
271 : 0 : StartListening(*pDocShell,sal_True);
272 : 0 : }
273 : :
274 : 0 : SwDocShell* SwSrcView::GetDocShell()
275 : : {
276 : 0 : SfxObjectShell* pObjShell = GetViewFrame()->GetObjectShell();
277 [ # # ][ # # ]: 0 : return PTR_CAST(SwDocShell, pObjShell);
278 : : }
279 : :
280 : 0 : void SwSrcView::SaveContent(const String& rTmpFile)
281 : : {
282 [ # # ]: 0 : SfxMedium aMedium( rTmpFile, STREAM_WRITE);
283 [ # # ]: 0 : SvStream* pOutStream = aMedium.GetOutStream();
284 [ # # ]: 0 : pOutStream->SetStreamCharSet( lcl_GetStreamCharSet(eLoadEncoding) );
285 [ # # ]: 0 : aEditWin.Write(*pOutStream);
286 [ # # ][ # # ]: 0 : aMedium.Commit();
287 : 0 : }
288 : :
289 : 0 : void SwSrcView::Execute(SfxRequest& rReq)
290 : : {
291 : 0 : sal_uInt16 nSlot = rReq.GetSlot();
292 : 0 : TextView* pTextView = aEditWin.GetTextView();
293 [ # # # # : 0 : switch( nSlot )
# # # # #
# # # # ]
294 : : {
295 : : case SID_SAVEASDOC:
296 : : {
297 [ # # ]: 0 : SvtPathOptions aPathOpt;
298 : : // filesave dialog with autoextension
299 : : FileDialogHelper aDlgHelper(
300 [ # # ]: 0 : TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
301 [ # # ]: 0 : uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
302 [ # # ]: 0 : uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
303 : :
304 : : // search for an html filter for export
305 [ # # ][ # # ]: 0 : SfxFilterContainer* pFilterCont = GetObjectShell()->GetFactory().GetFilterContainer();
[ # # ]
306 : : const SfxFilter* pFilter =
307 [ # # ][ # # ]: 0 : pFilterCont->GetFilter4Extension( rtl::OUString("html"), SFX_FILTER_EXPORT );
[ # # ]
308 [ # # ]: 0 : if ( pFilter )
309 : : {
310 : : // filter found -> use its uiname and wildcard
311 : 0 : const String& rUIName = pFilter->GetUIName();
312 : 0 : const WildCard& rCard = pFilter->GetWildcard();
313 [ # # ][ # # ]: 0 : xFltMgr->appendFilter( rUIName, rCard.getGlob() );
[ # # ][ # # ]
314 [ # # ][ # # ]: 0 : xFltMgr->setCurrentFilter( rUIName ) ;
[ # # ]
315 : : }
316 : : else
317 : : {
318 : : // filter not found
319 : 0 : rtl::OUString sHtml("HTML");
320 [ # # ][ # # ]: 0 : xFltMgr->appendFilter( sHtml, rtl::OUString("*.html;*.htm") );
321 [ # # ][ # # ]: 0 : xFltMgr->setCurrentFilter( sHtml ) ;
322 : : }
323 : :
324 [ # # ][ # # ]: 0 : xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
[ # # ][ # # ]
325 [ # # ][ # # ]: 0 : if( aDlgHelper.Execute() == ERRCODE_NONE)
326 : : {
327 [ # # ][ # # ]: 0 : SfxMedium aMedium( xFP->getFiles().getConstArray()[0],
[ # # ]
328 [ # # ][ # # ]: 0 : STREAM_WRITE | STREAM_SHARE_DENYNONE );
[ # # ]
329 [ # # ]: 0 : SvStream* pOutStream = aMedium.GetOutStream();
330 [ # # ]: 0 : pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
331 [ # # ]: 0 : aEditWin.Write( *pOutStream );
332 [ # # ][ # # ]: 0 : aMedium.Commit();
333 [ # # ][ # # ]: 0 : }
334 : : }
335 : 0 : break;
336 : : case SID_SAVEDOC:
337 : : {
338 : 0 : SwDocShell* pDocShell = GetDocShell();
339 : 0 : SfxMedium* pMed = 0;
340 [ # # ]: 0 : if(pDocShell->HasName())
341 : 0 : pMed = pDocShell->GetMedium();
342 : : else
343 : : {
344 : 0 : SfxBoolItem* pItem = (SfxBoolItem*)pDocShell->ExecuteSlot(rReq, pDocShell->GetInterface());
345 [ # # ][ # # ]: 0 : if(pItem && pItem->GetValue())
[ # # ]
346 : 0 : pMed = pDocShell->GetMedium();
347 : : }
348 [ # # ]: 0 : if(pMed)
349 : : {
350 : 0 : SvStream* pOutStream = pMed->GetOutStream();
351 : 0 : pOutStream->Seek(0);
352 : 0 : pOutStream->SetStreamSize(0);
353 : 0 : pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
354 : 0 : aEditWin.Write( *pOutStream );
355 : 0 : pMed->CloseOutStream();
356 : 0 : pMed->Commit();
357 : 0 : pDocShell->GetDoc()->ResetModified();
358 : 0 : SourceSaved();
359 : 0 : aEditWin.ClearModifyFlag();
360 : : }
361 : : }
362 : 0 : break;
363 : : case FID_SEARCH_NOW:
364 : : {
365 : 0 : const SfxItemSet* pTmpArgs = rReq.GetArgs();
366 : :
367 : 0 : sal_uInt16 nWhich = pTmpArgs->GetWhichByPos( 0 );
368 : : OSL_ENSURE( nWhich, "Wich fuer SearchItem ?" );
369 : 0 : const SfxPoolItem& rItem = pTmpArgs->Get( nWhich );
370 : 0 : SetSearchItem( (const SvxSearchItem&)rItem);
371 : 0 : StartSearchAndReplace( (const SvxSearchItem&)rItem, sal_False, rReq.IsAPI() );
372 [ # # ]: 0 : if(aEditWin.IsModified())
373 : 0 : GetDocShell()->GetDoc()->SetModified();
374 : : }
375 : 0 : break;
376 : : case FN_REPEAT_SEARCH:
377 : : {
378 : 0 : SvxSearchItem* pSrchItem = GetSearchItem();
379 [ # # ]: 0 : if(pSrchItem)
380 : : {
381 : 0 : StartSearchAndReplace( *pSrchItem, sal_False, rReq.IsAPI() );
382 [ # # ]: 0 : if(aEditWin.IsModified())
383 : 0 : GetDocShell()->GetDoc()->SetModified();
384 : : }
385 : : }
386 : 0 : break;
387 : : case SID_PRINTDOC:
388 : : case SID_PRINTDOCDIRECT:
389 : : {
390 : 0 : SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
391 : : }
392 : 0 : break;
393 : : case SID_UNDO:
394 : 0 : pTextView->Undo();
395 : 0 : GetViewFrame()->GetBindings().InvalidateAll(sal_False);
396 : 0 : break;
397 : : case SID_REDO:
398 : 0 : pTextView->Redo();
399 : 0 : GetViewFrame()->GetBindings().InvalidateAll(sal_False);
400 : 0 : break;
401 : : case SID_REPEAT:
402 : 0 : break;
403 : : case SID_CUT:
404 [ # # ]: 0 : if(pTextView->HasSelection())
405 : 0 : pTextView->Cut();
406 : 0 : break;
407 : : case SID_COPY:
408 [ # # ]: 0 : if(pTextView->HasSelection())
409 : 0 : pTextView->Copy();
410 : 0 : break;
411 : : case SID_PASTE:
412 : 0 : pTextView->Paste();
413 : 0 : break;
414 : : case SID_SELECTALL:
415 [ # # ][ # # ]: 0 : pTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
416 : 0 : break;
417 : : }
418 : 0 : aEditWin.Invalidate();
419 : 0 : }
420 : :
421 : 0 : void SwSrcView::GetState(SfxItemSet& rSet)
422 : : {
423 [ # # ]: 0 : SfxWhichIter aIter(rSet);
424 [ # # ]: 0 : sal_uInt16 nWhich = aIter.FirstWhich();
425 : 0 : TextView* pTextView = aEditWin.GetTextView();
426 : :
427 [ # # ]: 0 : while(nWhich)
428 : : {
429 [ # # # # : 0 : switch(nWhich)
# # # # #
# # # ]
430 : : {
431 : : case SID_SAVEASDOC:
432 [ # # ][ # # ]: 0 : rSet.Put(SfxStringItem(nWhich, String(SW_RES(STR_SAVEAS_SRC))));
[ # # ][ # # ]
[ # # ]
433 : 0 : break;
434 : : case SID_SAVEDOC:
435 : : {
436 [ # # ]: 0 : SwDocShell* pDocShell = GetDocShell();
437 [ # # ][ # # ]: 0 : if(!pDocShell->IsModified())
438 [ # # ]: 0 : rSet.DisableItem(nWhich);
439 : : }
440 : 0 : break;
441 : : case SID_PRINTDOC:
442 : : case SID_PRINTDOCDIRECT:
443 : 0 : break;
444 : : case SID_TABLE_CELL:
445 : : {
446 [ # # ]: 0 : String aPos( SW_RES(STR_SRCVIEW_ROW) );
447 [ # # ]: 0 : TextSelection aSel = pTextView->GetSelection();
448 [ # # ][ # # ]: 0 : aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 );
[ # # ]
449 [ # # ]: 0 : aPos += rtl::OUString(" : ");
450 [ # # ][ # # ]: 0 : aPos += String(SW_RES(STR_SRCVIEW_COL));
[ # # ]
451 [ # # ][ # # ]: 0 : aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 );
[ # # ]
452 [ # # ]: 0 : SfxStringItem aItem( nWhich, aPos );
453 [ # # ][ # # ]: 0 : rSet.Put( aItem );
[ # # ]
454 : : }
455 : 0 : break;
456 : : case SID_SEARCH_OPTIONS:
457 : : {
458 : 0 : sal_uInt16 nOpt = SRC_SEARCHOPTIONS;
459 [ # # ][ # # ]: 0 : if(GetDocShell()->IsReadOnly())
[ # # ]
460 : 0 : nOpt &= ~(SEARCH_OPTIONS_REPLACE|SEARCH_OPTIONS_REPLACE_ALL);
461 : :
462 [ # # ][ # # ]: 0 : rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOpt) );
[ # # ]
463 : : }
464 : 0 : break;
465 : : case SID_SEARCH_ITEM:
466 : : {
467 [ # # ]: 0 : String sSelected;
468 [ # # ][ # # ]: 0 : if ( !pTextView->HasSelection() )
469 : : {
470 [ # # ]: 0 : const TextSelection& rSel = pTextView->GetSelection();
471 [ # # ][ # # ]: 0 : sSelected = aEditWin.GetTextEngine()->GetWord( rSel.GetStart());
[ # # ]
472 : : }
473 : : else
474 : : {
475 [ # # ][ # # ]: 0 : sSelected = pTextView->GetSelected();
[ # # ]
476 : : }
477 [ # # ]: 0 : SvxSearchItem * pSrchItem = GetSearchItem();
478 [ # # ]: 0 : pSrchItem->SetSearchString( sSelected );
479 [ # # ][ # # ]: 0 : rSet.Put( *pSrchItem );
480 : : }
481 : 0 : break;
482 : : case FN_REPEAT_SEARCH:
483 : : {
484 [ # # ][ # # ]: 0 : if(!GetSearchItem())
485 [ # # ]: 0 : rSet.DisableItem(nWhich);
486 : : };
487 : 0 : break;
488 : : case SID_UNDO:
489 : : case SID_REDO:
490 : : {
491 [ # # ][ # # ]: 0 : ::svl::IUndoManager& rMgr = pTextView->GetTextEngine()->GetUndoManager();
492 : 0 : sal_uInt16 nCount = 0;
493 [ # # ]: 0 : if(nWhich == SID_UNDO)
494 : : {
495 [ # # ]: 0 : nCount = rMgr.GetUndoActionCount();
496 [ # # ]: 0 : if(nCount)
497 : : {
498 [ # # ][ # # ]: 0 : String aStr(SvtResId( STR_UNDO));
499 [ # # ][ # # ]: 0 : aStr += rMgr.GetUndoActionComment(--nCount);
500 [ # # ][ # # ]: 0 : rSet.Put(SfxStringItem(nWhich, aStr));
[ # # ][ # # ]
501 : : }
502 : : else
503 [ # # ]: 0 : rSet.DisableItem(nWhich);
504 : : }
505 : : else
506 : : {
507 [ # # ]: 0 : nCount = rMgr.GetRedoActionCount();
508 [ # # ]: 0 : if(nCount)
509 : : {
510 [ # # ][ # # ]: 0 : String aStr(SvtResId( STR_REDO));
511 [ # # ][ # # ]: 0 : aStr += rMgr.GetRedoActionComment(--nCount);
512 [ # # ][ # # ]: 0 : rSet.Put(SfxStringItem(nWhich,aStr));
[ # # ][ # # ]
513 : : }
514 : : else
515 [ # # ]: 0 : rSet.DisableItem(nWhich);
516 : : }
517 : : }
518 : 0 : break;
519 : : case SID_MAIL_SENDDOCASPDF:
520 : : case SID_MAIL_SENDDOC :
521 : : case SID_EXPORTDOCASPDF:
522 : : case SID_DIRECTEXPORTDOCASPDF:
523 : : case SID_EXPORTDOC:
524 : : case SID_REPEAT:
525 : : case SID_BROWSER_MODE:
526 : : case FN_PRINT_LAYOUT:
527 [ # # ]: 0 : rSet.DisableItem(nWhich);
528 : 0 : break;
529 : : case SID_CUT:
530 : : case SID_COPY:
531 [ # # ][ # # ]: 0 : if(!pTextView->HasSelection())
532 [ # # ]: 0 : rSet.DisableItem(nWhich);
533 : 0 : break;
534 : : case SID_PASTE:
535 : : {
536 : : TransferableDataHelper aDataHelper(
537 : : TransferableDataHelper::CreateFromSystemClipboard(
538 [ # # ]: 0 : &aEditWin) );
539 [ # # ][ # # ]: 0 : sal_Bool bDisable = !aDataHelper.GetXTransferable().is() ||
[ # # ]
540 [ # # ][ # # ]: 0 : 0 == aDataHelper.GetFormatCount();
[ # # ]
541 [ # # ]: 0 : if( bDisable )
542 [ # # ][ # # ]: 0 : rSet.DisableItem(nWhich);
543 : : }
544 : 0 : break;
545 : : }
546 [ # # ]: 0 : nWhich = aIter.NextWhich();
547 [ # # ]: 0 : }
548 : 0 : }
549 : :
550 : 0 : SvxSearchItem* SwSrcView::GetSearchItem()
551 : : {
552 [ # # ]: 0 : if(!pSearchItem)
553 : : {
554 [ # # ]: 0 : pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
555 : : }
556 : 0 : return pSearchItem;
557 : : }
558 : :
559 : 0 : void SwSrcView::SetSearchItem( const SvxSearchItem& rItem )
560 : : {
561 [ # # ]: 0 : delete pSearchItem;
562 : 0 : pSearchItem = (SvxSearchItem*)rItem.Clone();
563 : 0 : }
564 : :
565 : 0 : sal_uInt16 SwSrcView::StartSearchAndReplace(const SvxSearchItem& rSearchItem,
566 : : sal_Bool bFromStart,
567 : : sal_Bool bApi,
568 : : sal_Bool bRecursive)
569 : : {
570 : 0 : ExtTextView* pTextView = aEditWin.GetTextView();
571 [ # # ]: 0 : TextSelection aSel;
572 : 0 : TextPaM aPaM;
573 : :
574 : 0 : sal_Bool bForward = !rSearchItem.GetBackward();
575 [ # # ][ # # ]: 0 : sal_Bool bAtStart = pTextView->GetSelection() == TextSelection( aPaM, aPaM );
576 : :
577 [ # # ]: 0 : if( !bForward )
578 : 0 : aPaM = TextPaM( (sal_uLong)-1, (sal_uInt16)-1 );
579 : :
580 [ # # ]: 0 : if( bFromStart )
581 : : {
582 [ # # ]: 0 : aSel = pTextView->GetSelection();
583 [ # # ][ # # ]: 0 : pTextView->SetSelection( TextSelection( aPaM, aPaM ));
584 : : }
585 : :
586 : 0 : util::SearchOptions aSearchOpt( rSearchItem.GetSearchOptions() );
587 : : aSearchOpt.Locale = SvxCreateLocale(
588 [ # # ][ # # ]: 0 : static_cast< LanguageType >( GetAppLanguage() ) );
589 : :
590 : : sal_uInt16 nFound;
591 : 0 : sal_Bool bAll = sal_False;
592 [ # # # # ]: 0 : switch( rSearchItem.GetCommand() )
593 : : {
594 : : case SVX_SEARCHCMD_FIND:
595 : : case SVX_SEARCHCMD_FIND_ALL:
596 [ # # ]: 0 : nFound = pTextView->Search( aSearchOpt, bForward );
597 : 0 : break;
598 : :
599 : 0 : case SVX_SEARCHCMD_REPLACE_ALL: bAll = sal_True;
600 : : case SVX_SEARCHCMD_REPLACE:
601 [ # # ]: 0 : nFound = pTextView->Replace( aSearchOpt, bAll, bForward );
602 : 0 : break;
603 : :
604 : : default:
605 : 0 : nFound = 0;
606 : : }
607 : :
608 [ # # ]: 0 : if( !nFound )
609 : : {
610 : 0 : sal_Bool bNotFoundMessage = sal_False;
611 [ # # ]: 0 : if(!bRecursive)
612 : : {
613 [ # # ]: 0 : if(!bFromStart)
614 : : {
615 : 0 : bNotFoundMessage = bAtStart;
616 : : }
617 : : else
618 : : {
619 : 0 : bNotFoundMessage = sal_True;
620 [ # # ]: 0 : pTextView->SetSelection( aSel );
621 : : }
622 : : }
623 [ # # ]: 0 : else if(bAtStart)
624 : : {
625 : 0 : bNotFoundMessage = sal_True;
626 : : }
627 : :
628 : :
629 [ # # ]: 0 : if(!bApi)
630 : : {
631 [ # # ]: 0 : if(bNotFoundMessage)
632 : : {
633 [ # # ][ # # ]: 0 : InfoBox( 0, SW_RES(MSG_NOT_FOUND)).Execute();
[ # # ]
634 : : }
635 [ # # ][ # # ]: 0 : else if(!bRecursive && RET_YES ==
[ # # ]
636 : : QueryBox(0, SW_RES( bForward ? MSG_SEARCH_END
637 [ # # ][ # # ]: 0 : : MSG_SEARCH_START)).Execute())
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
638 : : {
639 [ # # ][ # # ]: 0 : pTextView->SetSelection( TextSelection( aPaM, aPaM ) );
640 [ # # ]: 0 : StartSearchAndReplace( rSearchItem, sal_False, sal_False, sal_True );
641 : : }
642 : : }
643 : : }
644 : 0 : return nFound;
645 : : }
646 : :
647 : 0 : sal_uInt16 SwSrcView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool )
648 : : {
649 : 0 : SwDocShell* pDocSh = GetDocShell();
650 [ # # ]: 0 : if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags )
651 : : {
652 : 0 : pDocSh->GetDoc()->setPrinter( pNew, true, true );
653 [ # # ]: 0 : if ( nDiffFlags & SFX_PRINTER_PRINTER )
654 : 0 : pDocSh->SetModified();
655 : : }
656 [ # # ]: 0 : if ( nDiffFlags & SFX_PRINTER_OPTIONS )
657 : 0 : ::SetPrinter( pDocSh->getIDocumentDeviceAccess(), pNew, sal_True );
658 : :
659 [ # # ]: 0 : const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False;
660 [ # # ]: 0 : const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False;
661 [ # # ][ # # ]: 0 : if ( bChgOri || bChgSize )
662 : : {
663 : 0 : pDocSh->SetModified();
664 : : }
665 : 0 : return 0;
666 : : }
667 : :
668 : 0 : SfxPrinter* SwSrcView::GetPrinter( sal_Bool bCreate )
669 : : {
670 : 0 : return GetDocShell()->GetDoc()->getPrinter( bCreate );
671 : : }
672 : :
673 : 0 : sal_Int32 SwSrcView::PrintSource(
674 : : OutputDevice *pOutDev,
675 : : sal_Int32 nPage,
676 : : bool bCalcNumPagesOnly )
677 : : {
678 [ # # ][ # # ]: 0 : if (!pOutDev || nPage <= 0)
679 : 0 : return 0;
680 : :
681 : : //! this a lgorithm for printing the n-th page is very poor since it
682 : : //! needs to go over the text of all previous pages to get to the correct one.
683 : : //! But since HTML source code is expected to be just a small number of pages
684 : : //! even this poor algorithm should be enough...
685 : :
686 [ # # ]: 0 : pOutDev->Push();
687 : :
688 : 0 : TextEngine* pTextEngine = aEditWin.GetTextEngine();
689 [ # # ][ # # ]: 0 : pOutDev->SetMapMode( MAP_100TH_MM );
[ # # ]
690 [ # # ]: 0 : Font aFont( aEditWin.GetOutWin()->GetFont() );
691 [ # # ]: 0 : Size aSize( aFont.GetSize() );
692 [ # # ][ # # ]: 0 : aSize = aEditWin.GetOutWin()->PixelToLogic( aSize, MAP_100TH_MM );
[ # # ]
693 [ # # ]: 0 : aFont.SetSize( aSize );
694 [ # # ]: 0 : aFont.SetColor( COL_BLACK );
695 [ # # ]: 0 : pOutDev->SetFont( aFont );
696 : :
697 [ # # ][ # # ]: 0 : String aTitle( GetViewFrame()->GetWindow().GetText() );
698 : :
699 [ # # ]: 0 : sal_uInt16 nLineHeight = (sal_uInt16) pOutDev->GetTextHeight(); // etwas mehr.
700 : 0 : sal_uInt16 nParaSpace = 10;
701 : :
702 [ # # ]: 0 : Size aPaperSz = pOutDev->GetOutputSize();
703 : 0 : aPaperSz.Width() -= (LMARGPRN + RMARGPRN);
704 : 0 : aPaperSz.Height() -= (TMARGPRN + BMARGPRN);
705 : :
706 : : // nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
707 : 0 : sal_uInt16 nLinespPage = (sal_uInt16) (aPaperSz.Height() / nLineHeight);
708 [ # # ][ # # ]: 0 : sal_uInt16 nCharspLine = (sal_uInt16) (aPaperSz.Width() / pOutDev->GetTextWidth(rtl::OUString('X')));
[ # # ]
709 [ # # ]: 0 : sal_uInt16 nParas = static_cast< sal_uInt16 >( pTextEngine->GetParagraphCount() );
710 : :
711 : 0 : sal_uInt16 nPages = (sal_uInt16) (nParas / nLinespPage + 1 );
712 : 0 : sal_uInt16 nCurPage = 1;
713 : :
714 : : // Header drucken...
715 [ # # ][ # # ]: 0 : if (!bCalcNumPagesOnly && nPage == nCurPage)
716 [ # # ]: 0 : lcl_PrintHeader( *pOutDev, nPages, nCurPage, aTitle );
717 : 0 : const Point aStartPos( LMARGPRN, TMARGPRN );
718 : 0 : Point aPos( aStartPos );
719 [ # # ]: 0 : for ( sal_uInt16 nPara = 0; nPara < nParas; ++nPara )
720 : : {
721 [ # # ]: 0 : String aLine( pTextEngine->GetText( nPara ) );
722 [ # # ]: 0 : lcl_ConvertTabsToSpaces( aLine );
723 : 0 : sal_uInt16 nLines = aLine.Len() / nCharspLine + 1;
724 [ # # ]: 0 : for ( sal_uInt16 nLine = 0; nLine < nLines; ++nLine )
725 : : {
726 [ # # ]: 0 : String aTmpLine( aLine, nLine * nCharspLine, nCharspLine );
727 : 0 : aPos.Y() += nLineHeight;
728 [ # # ]: 0 : if ( aPos.Y() > ( aPaperSz.Height() + TMARGPRN - nLineHeight/2 ) )
729 : : {
730 : 0 : ++nCurPage;
731 [ # # ][ # # ]: 0 : if (!bCalcNumPagesOnly && nPage == nCurPage)
732 [ # # ]: 0 : lcl_PrintHeader( *pOutDev, nPages, nCurPage, aTitle );
733 : 0 : aPos = aStartPos;
734 : : }
735 [ # # ][ # # ]: 0 : if (!bCalcNumPagesOnly && nPage == nCurPage)
736 [ # # ]: 0 : pOutDev->DrawText( aPos, aTmpLine );
737 [ # # ]: 0 : }
738 : 0 : aPos.Y() += nParaSpace;
739 [ # # ]: 0 : }
740 : :
741 [ # # ]: 0 : pOutDev->Pop();
742 : :
743 : : OSL_ENSURE( bCalcNumPagesOnly || nPage <= nCurPage, "page number out of range" );
744 [ # # ][ # # ]: 0 : return nCurPage;
745 : : }
746 : :
747 : 0 : void SwSrcView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
748 : : {
749 [ # # # # : 0 : if ( rHint.ISA(SfxSimpleHint) &&
# # # # #
# ][ # # ]
750 : : (
751 : 0 : ((SfxSimpleHint&) rHint).GetId() == SFX_HINT_MODECHANGED ||
752 : : (
753 : 0 : ((SfxSimpleHint&) rHint).GetId() == SFX_HINT_TITLECHANGED &&
754 : 0 : !GetDocShell()->IsReadOnly() && aEditWin.IsReadonly()
755 : : )
756 : : )
757 : : )
758 : : {
759 : : // Broadcast kommt nur einmal!
760 : 0 : const SwDocShell* pDocSh = GetDocShell();
761 : 0 : const sal_Bool bReadonly = pDocSh->IsReadOnly();
762 : 0 : aEditWin.SetReadonly(bReadonly);
763 : : }
764 : 0 : SfxViewShell::Notify(rBC, rHint);
765 : 0 : }
766 : :
767 : 0 : void SwSrcView::Load(SwDocShell* pDocShell)
768 : : {
769 : 0 : SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
770 : : const sal_Char *pCharSet =
771 : 0 : rtl_getBestMimeCharsetFromTextEncoding( rHtmlOptions.GetTextEncoding() );
772 : 0 : rtl_TextEncoding eDestEnc = rtl_getTextEncodingFromMimeCharset( pCharSet );
773 : :
774 : 0 : aEditWin.SetReadonly(pDocShell->IsReadOnly());
775 : 0 : aEditWin.SetTextEncoding(eDestEnc);
776 : 0 : SfxMedium* pMedium = pDocShell->GetMedium();
777 : :
778 : 0 : const SfxFilter* pFilter = pMedium->GetFilter();
779 [ # # ][ # # ]: 0 : sal_Bool bHtml = pFilter && pFilter->GetUserData() == "HTML";
780 : 0 : sal_Bool bDocModified = pDocShell->IsModified();
781 [ # # ][ # # ]: 0 : if(bHtml && !bDocModified && pDocShell->HasName())
[ # # ][ # # ]
782 : : {
783 : 0 : SvStream* pStream = pMedium->GetInStream();
784 [ # # ][ # # ]: 0 : if(pStream && 0 == pStream->GetError() )
[ # # ]
785 : : {
786 : : rtl_TextEncoding eHeaderEnc =
787 : : SfxHTMLParser::GetEncodingByHttpHeader(
788 : 0 : pDocShell->GetHeaderAttributes() );
789 [ # # ]: 0 : if( RTL_TEXTENCODING_DONTKNOW == eHeaderEnc )
790 : : {
791 : : const sal_Char *pTmpCharSet =
792 : 0 : rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 );
793 : 0 : eHeaderEnc = rtl_getTextEncodingFromMimeCharset( pTmpCharSet );
794 : : }
795 [ # # ][ # # ]: 0 : if( RTL_TEXTENCODING_DONTKNOW != eHeaderEnc &&
796 : : eDestEnc != eHeaderEnc )
797 : : {
798 : 0 : eDestEnc = eHeaderEnc;
799 : 0 : aEditWin.SetTextEncoding(eDestEnc);
800 : : }
801 : 0 : pStream->SetStreamCharSet( eDestEnc );
802 : 0 : pStream->Seek(0);
803 : 0 : TextEngine* pTextEngine = aEditWin.GetTextEngine();
804 : 0 : pTextEngine->EnableUndo(sal_False);
805 : 0 : aEditWin.Read(*pStream);
806 : 0 : pTextEngine->EnableUndo(sal_True);
807 : : }
808 : : else
809 : : {
810 : 0 : Window *pTmpWindow = &GetViewFrame()->GetWindow();
811 [ # # ][ # # ]: 0 : InfoBox(pTmpWindow, SW_RES(MSG_ERR_SRCSTREAM)).Execute();
[ # # ]
812 : : }
813 : : }
814 : : else
815 : : {
816 [ # # ]: 0 : utl::TempFile aTempFile;
817 : 0 : aTempFile.EnableKillingFile();
818 [ # # ]: 0 : String sFileURL( aTempFile.GetURL() );
819 [ # # ]: 0 : SvtSaveOptions aOpt;
820 : :
821 : : {
822 [ # # ]: 0 : SfxMedium aMedium( sFileURL,STREAM_READWRITE );
823 [ # # ]: 0 : SwWriter aWriter( aMedium, *pDocShell->GetDoc() );
824 : 0 : WriterRef xWriter;
825 [ # # ][ # # ]: 0 : ::GetHTMLWriter(aEmptyStr, aMedium.GetBaseURL( true ), xWriter);
[ # # ][ # # ]
826 [ # # ]: 0 : String sWriteName;
827 [ # # ]: 0 : if (pDocShell->HasName())
828 [ # # ][ # # ]: 0 : sWriteName = pMedium->GetName();
829 : : else
830 [ # # ]: 0 : sWriteName = sFileURL;
831 [ # # ]: 0 : sal_uLong nRes = aWriter.Write(xWriter, &sWriteName);
832 [ # # ]: 0 : if(nRes)
833 : : {
834 [ # # ]: 0 : ErrorHandler::HandleError(ErrCode(nRes));
835 : 0 : aEditWin.SetReadonly(sal_True);
836 : : }
837 [ # # ]: 0 : aMedium.Commit();
838 [ # # ]: 0 : SvStream* pInStream = aMedium.GetInStream();
839 [ # # ]: 0 : pInStream->Seek(0);
840 : 0 : pInStream->SetStreamCharSet( eDestEnc );
841 : :
842 : :
843 [ # # ][ # # ]: 0 : aEditWin.Read(*pInStream);
[ # # ][ # # ]
[ # # ]
844 [ # # ][ # # ]: 0 : }
[ # # ]
845 : : }
846 : 0 : aEditWin.ClearModifyFlag();
847 : :
848 : 0 : eLoadEncoding = eDestEnc;
849 : :
850 [ # # ]: 0 : if(bDocModified)
851 : 0 : pDocShell->SetModified();// das Flag wird zwischendurch zurueckgesetzt
852 : : // AutoLoad abschalten
853 [ # # ]: 0 : pDocShell->SetAutoLoad(INetURLObject(), 0, sal_False);
854 : : OSL_ENSURE(PTR_CAST(SwWebDocShell, pDocShell), "Wieso keine WebDocShell?");
855 : 0 : sal_uInt16 nLine = ((SwWebDocShell*)pDocShell)->GetSourcePara();
856 : 0 : aEditWin.SetStartLine(nLine);
857 : 0 : aEditWin.GetTextEngine()->ResetUndo();
858 : 0 : aEditWin.GetOutWin()->GrabFocus();
859 : 0 : }
860 : :
861 : :
862 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|