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 ((SwSrcEditWindow
*)GetParent())->GetSrcView()->GetViewFrame()->
399 GetBindings().Invalidate( SID_TABLE_CELL
);
403 /*--------------------------------------------------------------------
405 --------------------------------------------------------------------*/
408 void TextViewOutWin::MouseButtonDown( const MouseEvent
&rEvt
)
412 pTextView
->MouseButtonDown( rEvt
);
415 /*--------------------------------------------------------------------
417 --------------------------------------------------------------------*/
420 void TextViewOutWin::Command( const CommandEvent
& rCEvt
)
422 switch(rCEvt
.GetCommand())
424 case COMMAND_CONTEXTMENU
:
425 ((SwSrcEditWindow
*)GetParent())->GetSrcView()->GetViewFrame()->
426 GetDispatcher()->ExecutePopup();
429 case COMMAND_STARTAUTOSCROLL
:
430 case COMMAND_AUTOSCROLL
:
432 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
433 if( !pWData
|| COMMAND_WHEEL_ZOOM
!= pWData
->GetMode() )
435 ((SwSrcEditWindow
*)GetParent())->HandleWheelCommand( rCEvt
);
442 pTextView
->Command( rCEvt
);
444 Window::Command(rCEvt
);
449 /*--------------------------------------------------------------------
451 --------------------------------------------------------------------*/
454 void TextViewOutWin::KeyInput( const KeyEvent
& rKEvt
)
457 SwSrcEditWindow
* pSrcEditWin
= (SwSrcEditWindow
*)GetParent();
458 BOOL bChange
= !pSrcEditWin
->IsReadonly() || !TextEngine::DoesKeyChangeText( rKEvt
);
460 bDone
= pTextView
->KeyInput( rKEvt
);
464 if ( !SfxViewShell::Current()->KeyInput( rKEvt
) )
465 Window::KeyInput( rKEvt
);
469 SfxBindings
& rBindings
= ((SwSrcEditWindow
*)GetParent())->GetSrcView()->GetViewFrame()->GetBindings();
470 rBindings
.Invalidate( SID_TABLE_CELL
);
471 if ( rKEvt
.GetKeyCode().GetGroup() == KEYGROUP_CURSOR
)
472 rBindings
.Update( SID_BASICIDE_STAT_POS
);
473 if (pSrcEditWin
->GetTextEngine()->IsModified() )
475 rBindings
.Invalidate( SID_SAVEDOC
);
476 rBindings
.Invalidate( SID_DOC_MODIFIED
);
478 if( rKEvt
.GetKeyCode().GetCode() == KEY_INSERT
)
479 rBindings
.Invalidate( SID_ATTR_INSERT
);
481 SwDocShell
* pDocShell
= pSrcEditWin
->GetSrcView()->GetDocShell();
482 if(pSrcEditWin
->GetTextEngine()->IsModified())
484 pDocShell
->SetModified();
488 /*--------------------------------------------------------------------
490 --------------------------------------------------------------------*/
493 void TextViewOutWin::Paint( const Rectangle
& rRect
)
495 pTextView
->Paint( rRect
);
498 /*--------------------------------------------------------------------
500 --------------------------------------------------------------------*/
503 void SwSrcEditWindow::CreateTextEngine()
505 const Color
&rCol
= GetSettings().GetStyleSettings().GetWindowColor();
506 pOutWin
= new TextViewOutWin(this, 0);
507 pOutWin
->SetBackground(Wallpaper(rCol
));
508 pOutWin
->SetPointer(Pointer(POINTER_TEXT
));
512 pHScrollbar
= new ScrollBar(this, WB_3DLOOK
|WB_HSCROLL
|WB_DRAG
);
513 pHScrollbar
->EnableRTL( false ); // #107300# --- RTL --- no mirroring for scrollbars
514 pHScrollbar
->SetScrollHdl(LINK(this, SwSrcEditWindow
, ScrollHdl
));
517 pVScrollbar
= new ScrollBar(this, WB_3DLOOK
|WB_VSCROLL
|WB_DRAG
);
518 pVScrollbar
->EnableRTL( false ); // #107300# --- RTL --- no mirroring for scrollbars
519 pVScrollbar
->SetScrollHdl(LINK(this, SwSrcEditWindow
, ScrollHdl
));
520 pHScrollbar
->EnableDrag();
523 pTextEngine
= new ExtTextEngine
;
524 pTextView
= new ExtTextView( pTextEngine
, pOutWin
);
525 pTextView
->SetAutoIndentMode(TRUE
);
526 pOutWin
->SetTextView(pTextView
);
528 pTextEngine
->SetUpdateMode( FALSE
);
529 pTextEngine
->InsertView( pTextView
);
532 aFont
.SetTransparent( FALSE
);
533 aFont
.SetFillColor( rCol
);
534 SetPointFont( aFont
);
536 aFont
.SetFillColor( rCol
);
537 pOutWin
->SetFont( aFont
);
538 pTextEngine
->SetFont( aFont
);
540 aSyntaxIdleTimer
.SetTimeout( SYNTAX_HIGHLIGHT_TIMEOUT
);
541 aSyntaxIdleTimer
.SetTimeoutHdl( LINK( this, SwSrcEditWindow
, SyntaxTimerHdl
) );
543 pTextEngine
->EnableUndo( TRUE
);
544 pTextEngine
->SetUpdateMode( TRUE
);
546 pTextView
->ShowCursor( TRUE
, TRUE
);
548 StartListening( *pTextEngine
);
550 SfxBindings
& rBind
= GetSrcView()->GetViewFrame()->GetBindings();
551 rBind
.Invalidate( SID_TABLE_CELL
);
552 // rBind.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
555 /*--------------------------------------------------------------------
557 --------------------------------------------------------------------*/
559 /*--------------------------------------------------------------------
561 --------------------------------------------------------------------*/
564 void SwSrcEditWindow::SetScrollBarRanges()
566 // Extra-Methode, nicht InitScrollBars, da auch fuer TextEngine-Events.
568 pHScrollbar
->SetRange( Range( 0, nCurTextWidth
-1 ) );
569 pVScrollbar
->SetRange( Range(0, pTextEngine
->GetTextHeight()-1) );
572 /*--------------------------------------------------------------------
574 --------------------------------------------------------------------*/
577 void SwSrcEditWindow::InitScrollBars()
579 SetScrollBarRanges();
581 Size
aOutSz( pOutWin
->GetOutputSizePixel() );
582 pVScrollbar
->SetVisibleSize( aOutSz
.Height() );
583 pVScrollbar
->SetPageSize( aOutSz
.Height() * 8 / 10 );
584 pVScrollbar
->SetLineSize( pOutWin
->GetTextHeight() );
585 pVScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
586 pHScrollbar
->SetVisibleSize( aOutSz
.Width() );
587 pHScrollbar
->SetPageSize( aOutSz
.Width() * 8 / 10 );
588 pHScrollbar
->SetLineSize( pOutWin
->GetTextWidth( 'x' ) );
589 pHScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().X() );
593 /*--------------------------------------------------------------------
595 --------------------------------------------------------------------*/
598 IMPL_LINK(SwSrcEditWindow
, ScrollHdl
, ScrollBar
*, pScroll
)
600 if(pScroll
== pVScrollbar
)
602 long nDiff
= pTextView
->GetStartDocPos().Y() - pScroll
->GetThumbPos();
603 GetTextView()->Scroll( 0, nDiff
);
604 pTextView
->ShowCursor( FALSE
, TRUE
);
605 pScroll
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
609 long nDiff
= pTextView
->GetStartDocPos().X() - pScroll
->GetThumbPos();
610 GetTextView()->Scroll( nDiff
, 0 );
611 pTextView
->ShowCursor( FALSE
, TRUE
);
612 pScroll
->SetThumbPos( pTextView
->GetStartDocPos().X() );
614 GetSrcView()->GetViewFrame()->GetBindings().Invalidate( SID_TABLE_CELL
);
618 /*-----------------15.01.97 09.22-------------------
620 --------------------------------------------------*/
622 IMPL_LINK( SwSrcEditWindow
, SyntaxTimerHdl
, Timer
*, pTimer
)
624 Time aSyntaxCheckStart
;
625 DBG_ASSERT( pTextView
, "Noch keine View, aber Syntax-Highlight ?!" );
626 // pTextEngine->SetUpdateMode( FALSE );
628 bHighlighting
= TRUE
;
631 // zuerst wird der Bereich um dem Cursor bearbeitet
632 TextSelection aSel
= pTextView
->GetSelection();
633 USHORT nCur
= (USHORT
)aSel
.GetStart().GetPara();
638 if(aSyntaxLineTable
.Count())
639 for(USHORT i
= 0; i
< 80 && nCount
< 40; i
++, nCur
++)
641 void * p
= aSyntaxLineTable
.Get(nCur
);
644 DoSyntaxHighlight( nCur
);
645 aSyntaxLineTable
.Remove( nCur
);
647 if(!aSyntaxLineTable
.Count())
649 if((Time().GetTime() - aSyntaxCheckStart
.GetTime()) > MAX_HIGHLIGHTTIME
)
651 pTimer
->SetTimeout( 2 * SYNTAX_HIGHLIGHT_TIMEOUT
);
657 // wenn dann noch etwas frei ist, wird von Beginn an weitergearbeitet
658 void* p
= aSyntaxLineTable
.First();
659 while ( p
&& nCount
< MAX_SYNTAX_HIGHLIGHT
)
661 nLine
= (USHORT
)aSyntaxLineTable
.GetCurKey();
662 DoSyntaxHighlight( nLine
);
663 USHORT nCurKey
= (USHORT
)aSyntaxLineTable
.GetCurKey();
664 p
= aSyntaxLineTable
.Next();
665 aSyntaxLineTable
.Remove(nCurKey
);
667 if(Time().GetTime() - aSyntaxCheckStart
.GetTime() > MAX_HIGHLIGHTTIME
)
669 pTimer
->SetTimeout( 2 * SYNTAX_HIGHLIGHT_TIMEOUT
);
673 // os: #43050# hier wird ein TextView-Problem umpopelt:
674 // waehrend des Highlightings funktionierte das Scrolling nicht
675 /* MT: Shouldn't be a oproblem any more, using IdeFormatter in Insert/RemoveAttrib now.
677 TextView* pTmp = pTextEngine->GetActiveView();
678 pTextEngine->SetActiveView(0);
679 // pTextEngine->SetUpdateMode( TRUE );
680 pTextEngine->SetActiveView(pTmp);
681 pTextView->ShowCursor(FALSE, FALSE);
684 if(aSyntaxLineTable
.Count() && !pTimer
->IsActive())
686 // SyntaxTimerHdl wird gerufen, wenn Text-Aenderung
687 // => gute Gelegenheit, Textbreite zu ermitteln!
688 long nPrevTextWidth
= nCurTextWidth
;
689 nCurTextWidth
= pTextEngine
->CalcTextWidth() + 25; // kleine Toleranz
690 if ( nCurTextWidth
!= nPrevTextWidth
)
691 SetScrollBarRanges();
692 bHighlighting
= FALSE
;
696 /*-----------------15.01.97 10.01-------------------
698 --------------------------------------------------*/
700 void SwSrcEditWindow::DoSyntaxHighlight( USHORT nPara
)
702 // Durch das DelayedSyntaxHighlight kann es passieren,
703 // dass die Zeile nicht mehr existiert!
704 if ( nPara
< pTextEngine
->GetParagraphCount() )
706 BOOL bTempModified
= IsModified();
707 pTextEngine
->RemoveAttribs( nPara
, (BOOL
)TRUE
);
708 String
aSource( pTextEngine
->GetText( nPara
) );
709 pTextEngine
->SetUpdateMode( FALSE
);
710 ImpDoHighlight( aSource
, nPara
);
711 // os: #43050# hier wird ein TextView-Problem umpopelt:
712 // waehrend des Highlightings funktionierte das Scrolling nicht
713 TextView
* pTmp
= pTextEngine
->GetActiveView();
714 pTmp
->SetAutoScroll(FALSE
);
715 pTextEngine
->SetActiveView(0);
716 pTextEngine
->SetUpdateMode( TRUE
);
717 pTextEngine
->SetActiveView(pTmp
);
718 // Bug 72887 show the cursor
719 pTmp
->SetAutoScroll(TRUE
);
720 pTmp
->ShowCursor( FALSE
/*pTmp->IsAutoScroll()*/ );
727 /*-----------------15.01.97 09.49-------------------
729 --------------------------------------------------*/
731 void SwSrcEditWindow::DoDelayedSyntaxHighlight( USHORT nPara
)
733 if ( !bHighlighting
&& bDoSyntaxHighlight
)
735 aSyntaxLineTable
.Insert( nPara
, (void*)(USHORT
)1 );
736 aSyntaxIdleTimer
.Start();
740 /*-----------------15.01.97 11.32-------------------
742 --------------------------------------------------*/
744 void SwSrcEditWindow::ImpDoHighlight( const String
& rSource
, USHORT nLineOff
)
746 SwTextPortions aPortionList
;
747 lcl_Highlight(rSource
, aPortionList
);
749 USHORT nCount
= aPortionList
.Count();
753 SwTextPortion
& rLast
= aPortionList
[nCount
-1];
754 if ( rLast
.nStart
> rLast
.nEnd
) // Nur bis Bug von MD behoeben
757 aPortionList
.Remove( nCount
);
763 // Wenn haufig gleiche Farbe, dazwischen Blank ohne Farbe,
764 // ggf. zusammenfassen, oder zumindest das Blank,
765 // damit weniger Attribute
766 BOOL bOptimizeHighlight
= TRUE
; // war in der BasicIDE static
767 if ( bOptimizeHighlight
)
769 // Es muessen nur die Blanks und Tabs mit attributiert werden.
770 // Wenn zwei gleiche Attribute hintereinander eingestellt werden,
771 // optimiert das die TextEngine.
775 USHORT nLine
= aPortionList
[0].nLine
;
777 for ( USHORT i
= 0; i
< nCount
; i
++ )
779 SwTextPortion
& r
= aPortionList
[i
];
780 DBG_ASSERT( r
.nLine
== nLine
, "doch mehrere Zeilen ?" );
781 if ( r
.nStart
> r
.nEnd
) // Nur bis Bug von MD behoeben
784 if ( r
.nStart
> nLastEnd
)
786 // Kann ich mich drauf verlassen, dass alle ausser
787 // Blank und Tab gehighlightet wird ?!
791 if ( ( i
== (nCount
-1) ) && ( r
.nEnd
< rSource
.Len() ) )
792 r
.nEnd
= rSource
.Len();
796 for ( USHORT i
= 0; i
< aPortionList
.Count(); i
++ )
798 SwTextPortion
& r
= aPortionList
[i
];
799 if ( r
.nStart
> r
.nEnd
) // Nur bis Bug von MD behoeben
801 if(r
.eType
!= svtools::HTMLSGML
&&
802 r
.eType
!= svtools::HTMLCOMMENT
&&
803 r
.eType
!= svtools::HTMLKEYWORD
&&
804 r
.eType
!= svtools::HTMLUNKNOWN
)
805 r
.eType
= svtools::HTMLUNKNOWN
;
806 Color
aColor((ColorData
)SW_MOD()->GetColorConfig().GetColorValue((svtools::ColorConfigEntry
)r
.eType
).nColor
);
807 USHORT nLine
= nLineOff
+r
.nLine
; //
808 pTextEngine
->SetAttrib( TextAttribFontColor( aColor
), nLine
, r
.nStart
, r
.nEnd
+1, TRUE
);
812 /*-----------------30.06.97 09:12-------------------
814 --------------------------------------------------*/
816 void SwSrcEditWindow::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
818 if ( rHint
.ISA( TextHint
) )
820 const TextHint
& rTextHint
= (const TextHint
&)rHint
;
821 if( rTextHint
.GetId() == TEXT_HINT_VIEWSCROLLED
)
823 pHScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().X() );
824 pVScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
826 else if( rTextHint
.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED
)
828 if ( (long)pTextEngine
->GetTextHeight() < pOutWin
->GetOutputSizePixel().Height() )
829 pTextView
->Scroll( 0, pTextView
->GetStartDocPos().Y() );
830 pVScrollbar
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
831 SetScrollBarRanges();
833 else if( ( rTextHint
.GetId() == TEXT_HINT_PARAINSERTED
) ||
834 ( rTextHint
.GetId() == TEXT_HINT_PARACONTENTCHANGED
) )
836 DoDelayedSyntaxHighlight( (USHORT
)rTextHint
.GetValue() );
839 else if(&rBC
== pSourceViewConfig
)
843 /*-----------------30.06.97 13:22-------------------
845 --------------------------------------------------*/
847 void SwSrcEditWindow::Invalidate(USHORT
)
849 pOutWin
->Invalidate();
850 Window::Invalidate();
854 void SwSrcEditWindow::Command( const CommandEvent
& rCEvt
)
856 switch(rCEvt
.GetCommand())
859 case COMMAND_STARTAUTOSCROLL
:
860 case COMMAND_AUTOSCROLL
:
862 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
863 if( !pWData
|| COMMAND_WHEEL_ZOOM
!= pWData
->GetMode() )
864 HandleScrollCommand( rCEvt
, pHScrollbar
, pVScrollbar
);
868 Window::Command(rCEvt
);
872 void SwSrcEditWindow::HandleWheelCommand( const CommandEvent
& rCEvt
)
874 pTextView
->Command(rCEvt
);
875 HandleScrollCommand( rCEvt
, pHScrollbar
, pVScrollbar
);
878 void SwSrcEditWindow::GetFocus()
880 pOutWin
->GrabFocus();
883 /*void SwSrcEditWindow::LoseFocus()
886 // pOutWin->LoseFocus();
887 // rView.LostFocus();
889 /* -----------------------------29.08.2002 13:21------------------------------
891 ---------------------------------------------------------------------------*/
892 BOOL
lcl_GetLanguagesForEncoding(rtl_TextEncoding eEnc
, LanguageType aLanguages
[])
896 case RTL_TEXTENCODING_UTF7
:
897 case RTL_TEXTENCODING_UTF8
:
898 // don#t fill - all LANGUAGE_SYSTEM means unicode font has to be used
902 case RTL_TEXTENCODING_ISO_8859_3
:
903 case RTL_TEXTENCODING_ISO_8859_1
:
904 case RTL_TEXTENCODING_MS_1252
:
905 case RTL_TEXTENCODING_APPLE_ROMAN
:
906 case RTL_TEXTENCODING_IBM_850
:
907 case RTL_TEXTENCODING_ISO_8859_14
:
908 case RTL_TEXTENCODING_ISO_8859_15
:
909 //fill with western languages
910 aLanguages
[0] = LANGUAGE_GERMAN
;
911 aLanguages
[1] = LANGUAGE_FRENCH
;
912 aLanguages
[2] = LANGUAGE_ITALIAN
;
913 aLanguages
[3] = LANGUAGE_SPANISH
;
916 case RTL_TEXTENCODING_IBM_865
:
918 aLanguages
[0] = LANGUAGE_FINNISH
;
919 aLanguages
[1] = LANGUAGE_NORWEGIAN
;
920 aLanguages
[2] = LANGUAGE_SWEDISH
;
921 aLanguages
[3] = LANGUAGE_DANISH
;
924 case RTL_TEXTENCODING_ISO_8859_10
:
925 case RTL_TEXTENCODING_ISO_8859_13
:
926 case RTL_TEXTENCODING_ISO_8859_2
:
927 case RTL_TEXTENCODING_IBM_852
:
928 case RTL_TEXTENCODING_MS_1250
:
929 case RTL_TEXTENCODING_APPLE_CENTEURO
:
930 aLanguages
[0] = LANGUAGE_POLISH
;
931 aLanguages
[1] = LANGUAGE_CZECH
;
932 aLanguages
[2] = LANGUAGE_HUNGARIAN
;
933 aLanguages
[3] = LANGUAGE_SLOVAK
;
936 case RTL_TEXTENCODING_ISO_8859_4
:
937 case RTL_TEXTENCODING_IBM_775
:
938 case RTL_TEXTENCODING_MS_1257
:
939 aLanguages
[0] = LANGUAGE_LATVIAN
;
940 aLanguages
[1] = LANGUAGE_LITHUANIAN
;
941 aLanguages
[2] = LANGUAGE_ESTONIAN
;
944 case RTL_TEXTENCODING_IBM_863
: aLanguages
[0] = LANGUAGE_FRENCH_CANADIAN
; break;
945 case RTL_TEXTENCODING_APPLE_FARSI
: aLanguages
[0] = LANGUAGE_FARSI
; break;
946 case RTL_TEXTENCODING_APPLE_ROMANIAN
:aLanguages
[0] = LANGUAGE_ROMANIAN
; break;
948 case RTL_TEXTENCODING_IBM_861
:
949 case RTL_TEXTENCODING_APPLE_ICELAND
:
950 aLanguages
[0] = LANGUAGE_ICELANDIC
;
953 case RTL_TEXTENCODING_APPLE_CROATIAN
:aLanguages
[0] = LANGUAGE_CROATIAN
; break;
955 case RTL_TEXTENCODING_IBM_437
:
956 case RTL_TEXTENCODING_ASCII_US
: aLanguages
[0] = LANGUAGE_ENGLISH
; break;
958 case RTL_TEXTENCODING_IBM_862
:
959 case RTL_TEXTENCODING_MS_1255
:
960 case RTL_TEXTENCODING_APPLE_HEBREW
:
961 case RTL_TEXTENCODING_ISO_8859_8
:
962 aLanguages
[0] = LANGUAGE_HEBREW
;
965 case RTL_TEXTENCODING_IBM_857
:
966 case RTL_TEXTENCODING_MS_1254
:
967 case RTL_TEXTENCODING_APPLE_TURKISH
:
968 case RTL_TEXTENCODING_ISO_8859_9
:
969 aLanguages
[0] = LANGUAGE_TURKISH
;
972 case RTL_TEXTENCODING_IBM_860
:
973 aLanguages
[0] = LANGUAGE_PORTUGUESE
;
976 case RTL_TEXTENCODING_IBM_869
:
977 case RTL_TEXTENCODING_MS_1253
:
978 case RTL_TEXTENCODING_APPLE_GREEK
:
979 case RTL_TEXTENCODING_ISO_8859_7
:
980 case RTL_TEXTENCODING_IBM_737
:
981 aLanguages
[0] = LANGUAGE_GREEK
;
984 case RTL_TEXTENCODING_KOI8_R
:
985 case RTL_TEXTENCODING_ISO_8859_5
:
986 case RTL_TEXTENCODING_IBM_855
:
987 case RTL_TEXTENCODING_MS_1251
:
988 case RTL_TEXTENCODING_IBM_866
:
989 case RTL_TEXTENCODING_APPLE_CYRILLIC
:
990 aLanguages
[0] = LANGUAGE_RUSSIAN
;
993 case RTL_TEXTENCODING_APPLE_UKRAINIAN
:
994 case RTL_TEXTENCODING_KOI8_U
:
995 aLanguages
[0] = LANGUAGE_UKRAINIAN
;
998 case RTL_TEXTENCODING_IBM_864
:
999 case RTL_TEXTENCODING_MS_1256
:
1000 case RTL_TEXTENCODING_ISO_8859_6
:
1001 case RTL_TEXTENCODING_APPLE_ARABIC
:
1002 aLanguages
[0] = LANGUAGE_ARABIC_SAUDI_ARABIA
;
1005 case RTL_TEXTENCODING_APPLE_CHINTRAD
:
1006 case RTL_TEXTENCODING_MS_950
:
1007 case RTL_TEXTENCODING_GBT_12345
:
1008 case RTL_TEXTENCODING_BIG5
:
1009 case RTL_TEXTENCODING_EUC_TW
:
1010 case RTL_TEXTENCODING_BIG5_HKSCS
:
1011 aLanguages
[0] = LANGUAGE_CHINESE_TRADITIONAL
;
1014 case RTL_TEXTENCODING_EUC_JP
:
1015 case RTL_TEXTENCODING_ISO_2022_JP
:
1016 case RTL_TEXTENCODING_JIS_X_0201
:
1017 case RTL_TEXTENCODING_JIS_X_0208
:
1018 case RTL_TEXTENCODING_JIS_X_0212
:
1019 case RTL_TEXTENCODING_APPLE_JAPANESE
:
1020 case RTL_TEXTENCODING_MS_932
:
1021 case RTL_TEXTENCODING_SHIFT_JIS
:
1022 aLanguages
[0] = LANGUAGE_JAPANESE
;
1025 case RTL_TEXTENCODING_GB_2312
:
1026 case RTL_TEXTENCODING_MS_936
:
1027 case RTL_TEXTENCODING_GBK
:
1028 case RTL_TEXTENCODING_GB_18030
:
1029 case RTL_TEXTENCODING_APPLE_CHINSIMP
:
1030 case RTL_TEXTENCODING_EUC_CN
:
1031 case RTL_TEXTENCODING_ISO_2022_CN
:
1032 aLanguages
[0] = LANGUAGE_CHINESE_SIMPLIFIED
;
1035 case RTL_TEXTENCODING_APPLE_KOREAN
:
1036 case RTL_TEXTENCODING_MS_949
:
1037 case RTL_TEXTENCODING_EUC_KR
:
1038 case RTL_TEXTENCODING_ISO_2022_KR
:
1039 case RTL_TEXTENCODING_MS_1361
:
1040 aLanguages
[0] = LANGUAGE_KOREAN
;
1043 case RTL_TEXTENCODING_APPLE_THAI
:
1044 case RTL_TEXTENCODING_MS_874
:
1045 case RTL_TEXTENCODING_TIS_620
:
1046 aLanguages
[0] = LANGUAGE_THAI
;
1048 // case RTL_TEXTENCODING_SYMBOL :
1049 // case RTL_TEXTENCODING_DONTKNOW: :
1050 default: aLanguages
[0] = Application::GetSettings().GetUILanguage();
1052 return aLanguages
[0] != LANGUAGE_SYSTEM
;
1054 void SwSrcEditWindow::SetFont()
1056 String sFontName
= pSourceViewConfig
->GetFontName();
1057 if(!sFontName
.Len())
1059 LanguageType aLanguages
[5] =
1061 LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
, LANGUAGE_SYSTEM
1064 if(lcl_GetLanguagesForEncoding(eSourceEncoding
, aLanguages
))
1066 //TODO: check for multiple languages
1067 aFont
= OutputDevice::GetDefaultFont(DEFAULTFONT_FIXED
, aLanguages
[0], 0, this);
1070 aFont
= OutputDevice::GetDefaultFont(DEFAULTFONT_SANS_UNICODE
,
1071 Application::GetSettings().GetLanguage(), 0, this);
1072 sFontName
= aFont
.GetName();
1074 const SvxFontListItem
* pFontListItem
=
1075 (const SvxFontListItem
* )pSrcView
->GetDocShell()->GetItem( SID_ATTR_CHAR_FONTLIST
);
1076 const FontList
* pList
= pFontListItem
->GetFontList();
1077 FontInfo aInfo
= pList
->Get(sFontName
,WEIGHT_NORMAL
, ITALIC_NONE
);
1079 const Font
& rFont
= GetTextEngine()->GetFont();
1081 Size
aSize(rFont
.GetSize());
1082 //font height is stored in point and set in twip
1083 aSize
.Height() = pSourceViewConfig
->GetFontHeight() * 20;
1084 aFont
.SetSize(pOutWin
->LogicToPixel(aSize
, MAP_TWIP
));
1085 GetTextEngine()->SetFont( aFont
);
1086 pOutWin
->SetFont(aFont
);
1088 /* -----------------------------29.08.2002 13:47------------------------------
1090 ---------------------------------------------------------------------------*/
1091 void SwSrcEditWindow::SetTextEncoding(rtl_TextEncoding eEncoding
)
1093 eSourceEncoding
= eEncoding
;