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