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: srcedtw.cxx,v $
10 * $Revision: 1.21.252.1 $
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_sw.hxx"
35 #include <hintids.hxx>
41 #include <svtools/textview.hxx>
42 #ifndef _SVX_SVXIDS_HRC
43 #include <svx/svxids.hrc>
45 #ifndef _SCRBAR_HXX //autogen
46 #include <vcl/scrbar.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/app.hxx>
50 #include <svtools/htmltokn.h>
51 #include <svtools/txtattr.hxx>
52 #include <svtools/sourceviewconfig.hxx>
53 #include <svtools/colorcfg.hxx>
54 #include <svx/flstitem.hxx>
55 #include <vcl/metric.hxx>
56 #include <svtools/ctrltool.hxx>
57 #include <tools/time.hxx>
58 #include <swmodule.hxx>
63 #include <srcview.hxx>
74 svtools::ColorConfigEntry eType
;
77 #define MAX_SYNTAX_HIGHLIGHT 20
78 #define MAX_HIGHLIGHTTIME 200
79 #define SYNTAX_HIGHLIGHT_TIMEOUT 200
81 SV_DECL_VARARR(SwTextPortions
, SwTextPortion
,16,16)
83 /* -----------------15.01.97 12.07-------------------
85 --------------------------------------------------*/
87 SV_IMPL_VARARR(SwTextPortions
, SwTextPortion
)
89 /*-----------------15.01.97 12.08-------------------
91 --------------------------------------------------*/
93 static void lcl_Highlight(const String
& rSource
, SwTextPortions
& aPortionList
)
95 const sal_Unicode cOpenBracket
= '<';
96 const sal_Unicode cCloseBracket
= '>';
97 const sal_Unicode cSlash
= '/';
98 const sal_Unicode cExclamation
= '!';
99 const sal_Unicode cMinus
= '-';
100 const sal_Unicode cSpace
= ' ';
101 const sal_Unicode cTab
= 0x09;
102 const sal_Unicode cLF
= 0x0a;
103 const sal_Unicode cCR
= 0x0d;
106 const USHORT nStrLen
= rSource
.Len();
107 USHORT nInsert
= 0; // Anzahl der eingefuegten Portions
108 USHORT nActPos
= 0; //Position, an der '<' gefunden wurde
109 USHORT nOffset
= 0; //Offset von nActPos zur '<'
110 USHORT nPortStart
= USHRT_MAX
; // fuer die TextPortion
111 USHORT nPortEnd
= 0; //
113 while(nActPos
< nStrLen
)
115 svtools::ColorConfigEntry eFoundType
= svtools::HTMLUNKNOWN
;
116 if(rSource
.GetChar(nActPos
) == cOpenBracket
&& nActPos
< nStrLen
- 2 )
118 // 'leere' Portion einfuegen
119 if(nPortEnd
< nActPos
- 1 )
122 // am Anfang nicht verschieben
123 aText
.nStart
= nPortEnd
;
126 aText
.nEnd
= nActPos
- 1;
127 aText
.eType
= svtools::HTMLUNKNOWN
;
128 aPortionList
.Insert(aText
, nInsert
++);
130 sal_Unicode cFollowFirst
= rSource
.GetChar((xub_StrLen
)(nActPos
+ 1));
131 sal_Unicode cFollowNext
= rSource
.GetChar((xub_StrLen
)(nActPos
+ 2));
132 if(cExclamation
== cFollowFirst
)
134 // "<!" SGML oder Kommentar
135 if(cMinus
== cFollowNext
&&
136 nActPos
< nStrLen
- 3 && cMinus
== rSource
.GetChar((xub_StrLen
)(nActPos
+ 3)))
138 eFoundType
= svtools::HTMLCOMMENT
;
141 eFoundType
= svtools::HTMLSGML
;
142 nPortStart
= nActPos
;
143 nPortEnd
= nActPos
+ 1;
145 else if(cSlash
== cFollowFirst
)
147 // "</" Slash ignorieren
148 nPortStart
= nActPos
;
152 if(svtools::HTMLUNKNOWN
== eFoundType
)
154 //jetzt koennte hier ein keyword folgen
155 USHORT nSrchPos
= nActPos
;
156 while(++nSrchPos
< nStrLen
- 1)
158 sal_Unicode cNext
= rSource
.GetChar(nSrchPos
);
159 if( cNext
== cSpace
||
164 else if(cNext
== cCloseBracket
)
169 if(nSrchPos
> nActPos
+ 1)
171 //irgend ein String wurde gefunden
172 String sToken
= rSource
.Copy(nActPos
+ 1, nSrchPos
- nActPos
- 1 );
173 sToken
.ToUpperAscii();
174 int nToken
= ::GetHTMLToken(sToken
);
178 eFoundType
= svtools::HTMLKEYWORD
;
180 nPortStart
= nActPos
;
185 #if OSL_DEBUG_LEVEL > 1
186 DBG_ERROR("Token nicht erkannt!");
187 DBG_ERROR(ByteString(sToken
, gsl_getSystemTextEncoding()).GetBuffer());
193 // jetzt muss noch '>' gesucht werden
194 if(svtools::HTMLUNKNOWN
!= eFoundType
)
197 for(USHORT i
= nPortEnd
; i
< nStrLen
; i
++)
198 if(cCloseBracket
== rSource
.GetChar(i
))
204 if(!bFound
&& (eFoundType
== svtools::HTMLCOMMENT
))
206 // Kommentar ohne Ende in dieser Zeile
208 nPortEnd
= nStrLen
- 1;
211 if(bFound
||(eFoundType
== svtools::HTMLCOMMENT
))
213 SwTextPortion aTextPortion
;
214 aTextPortion
.nLine
= 0;
215 aTextPortion
.nStart
= nPortStart
+ 1;
216 aTextPortion
.nEnd
= nPortEnd
;
217 aTextPortion
.eType
= eFoundType
;
218 aPortionList
.Insert(aTextPortion
, nInsert
++);
219 eFoundType
= svtools::HTMLUNKNOWN
;
226 if(nInsert
&& nPortEnd
< nActPos
- 1)
229 aText
.nStart
= nPortEnd
+ 1;
230 aText
.nEnd
= nActPos
- 1;
231 aText
.eType
= svtools::HTMLUNKNOWN
;
232 aPortionList
.Insert(aText
, nInsert
++);
236 /*--------------------------------------------------------------------
238 --------------------------------------------------------------------*/
241 SwSrcEditWindow::SwSrcEditWindow( Window
* pParent
, SwSrcView
* pParentView
) :
242 Window( pParent
, WB_BORDER
|WB_CLIPCHILDREN
),
250 pSrcView(pParentView
),
251 pSourceViewConfig(new svt::SourceViewConfig
),
254 nStartLine(USHRT_MAX
),
255 eSourceEncoding(gsl_getSystemTextEncoding()),
256 bDoSyntaxHighlight(TRUE
),
259 SetHelpId(HID_SOURCE_EDITWIN
);
261 StartListening(*pSourceViewConfig
);
263 /*--------------------------------------------------------------------
265 --------------------------------------------------------------------*/
266 SwSrcEditWindow::~SwSrcEditWindow()
268 EndListening(*pSourceViewConfig
);
269 delete pSourceViewConfig
;
270 aSyntaxIdleTimer
.Stop();
273 EndListening( *pTextEngine
);
274 pTextEngine
->RemoveView( pTextView
);
285 /*--------------------------------------------------------------------
287 --------------------------------------------------------------------*/
289 void SwSrcEditWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
291 Window::DataChanged( rDCEvt
);
293 switch ( rDCEvt
.GetType() )
295 case DATACHANGED_SETTINGS
:
296 // ScrollBars neu anordnen bzw. Resize ausloesen, da sich
297 // ScrollBar-Groesse geaendert haben kann. Dazu muss dann im
298 // Resize-Handler aber auch die Groesse der ScrollBars aus
299 // den Settings abgefragt werden.
300 if( rDCEvt
.GetFlags() & SETTINGS_STYLE
)
306 void SwSrcEditWindow::Resize()
308 // ScrollBars, etc. passiert in Adjust...
311 long nVisY
= pTextView
->GetStartDocPos().Y();
312 pTextView
->ShowCursor();
313 Size
aOutSz( GetOutputSizePixel() );
314 long nMaxVisAreaStart
= pTextView
->GetTextEngine()->GetTextHeight() - aOutSz
.Height();
315 if ( nMaxVisAreaStart
< 0 )
316 nMaxVisAreaStart
= 0;
317 if ( pTextView
->GetStartDocPos().Y() > nMaxVisAreaStart
)
319 Point
aStartDocPos( pTextView
->GetStartDocPos() );
320 aStartDocPos
.Y() = nMaxVisAreaStart
;
321 pTextView
->SetStartDocPos( aStartDocPos
);
322 pTextView
->ShowCursor();
324 long nScrollStd
= GetSettings().GetStyleSettings().GetScrollBarSize();
325 Size
aScrollSz(aOutSz
.Width() - nScrollStd
, nScrollStd
);
326 Point
aScrollPos(0, aOutSz
.Height() - nScrollStd
);
328 pHScrollbar
->SetPosSizePixel( aScrollPos
, aScrollSz
);
330 aScrollSz
.Width() = aScrollSz
.Height();
331 aScrollSz
.Height() = aOutSz
.Height();
332 aScrollPos
= Point(aOutSz
.Width() - nScrollStd
, 0);
334 pVScrollbar
->SetPosSizePixel( aScrollPos
, aScrollSz
);
335 aOutSz
.Width() -= nScrollStd
;
336 aOutSz
.Height() -= nScrollStd
;
337 pOutWin
->SetOutputSizePixel(aOutSz
);
340 // Zeile im ersten Resize setzen
341 if(USHRT_MAX
!= nStartLine
)
343 if(nStartLine
< pTextEngine
->GetParagraphCount())
345 TextSelection
aSel(TextPaM( nStartLine
, 0 ), TextPaM( nStartLine
, 0x0 ));
346 pTextView
->SetSelection(aSel
);
347 pTextView
->ShowCursor();
349 nStartLine
= USHRT_MAX
;
352 if ( nVisY
!= pTextView
->GetStartDocPos().Y() )
358 /*--------------------------------------------------------------------
360 --------------------------------------------------------------------*/
362 void TextViewOutWin::DataChanged( const DataChangedEvent
& rDCEvt
)
364 Window::DataChanged( rDCEvt
);
366 switch( rDCEvt
.GetType() )
368 case DATACHANGED_SETTINGS
:
369 // den Settings abgefragt werden.
370 if( rDCEvt
.GetFlags() & SETTINGS_STYLE
)
372 const Color
&rCol
= GetSettings().GetStyleSettings().GetWindowColor();
373 SetBackground( rCol
);
374 Font
aFont( pTextView
->GetTextEngine()->GetFont() );
375 aFont
.SetFillColor( rCol
);
376 pTextView
->GetTextEngine()->SetFont( aFont
);
382 void TextViewOutWin::MouseMove( const MouseEvent
&rEvt
)
385 pTextView
->MouseMove( rEvt
);
388 /*--------------------------------------------------------------------
390 --------------------------------------------------------------------*/
393 void TextViewOutWin::MouseButtonUp( const MouseEvent
&rEvt
)
397 pTextView
->MouseButtonUp( rEvt
);
398 SfxBindings
& rBindings
= ((SwSrcEditWindow
*)GetParent())->GetSrcView()->GetViewFrame()->GetBindings();
399 rBindings
.Invalidate( SID_TABLE_CELL
);
400 rBindings
.Invalidate( SID_CUT
);
401 rBindings
.Invalidate( SID_COPY
);
405 /*--------------------------------------------------------------------
407 --------------------------------------------------------------------*/
410 void TextViewOutWin::MouseButtonDown( const MouseEvent
&rEvt
)
414 pTextView
->MouseButtonDown( rEvt
);
417 /*--------------------------------------------------------------------
419 --------------------------------------------------------------------*/
422 void TextViewOutWin::Command( const CommandEvent
& rCEvt
)
424 switch(rCEvt
.GetCommand())
426 case COMMAND_CONTEXTMENU
:
427 ((SwSrcEditWindow
*)GetParent())->GetSrcView()->GetViewFrame()->
428 GetDispatcher()->ExecutePopup();
431 case COMMAND_STARTAUTOSCROLL
:
432 case COMMAND_AUTOSCROLL
:
434 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
435 if( !pWData
|| COMMAND_WHEEL_ZOOM
!= pWData
->GetMode() )
437 ((SwSrcEditWindow
*)GetParent())->HandleWheelCommand( rCEvt
);
444 pTextView
->Command( rCEvt
);
446 Window::Command(rCEvt
);
451 /*--------------------------------------------------------------------
453 --------------------------------------------------------------------*/
456 void TextViewOutWin::KeyInput( const KeyEvent
& rKEvt
)
459 SwSrcEditWindow
* pSrcEditWin
= (SwSrcEditWindow
*)GetParent();
460 BOOL bChange
= !pSrcEditWin
->IsReadonly() || !TextEngine::DoesKeyChangeText( rKEvt
);
462 bDone
= pTextView
->KeyInput( rKEvt
);
464 SfxBindings
& rBindings
= ((SwSrcEditWindow
*)GetParent())->GetSrcView()->GetViewFrame()->GetBindings();
467 if ( !SfxViewShell::Current()->KeyInput( rKEvt
) )
468 Window::KeyInput( rKEvt
);
472 rBindings
.Invalidate( SID_TABLE_CELL
);
473 if ( rKEvt
.GetKeyCode().GetGroup() == KEYGROUP_CURSOR
)
474 rBindings
.Update( SID_BASICIDE_STAT_POS
);
475 if (pSrcEditWin
->GetTextEngine()->IsModified() )
477 rBindings
.Invalidate( SID_SAVEDOC
);
478 rBindings
.Invalidate( SID_DOC_MODIFIED
);
480 if( rKEvt
.GetKeyCode().GetCode() == KEY_INSERT
)
481 rBindings
.Invalidate( SID_ATTR_INSERT
);
484 rBindings
.Invalidate( SID_CUT
);
485 rBindings
.Invalidate( SID_COPY
);
487 SwDocShell
* pDocShell
= pSrcEditWin
->GetSrcView()->GetDocShell();
488 if(pSrcEditWin
->GetTextEngine()->IsModified())
490 pDocShell
->SetModified();
494 /*--------------------------------------------------------------------
496 --------------------------------------------------------------------*/
499 void TextViewOutWin::Paint( const Rectangle
& rRect
)
501 pTextView
->Paint( rRect
);
504 /*--------------------------------------------------------------------
506 --------------------------------------------------------------------*/
509 void SwSrcEditWindow::CreateTextEngine()
511 const Color
&rCol
= GetSettings().GetStyleSettings().GetWindowColor();
512 pOutWin
= new TextViewOutWin(this, 0);
513 pOutWin
->SetBackground(Wallpaper(rCol
));
514 pOutWin
->SetPointer(Pointer(POINTER_TEXT
));
518 pHScrollbar
= new ScrollBar(this, WB_3DLOOK
|WB_HSCROLL
|WB_DRAG
);
519 pHScrollbar
->EnableRTL( false ); // #107300# --- RTL --- no mirroring for scrollbars
520 pHScrollbar
->SetScrollHdl(LINK(this, SwSrcEditWindow
, ScrollHdl
));
523 pVScrollbar
= new ScrollBar(this, WB_3DLOOK
|WB_VSCROLL
|WB_DRAG
);
524 pVScrollbar
->EnableRTL( false ); // #107300# --- RTL --- no mirroring for scrollbars
525 pVScrollbar
->SetScrollHdl(LINK(this, SwSrcEditWindow
, ScrollHdl
));
526 pHScrollbar
->EnableDrag();
529 pTextEngine
= new ExtTextEngine
;
530 pTextView
= new ExtTextView( pTextEngine
, pOutWin
);
531 pTextView
->SetAutoIndentMode(TRUE
);
532 pOutWin
->SetTextView(pTextView
);
534 pTextEngine
->SetUpdateMode( FALSE
);
535 pTextEngine
->InsertView( pTextView
);
538 aFont
.SetTransparent( FALSE
);
539 aFont
.SetFillColor( rCol
);
540 SetPointFont( aFont
);
542 aFont
.SetFillColor( rCol
);
543 pOutWin
->SetFont( aFont
);
544 pTextEngine
->SetFont( aFont
);
546 aSyntaxIdleTimer
.SetTimeout( SYNTAX_HIGHLIGHT_TIMEOUT
);
547 aSyntaxIdleTimer
.SetTimeoutHdl( LINK( this, SwSrcEditWindow
, SyntaxTimerHdl
) );
549 pTextEngine
->EnableUndo( TRUE
);
550 pTextEngine
->SetUpdateMode( TRUE
);
552 pTextView
->ShowCursor( TRUE
, TRUE
);
554 StartListening( *pTextEngine
);
556 SfxBindings
& rBind
= GetSrcView()->GetViewFrame()->GetBindings();
557 rBind
.Invalidate( SID_TABLE_CELL
);
558 // rBind.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
561 /*--------------------------------------------------------------------
563 --------------------------------------------------------------------*/
565 /*--------------------------------------------------------------------
567 --------------------------------------------------------------------*/
570 void SwSrcEditWindow::SetScrollBarRanges()
572 // Extra-Methode, nicht InitScrollBars, da auch fuer TextEngine-Events.
574 pHScrollbar
->SetRange( Range( 0, nCurTextWidth
-1 ) );
575 pVScrollbar
->SetRange( Range(0, pTextEngine
->GetTextHeight()-1) );
578 /*--------------------------------------------------------------------
580 --------------------------------------------------------------------*/
583 void SwSrcEditWindow::InitScrollBars()
585 SetScrollBarRanges();
587 Size
aOutSz( pOutWin
->GetOutputSizePixel() );
588 pVScrollbar
->SetVisibleSize( aOutSz
.Height() );
589 pVScrollbar
->SetPageSize( aOutSz
.Height() * 8 / 10 );
590 pVScrollbar
->SetLineSize( pOutWin
->GetTextHeight() );
591 pVScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
592 pHScrollbar
->SetVisibleSize( aOutSz
.Width() );
593 pHScrollbar
->SetPageSize( aOutSz
.Width() * 8 / 10 );
594 pHScrollbar
->SetLineSize( pOutWin
->GetTextWidth( 'x' ) );
595 pHScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().X() );
599 /*--------------------------------------------------------------------
601 --------------------------------------------------------------------*/
604 IMPL_LINK(SwSrcEditWindow
, ScrollHdl
, ScrollBar
*, pScroll
)
606 if(pScroll
== pVScrollbar
)
608 long nDiff
= pTextView
->GetStartDocPos().Y() - pScroll
->GetThumbPos();
609 GetTextView()->Scroll( 0, nDiff
);
610 pTextView
->ShowCursor( FALSE
, TRUE
);
611 pScroll
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
615 long nDiff
= pTextView
->GetStartDocPos().X() - pScroll
->GetThumbPos();
616 GetTextView()->Scroll( nDiff
, 0 );
617 pTextView
->ShowCursor( FALSE
, TRUE
);
618 pScroll
->SetThumbPos( pTextView
->GetStartDocPos().X() );
620 GetSrcView()->GetViewFrame()->GetBindings().Invalidate( SID_TABLE_CELL
);
624 /*-----------------15.01.97 09.22-------------------
626 --------------------------------------------------*/
628 IMPL_LINK( SwSrcEditWindow
, SyntaxTimerHdl
, Timer
*, pTimer
)
630 Time aSyntaxCheckStart
;
631 DBG_ASSERT( pTextView
, "Noch keine View, aber Syntax-Highlight ?!" );
632 // pTextEngine->SetUpdateMode( FALSE );
634 bHighlighting
= TRUE
;
637 // zuerst wird der Bereich um dem Cursor bearbeitet
638 TextSelection aSel
= pTextView
->GetSelection();
639 USHORT nCur
= (USHORT
)aSel
.GetStart().GetPara();
644 if(aSyntaxLineTable
.Count())
645 for(USHORT i
= 0; i
< 80 && nCount
< 40; i
++, nCur
++)
647 void * p
= aSyntaxLineTable
.Get(nCur
);
650 DoSyntaxHighlight( nCur
);
651 aSyntaxLineTable
.Remove( nCur
);
653 if(!aSyntaxLineTable
.Count())
655 if((Time().GetTime() - aSyntaxCheckStart
.GetTime()) > MAX_HIGHLIGHTTIME
)
657 pTimer
->SetTimeout( 2 * SYNTAX_HIGHLIGHT_TIMEOUT
);
663 // wenn dann noch etwas frei ist, wird von Beginn an weitergearbeitet
664 void* p
= aSyntaxLineTable
.First();
665 while ( p
&& nCount
< MAX_SYNTAX_HIGHLIGHT
)
667 nLine
= (USHORT
)aSyntaxLineTable
.GetCurKey();
668 DoSyntaxHighlight( nLine
);
669 USHORT nCurKey
= (USHORT
)aSyntaxLineTable
.GetCurKey();
670 p
= aSyntaxLineTable
.Next();
671 aSyntaxLineTable
.Remove(nCurKey
);
673 if(Time().GetTime() - aSyntaxCheckStart
.GetTime() > MAX_HIGHLIGHTTIME
)
675 pTimer
->SetTimeout( 2 * SYNTAX_HIGHLIGHT_TIMEOUT
);
679 // os: #43050# hier wird ein TextView-Problem umpopelt:
680 // waehrend des Highlightings funktionierte das Scrolling nicht
681 /* MT: Shouldn't be a oproblem any more, using IdeFormatter in Insert/RemoveAttrib now.
683 TextView* pTmp = pTextEngine->GetActiveView();
684 pTextEngine->SetActiveView(0);
685 // pTextEngine->SetUpdateMode( TRUE );
686 pTextEngine->SetActiveView(pTmp);
687 pTextView->ShowCursor(FALSE, FALSE);
690 if(aSyntaxLineTable
.Count() && !pTimer
->IsActive())
692 // SyntaxTimerHdl wird gerufen, wenn Text-Aenderung
693 // => gute Gelegenheit, Textbreite zu ermitteln!
694 long nPrevTextWidth
= nCurTextWidth
;
695 nCurTextWidth
= pTextEngine
->CalcTextWidth() + 25; // kleine Toleranz
696 if ( nCurTextWidth
!= nPrevTextWidth
)
697 SetScrollBarRanges();
698 bHighlighting
= FALSE
;
702 /*-----------------15.01.97 10.01-------------------
704 --------------------------------------------------*/
706 void SwSrcEditWindow::DoSyntaxHighlight( USHORT nPara
)
708 // Durch das DelayedSyntaxHighlight kann es passieren,
709 // dass die Zeile nicht mehr existiert!
710 if ( nPara
< pTextEngine
->GetParagraphCount() )
712 BOOL bTempModified
= IsModified();
713 pTextEngine
->RemoveAttribs( nPara
, (BOOL
)TRUE
);
714 String
aSource( pTextEngine
->GetText( nPara
) );
715 pTextEngine
->SetUpdateMode( FALSE
);
716 ImpDoHighlight( aSource
, nPara
);
717 // os: #43050# hier wird ein TextView-Problem umpopelt:
718 // waehrend des Highlightings funktionierte das Scrolling nicht
719 TextView
* pTmp
= pTextEngine
->GetActiveView();
720 pTmp
->SetAutoScroll(FALSE
);
721 pTextEngine
->SetActiveView(0);
722 pTextEngine
->SetUpdateMode( TRUE
);
723 pTextEngine
->SetActiveView(pTmp
);
724 // Bug 72887 show the cursor
725 pTmp
->SetAutoScroll(TRUE
);
726 pTmp
->ShowCursor( FALSE
/*pTmp->IsAutoScroll()*/ );
733 /*-----------------15.01.97 09.49-------------------
735 --------------------------------------------------*/
737 void SwSrcEditWindow::DoDelayedSyntaxHighlight( USHORT nPara
)
739 if ( !bHighlighting
&& bDoSyntaxHighlight
)
741 aSyntaxLineTable
.Insert( nPara
, (void*)(USHORT
)1 );
742 aSyntaxIdleTimer
.Start();
746 /*-----------------15.01.97 11.32-------------------
748 --------------------------------------------------*/
750 void SwSrcEditWindow::ImpDoHighlight( const String
& rSource
, USHORT nLineOff
)
752 SwTextPortions aPortionList
;
753 lcl_Highlight(rSource
, aPortionList
);
755 USHORT nCount
= aPortionList
.Count();
759 SwTextPortion
& rLast
= aPortionList
[nCount
-1];
760 if ( rLast
.nStart
> rLast
.nEnd
) // Nur bis Bug von MD behoeben
763 aPortionList
.Remove( nCount
);
769 // Wenn haufig gleiche Farbe, dazwischen Blank ohne Farbe,
770 // ggf. zusammenfassen, oder zumindest das Blank,
771 // damit weniger Attribute
772 BOOL bOptimizeHighlight
= TRUE
; // war in der BasicIDE static
773 if ( bOptimizeHighlight
)
775 // Es muessen nur die Blanks und Tabs mit attributiert werden.
776 // Wenn zwei gleiche Attribute hintereinander eingestellt werden,
777 // optimiert das die TextEngine.
781 USHORT nLine
= aPortionList
[0].nLine
;
783 for ( USHORT i
= 0; i
< nCount
; i
++ )
785 SwTextPortion
& r
= aPortionList
[i
];
786 DBG_ASSERT( r
.nLine
== nLine
, "doch mehrere Zeilen ?" );
787 if ( r
.nStart
> r
.nEnd
) // Nur bis Bug von MD behoeben
790 if ( r
.nStart
> nLastEnd
)
792 // Kann ich mich drauf verlassen, dass alle ausser
793 // Blank und Tab gehighlightet wird ?!
797 if ( ( i
== (nCount
-1) ) && ( r
.nEnd
< rSource
.Len() ) )
798 r
.nEnd
= rSource
.Len();
802 for ( USHORT i
= 0; i
< aPortionList
.Count(); i
++ )
804 SwTextPortion
& r
= aPortionList
[i
];
805 if ( r
.nStart
> r
.nEnd
) // Nur bis Bug von MD behoeben
807 if(r
.eType
!= svtools::HTMLSGML
&&
808 r
.eType
!= svtools::HTMLCOMMENT
&&
809 r
.eType
!= svtools::HTMLKEYWORD
&&
810 r
.eType
!= svtools::HTMLUNKNOWN
)
811 r
.eType
= svtools::HTMLUNKNOWN
;
812 Color
aColor((ColorData
)SW_MOD()->GetColorConfig().GetColorValue((svtools::ColorConfigEntry
)r
.eType
).nColor
);
813 USHORT nLine
= nLineOff
+r
.nLine
; //
814 pTextEngine
->SetAttrib( TextAttribFontColor( aColor
), nLine
, r
.nStart
, r
.nEnd
+1, TRUE
);
818 /*-----------------30.06.97 09:12-------------------
820 --------------------------------------------------*/
822 void SwSrcEditWindow::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
824 if ( rHint
.ISA( TextHint
) )
826 const TextHint
& rTextHint
= (const TextHint
&)rHint
;
827 if( rTextHint
.GetId() == TEXT_HINT_VIEWSCROLLED
)
829 pHScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().X() );
830 pVScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
832 else if( rTextHint
.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED
)
834 if ( (long)pTextEngine
->GetTextHeight() < pOutWin
->GetOutputSizePixel().Height() )
835 pTextView
->Scroll( 0, pTextView
->GetStartDocPos().Y() );
836 pVScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
837 SetScrollBarRanges();
839 else if( ( rTextHint
.GetId() == TEXT_HINT_PARAINSERTED
) ||
840 ( rTextHint
.GetId() == TEXT_HINT_PARACONTENTCHANGED
) )
842 DoDelayedSyntaxHighlight( (USHORT
)rTextHint
.GetValue() );
845 else if(&rBC
== pSourceViewConfig
)
849 /*-----------------30.06.97 13:22-------------------
851 --------------------------------------------------*/
853 void SwSrcEditWindow::Invalidate(USHORT
)
855 pOutWin
->Invalidate();
856 Window::Invalidate();
860 void SwSrcEditWindow::Command( const CommandEvent
& rCEvt
)
862 switch(rCEvt
.GetCommand())
865 case COMMAND_STARTAUTOSCROLL
:
866 case COMMAND_AUTOSCROLL
:
868 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
869 if( !pWData
|| COMMAND_WHEEL_ZOOM
!= pWData
->GetMode() )
870 HandleScrollCommand( rCEvt
, pHScrollbar
, pVScrollbar
);
874 Window::Command(rCEvt
);
878 void SwSrcEditWindow::HandleWheelCommand( const CommandEvent
& rCEvt
)
880 pTextView
->Command(rCEvt
);
881 HandleScrollCommand( rCEvt
, pHScrollbar
, pVScrollbar
);
884 void SwSrcEditWindow::GetFocus()
886 pOutWin
->GrabFocus();
889 /*void SwSrcEditWindow::LoseFocus()
892 // pOutWin->LoseFocus();
893 // rView.LostFocus();
895 /* -----------------------------29.08.2002 13:21------------------------------
897 ---------------------------------------------------------------------------*/
898 BOOL
lcl_GetLanguagesForEncoding(rtl_TextEncoding eEnc
, LanguageType aLanguages
[])
902 case RTL_TEXTENCODING_UTF7
:
903 case RTL_TEXTENCODING_UTF8
:
904 // don#t fill - all LANGUAGE_SYSTEM means unicode font has to be used
908 case RTL_TEXTENCODING_ISO_8859_3
:
909 case RTL_TEXTENCODING_ISO_8859_1
:
910 case RTL_TEXTENCODING_MS_1252
:
911 case RTL_TEXTENCODING_APPLE_ROMAN
:
912 case RTL_TEXTENCODING_IBM_850
:
913 case RTL_TEXTENCODING_ISO_8859_14
:
914 case RTL_TEXTENCODING_ISO_8859_15
:
915 //fill with western languages
916 aLanguages
[0] = LANGUAGE_GERMAN
;
917 aLanguages
[1] = LANGUAGE_FRENCH
;
918 aLanguages
[2] = LANGUAGE_ITALIAN
;
919 aLanguages
[3] = LANGUAGE_SPANISH
;
922 case RTL_TEXTENCODING_IBM_865
:
924 aLanguages
[0] = LANGUAGE_FINNISH
;
925 aLanguages
[1] = LANGUAGE_NORWEGIAN
;
926 aLanguages
[2] = LANGUAGE_SWEDISH
;
927 aLanguages
[3] = LANGUAGE_DANISH
;
930 case RTL_TEXTENCODING_ISO_8859_10
:
931 case RTL_TEXTENCODING_ISO_8859_13
:
932 case RTL_TEXTENCODING_ISO_8859_2
:
933 case RTL_TEXTENCODING_IBM_852
:
934 case RTL_TEXTENCODING_MS_1250
:
935 case RTL_TEXTENCODING_APPLE_CENTEURO
:
936 aLanguages
[0] = LANGUAGE_POLISH
;
937 aLanguages
[1] = LANGUAGE_CZECH
;
938 aLanguages
[2] = LANGUAGE_HUNGARIAN
;
939 aLanguages
[3] = LANGUAGE_SLOVAK
;
942 case RTL_TEXTENCODING_ISO_8859_4
:
943 case RTL_TEXTENCODING_IBM_775
:
944 case RTL_TEXTENCODING_MS_1257
:
945 aLanguages
[0] = LANGUAGE_LATVIAN
;
946 aLanguages
[1] = LANGUAGE_LITHUANIAN
;
947 aLanguages
[2] = LANGUAGE_ESTONIAN
;
950 case RTL_TEXTENCODING_IBM_863
: aLanguages
[0] = LANGUAGE_FRENCH_CANADIAN
; break;
951 case RTL_TEXTENCODING_APPLE_FARSI
: aLanguages
[0] = LANGUAGE_FARSI
; break;
952 case RTL_TEXTENCODING_APPLE_ROMANIAN
:aLanguages
[0] = LANGUAGE_ROMANIAN
; break;
954 case RTL_TEXTENCODING_IBM_861
:
955 case RTL_TEXTENCODING_APPLE_ICELAND
:
956 aLanguages
[0] = LANGUAGE_ICELANDIC
;
959 case RTL_TEXTENCODING_APPLE_CROATIAN
:aLanguages
[0] = LANGUAGE_CROATIAN
; break;
961 case RTL_TEXTENCODING_IBM_437
:
962 case RTL_TEXTENCODING_ASCII_US
: aLanguages
[0] = LANGUAGE_ENGLISH
; break;
964 case RTL_TEXTENCODING_IBM_862
:
965 case RTL_TEXTENCODING_MS_1255
:
966 case RTL_TEXTENCODING_APPLE_HEBREW
:
967 case RTL_TEXTENCODING_ISO_8859_8
:
968 aLanguages
[0] = LANGUAGE_HEBREW
;
971 case RTL_TEXTENCODING_IBM_857
:
972 case RTL_TEXTENCODING_MS_1254
:
973 case RTL_TEXTENCODING_APPLE_TURKISH
:
974 case RTL_TEXTENCODING_ISO_8859_9
:
975 aLanguages
[0] = LANGUAGE_TURKISH
;
978 case RTL_TEXTENCODING_IBM_860
:
979 aLanguages
[0] = LANGUAGE_PORTUGUESE
;
982 case RTL_TEXTENCODING_IBM_869
:
983 case RTL_TEXTENCODING_MS_1253
:
984 case RTL_TEXTENCODING_APPLE_GREEK
:
985 case RTL_TEXTENCODING_ISO_8859_7
:
986 case RTL_TEXTENCODING_IBM_737
:
987 aLanguages
[0] = LANGUAGE_GREEK
;
990 case RTL_TEXTENCODING_KOI8_R
:
991 case RTL_TEXTENCODING_ISO_8859_5
:
992 case RTL_TEXTENCODING_IBM_855
:
993 case RTL_TEXTENCODING_MS_1251
:
994 case RTL_TEXTENCODING_IBM_866
:
995 case RTL_TEXTENCODING_APPLE_CYRILLIC
:
996 aLanguages
[0] = LANGUAGE_RUSSIAN
;
999 case RTL_TEXTENCODING_APPLE_UKRAINIAN
:
1000 case RTL_TEXTENCODING_KOI8_U
:
1001 aLanguages
[0] = LANGUAGE_UKRAINIAN
;
1004 case RTL_TEXTENCODING_IBM_864
:
1005 case RTL_TEXTENCODING_MS_1256
:
1006 case RTL_TEXTENCODING_ISO_8859_6
:
1007 case RTL_TEXTENCODING_APPLE_ARABIC
:
1008 aLanguages
[0] = LANGUAGE_ARABIC_SAUDI_ARABIA
;
1011 case RTL_TEXTENCODING_APPLE_CHINTRAD
:
1012 case RTL_TEXTENCODING_MS_950
:
1013 case RTL_TEXTENCODING_GBT_12345
:
1014 case RTL_TEXTENCODING_BIG5
:
1015 case RTL_TEXTENCODING_EUC_TW
:
1016 case RTL_TEXTENCODING_BIG5_HKSCS
:
1017 aLanguages
[0] = LANGUAGE_CHINESE_TRADITIONAL
;
1020 case RTL_TEXTENCODING_EUC_JP
:
1021 case RTL_TEXTENCODING_ISO_2022_JP
:
1022 case RTL_TEXTENCODING_JIS_X_0201
:
1023 case RTL_TEXTENCODING_JIS_X_0208
:
1024 case RTL_TEXTENCODING_JIS_X_0212
:
1025 case RTL_TEXTENCODING_APPLE_JAPANESE
:
1026 case RTL_TEXTENCODING_MS_932
:
1027 case RTL_TEXTENCODING_SHIFT_JIS
:
1028 aLanguages
[0] = LANGUAGE_JAPANESE
;
1031 case RTL_TEXTENCODING_GB_2312
:
1032 case RTL_TEXTENCODING_MS_936
:
1033 case RTL_TEXTENCODING_GBK
:
1034 case RTL_TEXTENCODING_GB_18030
:
1035 case RTL_TEXTENCODING_APPLE_CHINSIMP
:
1036 case RTL_TEXTENCODING_EUC_CN
:
1037 case RTL_TEXTENCODING_ISO_2022_CN
:
1038 aLanguages
[0] = LANGUAGE_CHINESE_SIMPLIFIED
;
1041 case RTL_TEXTENCODING_APPLE_KOREAN
:
1042 case RTL_TEXTENCODING_MS_949
:
1043 case RTL_TEXTENCODING_EUC_KR
:
1044 case RTL_TEXTENCODING_ISO_2022_KR
:
1045 case RTL_TEXTENCODING_MS_1361
:
1046 aLanguages
[0] = LANGUAGE_KOREAN
;
1049 case RTL_TEXTENCODING_APPLE_THAI
:
1050 case RTL_TEXTENCODING_MS_874
:
1051 case RTL_TEXTENCODING_TIS_620
:
1052 aLanguages
[0] = LANGUAGE_THAI
;
1054 // case RTL_TEXTENCODING_SYMBOL :
1055 // case RTL_TEXTENCODING_DONTKNOW: :
1056 default: aLanguages
[0] = Application::GetSettings().GetUILanguage();
1058 return aLanguages
[0] != LANGUAGE_SYSTEM
;
1060 void SwSrcEditWindow::SetFont()
1062 String sFontName
= pSourceViewConfig
->GetFontName();
1063 if(!sFontName
.Len())
1065 LanguageType aLanguages
[5] =
1067 LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
1070 if(lcl_GetLanguagesForEncoding(eSourceEncoding
, aLanguages
))
1072 //TODO: check for multiple languages
1073 aFont
= OutputDevice::GetDefaultFont(DEFAULTFONT_FIXED
, aLanguages
[0], 0, this);
1076 aFont
= OutputDevice::GetDefaultFont(DEFAULTFONT_SANS_UNICODE
,
1077 Application::GetSettings().GetLanguage(), 0, this);
1078 sFontName
= aFont
.GetName();
1080 const SvxFontListItem
* pFontListItem
=
1081 (const SvxFontListItem
* )pSrcView
->GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST
);
1082 const FontList
* pList
= pFontListItem
->GetFontList();
1083 FontInfo aInfo
= pList
->Get(sFontName
,WEIGHT_NORMAL
, ITALIC_NONE
);
1085 const Font
& rFont
= GetTextEngine()->GetFont();
1087 Size
aSize(rFont
.GetSize());
1088 //font height is stored in point and set in twip
1089 aSize
.Height() = pSourceViewConfig
->GetFontHeight() * 20;
1090 aFont
.SetSize(pOutWin
->LogicToPixel(aSize
, MAP_TWIP
));
1091 GetTextEngine()->SetFont( aFont
);
1092 pOutWin
->SetFont(aFont
);
1094 /* -----------------------------29.08.2002 13:47------------------------------
1096 ---------------------------------------------------------------------------*/
1097 void SwSrcEditWindow::SetTextEncoding(rtl_TextEncoding eEncoding
)
1099 eSourceEncoding
= eEncoding
;