Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <memory>
30 : :
31 : : #include <tools/rc.h>
32 : :
33 : : #include <vcl/decoview.hxx>
34 : : #include <vcl/svapp.hxx>
35 : :
36 : : #include <vcl/vclmedit.hxx>
37 : : #include <vcl/xtextedt.hxx>
38 : : #include <svl/brdcst.hxx>
39 : : #include <svl/undo.hxx>
40 : : #include <svl/lstner.hxx>
41 : : #include <svl/smplhint.hxx>
42 : :
43 : : #include <svids.hrc>
44 : : #include <vcl/scrbar.hxx>
45 : :
46 : :
47 : : class TextWindow : public Window
48 : : {
49 : : private:
50 : : ExtTextEngine* mpExtTextEngine;
51 : : ExtTextView* mpExtTextView;
52 : :
53 : : sal_Bool mbInMBDown;
54 : : sal_Bool mbFocusSelectionHide;
55 : : sal_Bool mbIgnoreTab;
56 : : sal_Bool mbActivePopup;
57 : : sal_Bool mbSelectOnTab;
58 : : sal_Bool mbTextSelectable;
59 : :
60 : : public:
61 : : TextWindow( Window* pParent );
62 : : ~TextWindow();
63 : :
64 : 2106 : ExtTextEngine* GetTextEngine() const { return mpExtTextEngine; }
65 : 986 : ExtTextView* GetTextView() const { return mpExtTextView; }
66 : :
67 : : virtual void MouseMove( const MouseEvent& rMEvt );
68 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
69 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
70 : : virtual void KeyInput( const KeyEvent& rKEvent );
71 : :
72 : : virtual void Command( const CommandEvent& rCEvt );
73 : :
74 : : virtual void Paint( const Rectangle& rRect );
75 : : virtual void Resize();
76 : :
77 : : virtual void GetFocus();
78 : : virtual void LoseFocus();
79 : :
80 : : sal_Bool IsAutoFocusHide() const { return mbFocusSelectionHide; }
81 : 298 : void SetAutoFocusHide( sal_Bool bAutoHide ) { mbFocusSelectionHide = bAutoHide; }
82 : :
83 : : sal_Bool IsIgnoreTab() const { return mbIgnoreTab; }
84 : 272 : void SetIgnoreTab( sal_Bool bIgnore ) { mbIgnoreTab = bIgnore; }
85 : :
86 : 22 : void DisableSelectionOnFocus() { mbSelectOnTab = sal_False; }
87 : :
88 : 0 : void SetTextSelectable( sal_Bool bTextSelectable ) { mbTextSelectable = bTextSelectable; }
89 : : };
90 : :
91 : :
92 : : class ImpSvMEdit : public SfxListener
93 : : {
94 : : private:
95 : : VCLMultiLineEdit* pSvVCLMultiLineEdit;
96 : :
97 : : TextWindow* mpTextWindow;
98 : : ScrollBar* mpHScrollBar;
99 : : ScrollBar* mpVScrollBar;
100 : : ScrollBarBox* mpScrollBox;
101 : :
102 : : Point maTextWindowOffset;
103 : : xub_StrLen mnTextWidth;
104 : : mutable Selection maSelection;
105 : :
106 : : protected:
107 : : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
108 : : void ImpUpdateSrollBarVis( WinBits nWinStyle );
109 : : void ImpInitScrollBars();
110 : : void ImpSetScrollBarRanges();
111 : : void ImpSetHScrollBarThumbPos();
112 : : DECL_LINK( ScrollHdl, ScrollBar* );
113 : :
114 : : public:
115 : : ImpSvMEdit( VCLMultiLineEdit* pSvVCLMultiLineEdit, WinBits nWinStyle );
116 : : ~ImpSvMEdit();
117 : :
118 : : void SetModified( sal_Bool bMod );
119 : : sal_Bool IsModified() const;
120 : :
121 : : void SetReadOnly( sal_Bool bRdOnly );
122 : : sal_Bool IsReadOnly() const;
123 : :
124 : : void SetMaxTextLen( xub_StrLen nLen );
125 : : xub_StrLen GetMaxTextLen() const;
126 : :
127 : : sal_Bool IsInsertMode() const;
128 : :
129 : : void InsertText( const String& rStr );
130 : : String GetSelected() const;
131 : : String GetSelected( LineEnd aSeparator ) const;
132 : :
133 : : void SetSelection( const Selection& rSelection );
134 : : const Selection& GetSelection() const;
135 : :
136 : : void Cut();
137 : : void Copy();
138 : : void Paste();
139 : :
140 : : void SetText( const String& rStr );
141 : : String GetText() const;
142 : : String GetText( LineEnd aSeparator ) const;
143 : : String GetTextLines( LineEnd aSeparator ) const;
144 : :
145 : : void Resize();
146 : : void GetFocus();
147 : :
148 : : sal_Bool HandleCommand( const CommandEvent& rCEvt );
149 : :
150 : : void Enable( sal_Bool bEnable );
151 : :
152 : : Size CalcMinimumSize() const;
153 : : Size CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const;
154 : : void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const;
155 : :
156 : : void SetAlign( WinBits nWinStyle );
157 : :
158 : : void InitFromStyle( WinBits nWinStyle );
159 : :
160 : 1810 : TextWindow* GetTextWindow() { return mpTextWindow; }
161 : 0 : ScrollBar* GetHScrollBar() { return mpHScrollBar; }
162 : 0 : ScrollBar* GetVScrollBar() { return mpVScrollBar; }
163 : : };
164 : :
165 : 90 : ImpSvMEdit::ImpSvMEdit( VCLMultiLineEdit* pEdt, WinBits nWinStyle )
166 : : :mpHScrollBar(NULL)
167 : : ,mpVScrollBar(NULL)
168 : 90 : ,mpScrollBox(NULL)
169 : : {
170 : 90 : pSvVCLMultiLineEdit = pEdt;
171 : 90 : mnTextWidth = 0;
172 [ + - ][ + - ]: 90 : mpTextWindow = new TextWindow( pEdt );
173 [ + - ]: 90 : mpTextWindow->Show();
174 [ + - ]: 90 : InitFromStyle( nWinStyle );
175 [ + - ]: 90 : StartListening( *mpTextWindow->GetTextEngine() );
176 : 90 : }
177 : :
178 : 272 : void ImpSvMEdit::ImpUpdateSrollBarVis( WinBits nWinStyle )
179 : : {
180 : 272 : const sal_Bool bHaveVScroll = (NULL != mpVScrollBar);
181 : 272 : const sal_Bool bHaveHScroll = (NULL != mpHScrollBar);
182 : 272 : const sal_Bool bHaveScrollBox = (NULL != mpScrollBox);
183 : :
184 : 272 : sal_Bool bNeedVScroll = ( nWinStyle & WB_VSCROLL ) == WB_VSCROLL;
185 : 272 : const sal_Bool bNeedHScroll = ( nWinStyle & WB_HSCROLL ) == WB_HSCROLL;
186 : :
187 : 272 : const sal_Bool bAutoVScroll = ( nWinStyle & WB_AUTOVSCROLL ) == WB_AUTOVSCROLL;
188 [ + + ][ - + ]: 272 : if ( !bNeedVScroll && bAutoVScroll )
189 : : {
190 : 0 : TextEngine& rEngine( *mpTextWindow->GetTextEngine() );
191 : 0 : sal_uLong nOverallTextHeight(0);
192 [ # # ]: 0 : for ( sal_uLong i=0; i<rEngine.GetParagraphCount(); ++i )
193 : 0 : nOverallTextHeight += rEngine.GetTextHeight( i );
194 [ # # ]: 0 : if ( nOverallTextHeight > (sal_uLong)mpTextWindow->GetOutputSizePixel().Height() )
195 : 0 : bNeedVScroll = true;
196 : : }
197 : :
198 [ + + ][ + + ]: 272 : const sal_Bool bNeedScrollBox = bNeedVScroll && bNeedHScroll;
199 : :
200 : 272 : sal_Bool bScrollbarsChanged = false;
201 [ + + ]: 272 : if ( bHaveVScroll != bNeedVScroll )
202 : : {
203 [ - + ]: 14 : delete mpVScrollBar;
204 [ + - ][ + - ]: 14 : mpVScrollBar = bNeedVScroll ? new ScrollBar( pSvVCLMultiLineEdit, WB_VSCROLL|WB_DRAG ) : NULL;
205 : :
206 [ + - ]: 14 : if ( bNeedVScroll )
207 : : {
208 : 14 : mpVScrollBar->Show();
209 : 14 : mpVScrollBar->SetScrollHdl( LINK( this, ImpSvMEdit, ScrollHdl ) );
210 : : }
211 : :
212 : 14 : bScrollbarsChanged = sal_True;
213 : : }
214 : :
215 [ + + ]: 272 : if ( bHaveHScroll != bNeedHScroll )
216 : : {
217 [ - + ]: 18 : delete mpHScrollBar;
218 [ + - ][ + - ]: 18 : mpHScrollBar = bNeedHScroll ? new ScrollBar( pSvVCLMultiLineEdit, WB_HSCROLL|WB_DRAG ) : NULL;
219 : :
220 [ + - ]: 18 : if ( bNeedHScroll )
221 : : {
222 : 18 : mpHScrollBar->Show();
223 : 18 : mpHScrollBar->SetScrollHdl( LINK( this, ImpSvMEdit, ScrollHdl ) );
224 : : }
225 : :
226 : 18 : bScrollbarsChanged = sal_True;
227 : : }
228 : :
229 [ + + ]: 272 : if ( bHaveScrollBox != bNeedScrollBox )
230 : : {
231 [ - + ]: 10 : delete mpScrollBox;
232 [ + - ][ + - ]: 10 : mpScrollBox = bNeedScrollBox ? new ScrollBarBox( pSvVCLMultiLineEdit, WB_SIZEABLE ) : NULL;
233 : :
234 [ + - ]: 10 : if ( bNeedScrollBox )
235 : 10 : mpScrollBox->Show();
236 : : }
237 : :
238 [ + + ]: 272 : if ( bScrollbarsChanged )
239 : : {
240 : 22 : ImpInitScrollBars();
241 : 22 : Resize();
242 : : }
243 : 272 : }
244 : :
245 : 272 : void ImpSvMEdit::InitFromStyle( WinBits nWinStyle )
246 : : {
247 : 272 : ImpUpdateSrollBarVis( nWinStyle );
248 : 272 : SetAlign( nWinStyle );
249 : :
250 [ + + ]: 272 : if ( nWinStyle & WB_NOHIDESELECTION )
251 : 88 : mpTextWindow->SetAutoFocusHide( sal_False );
252 : : else
253 : 184 : mpTextWindow->SetAutoFocusHide( sal_True );
254 : :
255 [ + + ]: 272 : if ( nWinStyle & WB_READONLY )
256 : 62 : mpTextWindow->GetTextView()->SetReadOnly( sal_True );
257 : : else
258 : 210 : mpTextWindow->GetTextView()->SetReadOnly( sal_False );
259 : :
260 [ + + ]: 272 : if ( nWinStyle & WB_IGNORETAB )
261 : : {
262 : 136 : mpTextWindow->SetIgnoreTab( sal_True );
263 : : }
264 : : else
265 : : {
266 : 136 : mpTextWindow->SetIgnoreTab( sal_False );
267 : : // #103667# VCLMultiLineEdit has the flag, but focusable window also needs this flag
268 : 136 : WinBits nStyle = mpTextWindow->GetStyle();
269 : 136 : nStyle |= WINDOW_DLGCTRL_MOD1TAB;
270 : 136 : mpTextWindow->SetStyle( nStyle );
271 : : }
272 : 272 : }
273 : :
274 : 90 : ImpSvMEdit::~ImpSvMEdit()
275 : : {
276 [ + - ]: 90 : EndListening( *mpTextWindow->GetTextEngine() );
277 [ + - ][ + - ]: 90 : delete mpTextWindow;
278 [ + + ][ + - ]: 90 : delete mpHScrollBar;
279 [ + + ][ + - ]: 90 : delete mpVScrollBar;
280 [ + + ][ + - ]: 90 : delete mpScrollBox;
281 [ - + ]: 180 : }
282 : :
283 : 370 : void ImpSvMEdit::ImpSetScrollBarRanges()
284 : : {
285 [ + + ]: 370 : if ( mpVScrollBar )
286 : : {
287 : 144 : sal_uLong nTextHeight = mpTextWindow->GetTextEngine()->GetTextHeight();
288 [ + - ]: 144 : mpVScrollBar->SetRange( Range( 0, (long)nTextHeight-1 ) );
289 : : }
290 [ + + ]: 370 : if ( mpHScrollBar )
291 : : {
292 : : // sal_uLong nTextWidth = mpTextWindow->GetTextEngine()->CalcTextWidth();
293 : : // Es gibt kein Notify bei Breiten-Aenderung...
294 : : // sal_uLong nW = Max( (sal_uLong)mpTextWindow->GetOutputSizePixel().Width()*5, (sal_uLong)nTextWidth );
295 : : // mpHScrollBar->SetRange( Range( 0, (long)nW ) );
296 [ + - ]: 190 : mpHScrollBar->SetRange( Range( 0, (long)mnTextWidth-1 ) );
297 : : }
298 : 370 : }
299 : :
300 : 200 : void ImpSvMEdit::ImpInitScrollBars()
301 : : {
302 : : static const sal_Unicode sampleChar = { 'x' };
303 [ + + ][ + + ]: 200 : if ( mpHScrollBar || mpVScrollBar )
304 : : {
305 [ + - ]: 160 : ImpSetScrollBarRanges();
306 : 160 : Size aCharBox;
307 [ + - ][ + - ]: 160 : aCharBox.Width() = mpTextWindow->GetTextWidth( rtl::OUString(sampleChar) );
[ + - ]
308 [ + - ]: 160 : aCharBox.Height() = mpTextWindow->GetTextHeight();
309 : 160 : Size aOutSz = mpTextWindow->GetOutputSizePixel();
310 [ + + ]: 160 : if ( mpHScrollBar )
311 : : {
312 [ + - ]: 132 : mpHScrollBar->SetVisibleSize( aOutSz.Width() );
313 : 132 : mpHScrollBar->SetPageSize( aOutSz.Width() * 8 / 10 );
314 : 132 : mpHScrollBar->SetLineSize( aCharBox.Width()*10 );
315 [ + - ]: 132 : ImpSetHScrollBarThumbPos();
316 : : }
317 [ + + ]: 160 : if ( mpVScrollBar )
318 : : {
319 [ + - ]: 98 : mpVScrollBar->SetVisibleSize( aOutSz.Height() );
320 : 98 : mpVScrollBar->SetPageSize( aOutSz.Height() * 8 / 10 );
321 : 98 : mpVScrollBar->SetLineSize( aCharBox.Height() );
322 [ + - ][ + - ]: 160 : mpVScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().Y() );
323 : : }
324 : : }
325 : 200 : }
326 : :
327 : 174 : void ImpSvMEdit::ImpSetHScrollBarThumbPos()
328 : : {
329 : 174 : long nX = mpTextWindow->GetTextView()->GetStartDocPos().X();
330 [ + - ]: 174 : if ( !mpTextWindow->GetTextEngine()->IsRightToLeft() )
331 : 174 : mpHScrollBar->SetThumbPos( nX );
332 : : else
333 : 0 : mpHScrollBar->SetThumbPos( mnTextWidth - mpHScrollBar->GetVisibleSize() - nX );
334 : :
335 : 174 : }
336 : :
337 : 0 : IMPL_LINK( ImpSvMEdit, ScrollHdl, ScrollBar*, pCurScrollBar )
338 : : {
339 : 0 : long nDiffX = 0, nDiffY = 0;
340 : :
341 [ # # ]: 0 : if ( pCurScrollBar == mpVScrollBar )
342 : 0 : nDiffY = mpTextWindow->GetTextView()->GetStartDocPos().Y() - pCurScrollBar->GetThumbPos();
343 [ # # ]: 0 : else if ( pCurScrollBar == mpHScrollBar )
344 : 0 : nDiffX = mpTextWindow->GetTextView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
345 : :
346 : 0 : mpTextWindow->GetTextView()->Scroll( nDiffX, nDiffY );
347 : : // mpTextWindow->GetTextView()->ShowCursor( sal_False, sal_True );
348 : :
349 : 0 : return 0;
350 : : }
351 : :
352 : :
353 : : // void ImpSvMEdit::ImpModified()
354 : : // {
355 : : // // Wann wird das gerufen ?????????????????????
356 : : // pSvVCLMultiLineEdit->Modify();
357 : : // }
358 : :
359 : 272 : void ImpSvMEdit::SetAlign( WinBits nWinStyle )
360 : : {
361 : 272 : sal_Bool bRTL = Application::GetSettings().GetLayoutRTL();
362 : 272 : mpTextWindow->GetTextEngine()->SetRightToLeft( bRTL );
363 : :
364 [ + + ]: 272 : if ( nWinStyle & WB_CENTER )
365 : 124 : mpTextWindow->GetTextEngine()->SetTextAlign( TXTALIGN_CENTER );
366 [ - + ]: 148 : else if ( nWinStyle & WB_RIGHT )
367 [ # # ]: 0 : mpTextWindow->GetTextEngine()->SetTextAlign( !bRTL ? TXTALIGN_RIGHT : TXTALIGN_LEFT );
368 [ + - ]: 148 : else if ( nWinStyle & WB_LEFT )
369 [ + - ]: 148 : mpTextWindow->GetTextEngine()->SetTextAlign( !bRTL ? TXTALIGN_LEFT : TXTALIGN_RIGHT );
370 : 272 : }
371 : :
372 : 32 : void ImpSvMEdit::SetModified( sal_Bool bMod )
373 : : {
374 : 32 : mpTextWindow->GetTextEngine()->SetModified( bMod );
375 : 32 : }
376 : :
377 : 0 : sal_Bool ImpSvMEdit::IsModified() const
378 : : {
379 : 0 : return mpTextWindow->GetTextEngine()->IsModified();
380 : : }
381 : :
382 : 82 : void ImpSvMEdit::SetReadOnly( sal_Bool bRdOnly )
383 : : {
384 : 82 : mpTextWindow->GetTextView()->SetReadOnly( bRdOnly );
385 : : // Farbe anpassen ???????????????????????????
386 : 82 : }
387 : :
388 : 22 : sal_Bool ImpSvMEdit::IsReadOnly() const
389 : : {
390 : 22 : return mpTextWindow->GetTextView()->IsReadOnly();
391 : : }
392 : :
393 : 94 : void ImpSvMEdit::SetMaxTextLen( xub_StrLen nLen )
394 : : {
395 : 94 : mpTextWindow->GetTextEngine()->SetMaxTextLen( nLen );
396 : 94 : }
397 : :
398 : 0 : xub_StrLen ImpSvMEdit::GetMaxTextLen() const
399 : : {
400 : : return sal::static_int_cast< xub_StrLen >(
401 : 0 : mpTextWindow->GetTextEngine()->GetMaxTextLen());
402 : : }
403 : :
404 : 0 : void ImpSvMEdit::InsertText( const String& rStr )
405 : : {
406 : 0 : mpTextWindow->GetTextView()->InsertText( rStr );
407 : 0 : }
408 : :
409 : 0 : String ImpSvMEdit::GetSelected() const
410 : : {
411 : 0 : return mpTextWindow->GetTextView()->GetSelected();
412 : : }
413 : :
414 : 0 : String ImpSvMEdit::GetSelected( LineEnd aSeparator ) const
415 : : {
416 : 0 : return mpTextWindow->GetTextView()->GetSelected( aSeparator );
417 : : }
418 : :
419 : 178 : void ImpSvMEdit::Resize()
420 : : {
421 : 178 : size_t nIteration = 1;
422 [ + - ]: 220 : do
423 : : {
424 [ + - ]: 220 : WinBits nWinStyle( pSvVCLMultiLineEdit->GetStyle() );
425 [ - + ]: 220 : if ( ( nWinStyle & WB_AUTOVSCROLL ) == WB_AUTOVSCROLL )
426 [ # # ]: 0 : ImpUpdateSrollBarVis( nWinStyle );
427 : :
428 : 220 : Size aSz = pSvVCLMultiLineEdit->GetOutputSizePixel();
429 : 220 : Size aEditSize = aSz;
430 : 220 : long nSBWidth = pSvVCLMultiLineEdit->GetSettings().GetStyleSettings().GetScrollBarSize();
431 [ + - ]: 220 : nSBWidth = pSvVCLMultiLineEdit->CalcZoom( nSBWidth );
432 : :
433 [ + + ]: 220 : if ( mpHScrollBar )
434 : 144 : aSz.Height() -= nSBWidth+1;
435 [ + + ]: 220 : if ( mpVScrollBar )
436 : 106 : aSz.Width() -= nSBWidth+1;
437 : :
438 [ + + ]: 220 : if ( !mpHScrollBar )
439 [ + - ]: 76 : mpTextWindow->GetTextEngine()->SetMaxTextWidth( aSz.Width() );
440 : : else
441 [ + - ]: 144 : mpHScrollBar->SetPosSizePixel( 0, aEditSize.Height()-nSBWidth, aSz.Width(), nSBWidth );
442 : :
443 : 220 : Point aTextWindowPos( maTextWindowOffset );
444 [ + + ]: 220 : if ( mpVScrollBar )
445 : : {
446 [ + - ][ + - ]: 106 : if( Application::GetSettings().GetLayoutRTL() )
[ - + ]
447 : : {
448 [ # # ]: 0 : mpVScrollBar->SetPosSizePixel( 0, 0, nSBWidth, aSz.Height() );
449 : 0 : aTextWindowPos.X() += nSBWidth;
450 : : }
451 : : else
452 [ + - ]: 106 : mpVScrollBar->SetPosSizePixel( aEditSize.Width()-nSBWidth, 0, nSBWidth, aSz.Height() );
453 : : }
454 : :
455 [ + + ]: 220 : if ( mpScrollBox )
456 [ + - ]: 76 : mpScrollBox->SetPosSizePixel( aSz.Width(), aSz.Height(), nSBWidth, nSBWidth );
457 : :
458 : 220 : Size aTextWindowSize( aSz );
459 : 220 : aTextWindowSize.Width() -= maTextWindowOffset.X();
460 : 220 : aTextWindowSize.Height() -= maTextWindowOffset.Y();
461 [ + + ]: 220 : if ( aTextWindowSize.Width() < 0 )
462 : 14 : aTextWindowSize.Width() = 0;
463 [ + + ]: 220 : if ( aTextWindowSize.Height() < 0 )
464 : 18 : aTextWindowSize.Height() = 0;
465 : :
466 [ + - ]: 220 : Size aOldTextWindowSize( mpTextWindow->GetSizePixel() );
467 [ + - ]: 220 : mpTextWindow->SetPosSizePixel( aTextWindowPos, aTextWindowSize );
468 [ + + ]: 220 : if ( aOldTextWindowSize == aTextWindowSize )
469 : : break;
470 : :
471 : : // Changing the text window size might effectively have changed the need for
472 : : // scrollbars, so do another iteration.
473 : 42 : ++nIteration;
474 : : OSL_ENSURE( nIteration < 3, "ImpSvMEdit::Resize: isn't this expected to terminate with the second iteration?" );
475 : :
476 : : } while ( nIteration <= 3 ); // artificial break after four iterations
477 : :
478 : 178 : ImpInitScrollBars();
479 : 178 : }
480 : :
481 : 0 : void ImpSvMEdit::GetFocus()
482 : : {
483 : 0 : mpTextWindow->GrabFocus();
484 : 0 : }
485 : :
486 : 0 : void ImpSvMEdit::Cut()
487 : : {
488 [ # # ]: 0 : if ( !mpTextWindow->GetTextView()->IsReadOnly() )
489 : 0 : mpTextWindow->GetTextView()->Cut();
490 : 0 : }
491 : :
492 : 0 : void ImpSvMEdit::Copy()
493 : : {
494 : 0 : mpTextWindow->GetTextView()->Copy();
495 : 0 : }
496 : :
497 : 0 : void ImpSvMEdit::Paste()
498 : : {
499 [ # # ]: 0 : if ( !mpTextWindow->GetTextView()->IsReadOnly() )
500 : 0 : mpTextWindow->GetTextView()->Paste();
501 : 0 : }
502 : :
503 : 128 : void ImpSvMEdit::SetText( const String& rStr )
504 : : {
505 : 128 : sal_Bool bWasModified = mpTextWindow->GetTextEngine()->IsModified();
506 : 128 : mpTextWindow->GetTextEngine()->SetText( rStr );
507 [ + + ]: 128 : if ( !bWasModified )
508 : 118 : mpTextWindow->GetTextEngine()->SetModified( sal_False );
509 : :
510 [ + - ]: 128 : mpTextWindow->GetTextView()->SetSelection( TextSelection() );
511 : :
512 : 128 : WinBits nWinStyle( pSvVCLMultiLineEdit->GetStyle() );
513 [ - + ]: 128 : if ( ( nWinStyle & WB_AUTOVSCROLL ) == WB_AUTOVSCROLL )
514 : 0 : ImpUpdateSrollBarVis( nWinStyle );
515 : 128 : }
516 : :
517 : 0 : String ImpSvMEdit::GetText() const
518 : : {
519 : 0 : return mpTextWindow->GetTextEngine()->GetText();
520 : : }
521 : :
522 : 0 : String ImpSvMEdit::GetText( LineEnd aSeparator ) const
523 : : {
524 : 0 : return mpTextWindow->GetTextEngine()->GetText( aSeparator );
525 : : }
526 : :
527 : 0 : String ImpSvMEdit::GetTextLines( LineEnd aSeparator ) const
528 : : {
529 : 0 : return mpTextWindow->GetTextEngine()->GetTextLines( aSeparator );
530 : : }
531 : :
532 : 1482 : void ImpSvMEdit::Notify( SfxBroadcaster&, const SfxHint& rHint )
533 : : {
534 [ + - ]: 1482 : if ( rHint.ISA( TextHint ) )
535 : : {
536 : 1482 : const TextHint& rTextHint = (const TextHint&)rHint;
537 [ - + ]: 1482 : if( rTextHint.GetId() == TEXT_HINT_VIEWSCROLLED )
538 : : {
539 [ # # ]: 0 : if ( mpHScrollBar )
540 : 0 : ImpSetHScrollBarThumbPos();
541 [ # # ]: 0 : if ( mpVScrollBar )
542 : 0 : mpVScrollBar->SetThumbPos( mpTextWindow->GetTextView()->GetStartDocPos().Y() );
543 : : }
544 [ + + ]: 1482 : else if( rTextHint.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED )
545 : : {
546 [ - + ]: 210 : if ( mpTextWindow->GetTextView()->GetStartDocPos().Y() )
547 : : {
548 : 0 : long nOutHeight = mpTextWindow->GetOutputSizePixel().Height();
549 : 0 : long nTextHeight = mpTextWindow->GetTextEngine()->GetTextHeight();
550 [ # # ]: 0 : if ( nTextHeight < nOutHeight )
551 : 0 : mpTextWindow->GetTextView()->Scroll( 0, mpTextWindow->GetTextView()->GetStartDocPos().Y() );
552 : : }
553 : :
554 : 210 : ImpSetScrollBarRanges();
555 : : }
556 [ + + ]: 1272 : else if( rTextHint.GetId() == TEXT_HINT_TEXTFORMATTED )
557 : : {
558 [ + + ]: 482 : if ( mpHScrollBar )
559 : : {
560 : 146 : sal_uLong nWidth = mpTextWindow->GetTextEngine()->CalcTextWidth();
561 [ + + ]: 146 : if ( nWidth != mnTextWidth )
562 : : {
563 : 42 : mnTextWidth = sal::static_int_cast< xub_StrLen >(nWidth);
564 [ + - ]: 42 : mpHScrollBar->SetRange( Range( 0, (long)mnTextWidth-1 ) );
565 : 42 : ImpSetHScrollBarThumbPos();
566 : : }
567 : : }
568 : : }
569 [ - + ]: 790 : else if( rTextHint.GetId() == TEXT_HINT_MODIFIED )
570 : : {
571 : 0 : pSvVCLMultiLineEdit->Modify();
572 : : }
573 : : }
574 : 1482 : }
575 : :
576 : 0 : void ImpSvMEdit::SetSelection( const Selection& rSelection )
577 : : {
578 [ # # ]: 0 : String aText = mpTextWindow->GetTextEngine()->GetText();
579 : :
580 : 0 : Selection aNewSelection( rSelection );
581 [ # # ]: 0 : if ( aNewSelection.Min() < 0 )
582 : 0 : aNewSelection.Min() = 0;
583 [ # # ]: 0 : else if ( aNewSelection.Min() > aText.Len() )
584 : 0 : aNewSelection.Min() = aText.Len();
585 [ # # ]: 0 : if ( aNewSelection.Max() < 0 )
586 : 0 : aNewSelection.Max() = 0;
587 [ # # ]: 0 : else if ( aNewSelection.Max() > aText.Len() )
588 : 0 : aNewSelection.Max() = aText.Len();
589 : :
590 : 0 : long nEnd = Max( aNewSelection.Min(), aNewSelection.Max() );
591 [ # # ]: 0 : TextSelection aTextSel;
592 : 0 : sal_uLong nPara = 0;
593 : 0 : sal_uInt16 nChar = 0;
594 : 0 : sal_uInt16 x = 0;
595 [ # # ]: 0 : while ( x <= nEnd )
596 : : {
597 [ # # ]: 0 : if ( x == aNewSelection.Min() )
598 : 0 : aTextSel.GetStart() = TextPaM( nPara, nChar );
599 [ # # ]: 0 : if ( x == aNewSelection.Max() )
600 : 0 : aTextSel.GetEnd() = TextPaM( nPara, nChar );
601 : :
602 [ # # ][ # # ]: 0 : if ( ( x < aText.Len() ) && ( aText.GetChar( x ) == '\n' ) )
[ # # ]
603 : : {
604 : 0 : nPara++;
605 : 0 : nChar = 0;
606 : : }
607 : : else
608 : 0 : nChar++;
609 : 0 : x++;
610 : : }
611 [ # # ][ # # ]: 0 : mpTextWindow->GetTextView()->SetSelection( aTextSel );
612 : 0 : }
613 : :
614 : 0 : const Selection& ImpSvMEdit::GetSelection() const
615 : : {
616 : 0 : maSelection = Selection();
617 [ # # ]: 0 : TextSelection aTextSel( mpTextWindow->GetTextView()->GetSelection() );
618 [ # # ]: 0 : aTextSel.Justify();
619 : : // Selektion flachklopfen => jeder Umbruch ein Zeichen...
620 : :
621 : 0 : ExtTextEngine* pExtTextEngine = mpTextWindow->GetTextEngine();
622 : : // Absaetze davor:
623 : : sal_uLong n;
624 [ # # ]: 0 : for ( n = 0; n < aTextSel.GetStart().GetPara(); n++ )
625 : : {
626 [ # # ]: 0 : maSelection.Min() += pExtTextEngine->GetTextLen( n );
627 : 0 : maSelection.Min()++;
628 : : }
629 : :
630 : : // Erster Absatz mit Selektion:
631 : 0 : maSelection.Max() = maSelection.Min();
632 : 0 : maSelection.Min() += aTextSel.GetStart().GetIndex();
633 : :
634 [ # # ]: 0 : for ( n = aTextSel.GetStart().GetPara(); n < aTextSel.GetEnd().GetPara(); n++ )
635 : : {
636 [ # # ]: 0 : maSelection.Max() += pExtTextEngine->GetTextLen( n );
637 : 0 : maSelection.Max()++;
638 : : }
639 : :
640 : 0 : maSelection.Max() += aTextSel.GetEnd().GetIndex();
641 : :
642 : 0 : return maSelection;
643 : : }
644 : :
645 : 0 : Size ImpSvMEdit::CalcMinimumSize() const
646 : : {
647 : 0 : Size aSz( mpTextWindow->GetTextEngine()->CalcTextWidth(),
648 : 0 : mpTextWindow->GetTextEngine()->GetTextHeight() );
649 : :
650 [ # # ]: 0 : if ( mpHScrollBar )
651 : 0 : aSz.Height() += mpHScrollBar->GetSizePixel().Height();
652 [ # # ]: 0 : if ( mpVScrollBar )
653 : 0 : aSz.Width() += mpVScrollBar->GetSizePixel().Width();
654 : :
655 : 0 : return aSz;
656 : : }
657 : :
658 : 0 : Size ImpSvMEdit::CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const
659 : : {
660 : : static const sal_Unicode sampleChar = 'X';
661 : :
662 : 0 : Size aSz;
663 : 0 : Size aCharSz;
664 [ # # ][ # # ]: 0 : aCharSz.Width() = mpTextWindow->GetTextWidth( rtl::OUString(sampleChar) );
[ # # ]
665 [ # # ]: 0 : aCharSz.Height() = mpTextWindow->GetTextHeight();
666 : :
667 [ # # ]: 0 : if ( nLines )
668 : 0 : aSz.Height() = nLines*aCharSz.Height();
669 : : else
670 [ # # ]: 0 : aSz.Height() = mpTextWindow->GetTextEngine()->GetTextHeight();
671 : :
672 [ # # ]: 0 : if ( nColumns )
673 : 0 : aSz.Width() = nColumns*aCharSz.Width();
674 : : else
675 [ # # ]: 0 : aSz.Width() = mpTextWindow->GetTextEngine()->CalcTextWidth();
676 : :
677 [ # # ]: 0 : if ( mpHScrollBar )
678 [ # # ]: 0 : aSz.Height() += mpHScrollBar->GetSizePixel().Height();
679 [ # # ]: 0 : if ( mpVScrollBar )
680 [ # # ]: 0 : aSz.Width() += mpVScrollBar->GetSizePixel().Width();
681 : :
682 : 0 : return aSz;
683 : : }
684 : :
685 : 0 : void ImpSvMEdit::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
686 : : {
687 : : static const sal_Unicode sampleChar = { 'x' };
688 : 0 : Size aOutSz = mpTextWindow->GetOutputSizePixel();
689 [ # # ][ # # ]: 0 : Size aCharSz( mpTextWindow->GetTextWidth( rtl::OUString(sampleChar) ), mpTextWindow->GetTextHeight() );
[ # # ][ # # ]
690 : 0 : rnCols = (sal_uInt16) (aOutSz.Width()/aCharSz.Width());
691 : 0 : rnLines = (sal_uInt16) (aOutSz.Height()/aCharSz.Height());
692 : 0 : }
693 : :
694 : 22 : void ImpSvMEdit::Enable( sal_Bool bEnable )
695 : : {
696 : 22 : mpTextWindow->Enable( bEnable );
697 [ + - ]: 22 : if ( mpHScrollBar )
698 : 22 : mpHScrollBar->Enable( bEnable );
699 [ + + ]: 22 : if ( mpVScrollBar )
700 : 14 : mpVScrollBar->Enable( bEnable );
701 : 22 : }
702 : :
703 : 0 : sal_Bool ImpSvMEdit::HandleCommand( const CommandEvent& rCEvt )
704 : : {
705 : 0 : sal_Bool bDone = sal_False;
706 [ # # # # : 0 : if ( ( rCEvt.GetCommand() == COMMAND_WHEEL ) ||
# # ][ # # ]
707 : 0 : ( rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL ) ||
708 : 0 : ( rCEvt.GetCommand() == COMMAND_AUTOSCROLL ) )
709 : : {
710 : 0 : mpTextWindow->HandleScrollCommand( rCEvt, mpHScrollBar, mpVScrollBar );
711 : 0 : bDone = sal_True;
712 : : }
713 : 0 : return bDone;
714 : : }
715 : :
716 : :
717 : 90 : TextWindow::TextWindow( Window* pParent ) : Window( pParent )
718 : : {
719 : 90 : mbInMBDown = sal_False;
720 : 90 : mbSelectOnTab = sal_True;
721 : 90 : mbFocusSelectionHide = sal_False;
722 : 90 : mbIgnoreTab = sal_False;
723 : 90 : mbActivePopup = sal_False;
724 : 90 : mbSelectOnTab = sal_True;
725 : 90 : mbTextSelectable = sal_True;
726 : :
727 [ + - ]: 90 : SetPointer( Pointer( POINTER_TEXT ) );
728 : :
729 [ + - ][ + - ]: 90 : mpExtTextEngine = new ExtTextEngine;
730 [ + - ]: 90 : mpExtTextEngine->SetMaxTextLen( STRING_MAXLEN );
731 [ + - ][ + + ]: 90 : if( pParent->GetStyle() & WB_BORDER )
732 [ + - ]: 22 : mpExtTextEngine->SetLeftMargin( 2 );
733 [ + - ][ + - ]: 90 : mpExtTextEngine->SetLocale( GetSettings().GetLocale() );
734 [ + - ][ + - ]: 90 : mpExtTextView = new ExtTextView( mpExtTextEngine, this );
735 [ + - ]: 90 : mpExtTextEngine->InsertView( mpExtTextView );
736 [ + - ]: 90 : mpExtTextEngine->EnableUndo( sal_True );
737 [ + - ]: 90 : mpExtTextView->ShowCursor();
738 : :
739 : 90 : Color aBackgroundColor = GetSettings().GetStyleSettings().GetWorkspaceColor();
740 [ + - ][ + - ]: 90 : SetBackground( aBackgroundColor );
[ + - ]
741 [ + - ][ + - ]: 90 : pParent->SetBackground( aBackgroundColor );
[ + - ]
742 : 90 : }
743 : :
744 : 90 : TextWindow::~TextWindow()
745 : : {
746 [ + - ][ + - ]: 90 : delete mpExtTextView;
747 [ + - ][ + - ]: 90 : delete mpExtTextEngine;
748 [ - + ]: 180 : }
749 : :
750 : 0 : void TextWindow::MouseMove( const MouseEvent& rMEvt )
751 : : {
752 : 0 : mpExtTextView->MouseMove( rMEvt );
753 : 0 : Window::MouseMove( rMEvt );
754 : 0 : }
755 : :
756 : 0 : void TextWindow::MouseButtonDown( const MouseEvent& rMEvt )
757 : : {
758 [ # # ]: 0 : if ( !mbTextSelectable )
759 : 0 : return;
760 : :
761 : 0 : mbInMBDown = sal_True; // Dann im GetFocus nicht alles selektieren wird
762 : 0 : mpExtTextView->MouseButtonDown( rMEvt );
763 : 0 : Window::MouseButtonDown( rMEvt );
764 : 0 : GrabFocus();
765 : 0 : mbInMBDown = sal_False;
766 : : }
767 : :
768 : 0 : void TextWindow::MouseButtonUp( const MouseEvent& rMEvt )
769 : : {
770 : 0 : mpExtTextView->MouseButtonUp( rMEvt );
771 : 0 : Window::MouseButtonUp( rMEvt );
772 : 0 : }
773 : :
774 : 0 : void TextWindow::KeyInput( const KeyEvent& rKEvent )
775 : : {
776 : 0 : sal_Bool bDone = sal_False;
777 : 0 : sal_uInt16 nCode = rKEvent.GetKeyCode().GetCode();
778 [ # # # # : 0 : if ( nCode == com::sun::star::awt::Key::SELECT_ALL ||
# # ][ # # ]
[ # # ]
779 : 0 : ( (nCode == KEY_A) && rKEvent.GetKeyCode().IsMod1() && !rKEvent.GetKeyCode().IsMod2() )
780 : : )
781 : : {
782 [ # # ][ # # ]: 0 : mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFF, 0xFFFF ) ) );
783 : 0 : bDone = sal_True;
784 : : }
785 [ # # ][ # # ]: 0 : else if ( (nCode == KEY_S) && rKEvent.GetKeyCode().IsShift() && rKEvent.GetKeyCode().IsMod1() )
[ # # ][ # # ]
786 : : {
787 [ # # ]: 0 : if ( Edit::GetGetSpecialCharsFunction() )
788 : : {
789 : : // Damit die Selektion erhalten bleibt
790 : 0 : mbActivePopup = sal_True;
791 [ # # ][ # # ]: 0 : rtl::OUString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() );
[ # # ][ # # ]
792 [ # # ]: 0 : if (!aChars.isEmpty())
793 : : {
794 [ # # ][ # # ]: 0 : mpExtTextView->InsertText( aChars );
[ # # ]
795 [ # # ]: 0 : mpExtTextView->GetTextEngine()->SetModified( sal_True );
796 : : }
797 : 0 : mbActivePopup = sal_False;
798 : 0 : bDone = sal_True;
799 : : }
800 : : }
801 [ # # ]: 0 : else if ( nCode == KEY_TAB )
802 : : {
803 [ # # ][ # # ]: 0 : if ( !mbIgnoreTab || rKEvent.GetKeyCode().IsMod1() )
[ # # ]
804 : 0 : bDone = mpExtTextView->KeyInput( rKEvent );
805 : : }
806 : : else
807 : : {
808 : 0 : bDone = mpExtTextView->KeyInput( rKEvent );
809 : : }
810 : :
811 [ # # ]: 0 : if ( !bDone )
812 : 0 : Window::KeyInput( rKEvent );
813 : 0 : }
814 : :
815 : 89 : void TextWindow::Paint( const Rectangle& rRect )
816 : : {
817 : 89 : mpExtTextView->Paint( rRect );
818 : 89 : }
819 : :
820 : 132 : void TextWindow::Resize()
821 : : {
822 : 132 : }
823 : :
824 : 0 : void TextWindow::Command( const CommandEvent& rCEvt )
825 : : {
826 [ # # ]: 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
827 : : {
828 [ # # ]: 0 : PopupMenu* pPopup = Edit::CreatePopupMenu();
829 [ # # ][ # # ]: 0 : if ( !mpExtTextView->HasSelection() )
830 : : {
831 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_CUT, sal_False );
832 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_COPY, sal_False );
833 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_DELETE, sal_False );
834 : : }
835 [ # # ][ # # ]: 0 : if ( mpExtTextView->IsReadOnly() )
836 : : {
837 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_CUT, sal_False );
838 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_PASTE, sal_False );
839 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_DELETE, sal_False );
840 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_INSERTSYMBOL, sal_False );
841 : : }
842 [ # # ][ # # ]: 0 : if ( !mpExtTextView->GetTextEngine()->HasUndoManager() || !mpExtTextView->GetTextEngine()->GetUndoManager().GetUndoActionCount() )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
843 : : {
844 [ # # ]: 0 : pPopup->EnableItem( SV_MENU_EDIT_UNDO, sal_False );
845 : : }
846 : : // if ( ( maSelection.Min() == 0 ) && ( maSelection.Max() == maText.Len() ) )
847 : : // {
848 : : // pPopup->EnableItem( SV_MENU_EDIT_SELECTALL, sal_False );
849 : : // }
850 [ # # ][ # # ]: 0 : if ( !Edit::GetGetSpecialCharsFunction() )
851 : : {
852 [ # # ]: 0 : sal_uInt16 nPos = pPopup->GetItemPos( SV_MENU_EDIT_INSERTSYMBOL );
853 [ # # ]: 0 : pPopup->RemoveItem( nPos );
854 [ # # ]: 0 : pPopup->RemoveItem( nPos-1 );
855 : : }
856 : :
857 : 0 : mbActivePopup = sal_True;
858 : 0 : Point aPos = rCEvt.GetMousePosPixel();
859 [ # # ]: 0 : if ( !rCEvt.IsMouseEvent() )
860 : : {
861 : : // !!! Irgendwann einmal Menu zentriert in der Selektion anzeigen !!!
862 : 0 : Size aSize = GetOutputSizePixel();
863 : 0 : aPos = Point( aSize.Width()/2, aSize.Height()/2 );
864 : : }
865 : : // pPopup->RemoveDisabledEntries();
866 [ # # ]: 0 : sal_uInt16 n = pPopup->Execute( this, aPos );
867 [ # # ]: 0 : Edit::DeletePopupMenu( pPopup );
868 [ # # # # : 0 : switch ( n )
# # # # ]
869 : : {
870 [ # # ]: 0 : case SV_MENU_EDIT_UNDO: mpExtTextView->Undo();
871 : 0 : mpExtTextEngine->SetModified( sal_True );
872 [ # # ][ # # ]: 0 : mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
[ # # ]
873 : 0 : break;
874 [ # # ]: 0 : case SV_MENU_EDIT_CUT: mpExtTextView->Cut();
875 : 0 : mpExtTextEngine->SetModified( sal_True );
876 [ # # ][ # # ]: 0 : mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
[ # # ]
877 : 0 : break;
878 [ # # ]: 0 : case SV_MENU_EDIT_COPY: mpExtTextView->Copy();
879 : 0 : break;
880 [ # # ]: 0 : case SV_MENU_EDIT_PASTE: mpExtTextView->Paste();
881 : 0 : mpExtTextEngine->SetModified( sal_True );
882 [ # # ][ # # ]: 0 : mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
[ # # ]
883 : 0 : break;
884 [ # # ]: 0 : case SV_MENU_EDIT_DELETE: mpExtTextView->DeleteSelected();
885 : 0 : mpExtTextEngine->SetModified( sal_True );
886 [ # # ][ # # ]: 0 : mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
[ # # ]
887 : 0 : break;
888 [ # # ][ # # ]: 0 : case SV_MENU_EDIT_SELECTALL: mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
889 : 0 : break;
890 : : case SV_MENU_EDIT_INSERTSYMBOL:
891 : : {
892 [ # # ][ # # ]: 0 : rtl::OUString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() );
[ # # ][ # # ]
893 [ # # ]: 0 : if (!aChars.isEmpty())
894 : : {
895 [ # # ][ # # ]: 0 : mpExtTextView->InsertText( aChars );
[ # # ]
896 : 0 : mpExtTextEngine->SetModified( sal_True );
897 [ # # ][ # # ]: 0 : mpExtTextEngine->Broadcast( TextHint( TEXT_HINT_MODIFIED ) );
[ # # ]
898 : 0 : }
899 : : }
900 : 0 : break;
901 : : }
902 : 0 : mbActivePopup = sal_False;
903 : : }
904 : : else
905 : : {
906 : 0 : mpExtTextView->Command( rCEvt );
907 : : }
908 : 0 : Window::Command( rCEvt );
909 : 0 : }
910 : :
911 : 0 : void TextWindow::GetFocus()
912 : : {
913 : 0 : Window::GetFocus();
914 [ # # ]: 0 : if ( !mbActivePopup )
915 : : {
916 : 0 : sal_Bool bGotoCursor = !mpExtTextView->IsReadOnly();
917 [ # # ][ # # ]: 0 : if ( mbFocusSelectionHide && IsReallyVisible() && !mpExtTextView->IsReadOnly()
[ # # ]
[ # # # # ]
[ # # ][ # # ]
918 : : && ( mbSelectOnTab &&
919 : 0 : (!mbInMBDown || ( GetSettings().GetStyleSettings().GetSelectionOptions() & SELECTION_OPTION_FOCUS ) )) )
920 : : {
921 : : // Alles selektieren, aber nicht scrollen
922 : 0 : sal_Bool bAutoScroll = mpExtTextView->IsAutoScroll();
923 : 0 : mpExtTextView->SetAutoScroll( sal_False );
924 [ # # ][ # # ]: 0 : mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFF, 0xFFFF ) ) );
925 : 0 : mpExtTextView->SetAutoScroll( bAutoScroll );
926 : 0 : bGotoCursor = sal_False;
927 : : }
928 : 0 : mpExtTextView->SetPaintSelection( sal_True );
929 : 0 : mpExtTextView->ShowCursor( bGotoCursor );
930 : : }
931 : 0 : }
932 : :
933 : 0 : void TextWindow::LoseFocus()
934 : : {
935 : 0 : Window::LoseFocus();
936 : :
937 [ # # ][ # # ]: 0 : if ( mbFocusSelectionHide && !mbActivePopup )
938 : 0 : mpExtTextView->SetPaintSelection( sal_False );
939 : 0 : }
940 : :
941 : 90 : VCLMultiLineEdit::VCLMultiLineEdit( Window* pParent, WinBits nWinStyle )
942 [ + - ][ + - ]: 90 : : Edit( pParent, nWinStyle )
[ + - ]
943 : : {
944 [ + - ]: 90 : SetType( WINDOW_MULTILINEEDIT );
945 [ + - ][ + - ]: 90 : pImpSvMEdit = new ImpSvMEdit( this, nWinStyle );
946 [ + - ]: 90 : ImplInitSettings( sal_True, sal_True, sal_True );
947 : 90 : pUpdateDataTimer = 0;
948 : :
949 [ + - ]: 90 : SetCompoundControl( sal_True );
950 [ + - ][ + - ]: 90 : SetStyle( ImplInitStyle( nWinStyle ) );
951 : 90 : }
952 : :
953 : 0 : VCLMultiLineEdit::VCLMultiLineEdit( Window* pParent, const ResId& rResId )
954 [ # # ][ # # ]: 0 : : Edit( pParent, rResId.SetRT( RSC_MULTILINEEDIT ) )
[ # # ]
955 : : {
956 [ # # ]: 0 : SetType( WINDOW_MULTILINEEDIT );
957 : 0 : WinBits nWinStyle = rResId.GetWinBits();
958 [ # # ][ # # ]: 0 : pImpSvMEdit = new ImpSvMEdit( this, nWinStyle );
959 [ # # ]: 0 : ImplInitSettings( sal_True, sal_True, sal_True );
960 : 0 : pUpdateDataTimer = 0;
961 : :
962 : 0 : sal_uInt16 nMaxLen = Edit::GetMaxTextLen();
963 [ # # ]: 0 : if ( nMaxLen )
964 [ # # ]: 0 : SetMaxTextLen( nMaxLen );
965 : :
966 [ # # ][ # # ]: 0 : SetText( Edit::GetText() );
[ # # ]
967 : :
968 [ # # ][ # # ]: 0 : if ( IsVisible() )
969 [ # # ]: 0 : pImpSvMEdit->Resize();
970 : :
971 [ # # ]: 0 : SetCompoundControl( sal_True );
972 [ # # ][ # # ]: 0 : SetStyle( ImplInitStyle( nWinStyle ) );
973 : :
974 : : // Base Edit ctor could call Show already, but that would cause problems
975 : : // with accessibility, as Show might (indirectly) trigger a call to virtual
976 : : // GetComponentInterface, which is the Edit's base version instead of the
977 : : // VCLMultiLineEdit's version while in the base Edit ctor:
978 [ # # ][ # # ]: 0 : if ((GetStyle() & WB_HIDE) == 0)
979 [ # # ]: 0 : Show();
980 : :
981 : 0 : }
982 : :
983 [ + - ]: 90 : VCLMultiLineEdit::~VCLMultiLineEdit()
984 : : {
985 : : {
986 : 90 : ::std::auto_ptr< ImpSvMEdit > pDelete( pImpSvMEdit );
987 [ + - ]: 90 : pImpSvMEdit = NULL;
988 : : }
989 [ - + ][ # # ]: 90 : delete pUpdateDataTimer;
990 [ - + ]: 90 : }
991 : :
992 : 272 : WinBits VCLMultiLineEdit::ImplInitStyle( WinBits nStyle )
993 : : {
994 [ + - ]: 272 : if ( !(nStyle & WB_NOTABSTOP) )
995 : 272 : nStyle |= WB_TABSTOP;
996 : :
997 [ + - ]: 272 : if ( !(nStyle & WB_NOGROUP) )
998 : 272 : nStyle |= WB_GROUP;
999 : :
1000 [ + + ]: 272 : if ( !(nStyle & WB_IGNORETAB ))
1001 : 136 : nStyle |= WINDOW_DLGCTRL_MOD1TAB;
1002 : :
1003 : 272 : return nStyle;
1004 : : }
1005 : :
1006 : :
1007 : 342 : void VCLMultiLineEdit::ImplInitSettings( sal_Bool /*bFont*/, sal_Bool /*bForeground*/, sal_Bool bBackground )
1008 : : {
1009 : 342 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1010 : :
1011 : : // Der Font muss immer mit manipuliert werden, weil die TextEngine
1012 : : // sich nicht um TextColor/Background kuemmert
1013 : :
1014 : 342 : Color aTextColor = rStyleSettings.GetFieldTextColor();
1015 [ + + ][ + - ]: 342 : if ( IsControlForeground() )
1016 [ + - ]: 90 : aTextColor = GetControlForeground();
1017 [ + - ][ + + ]: 342 : if ( !IsEnabled() )
1018 : 78 : aTextColor = rStyleSettings.GetDisableColor();
1019 : :
1020 [ + - ]: 342 : Font aFont = rStyleSettings.GetFieldFont();
1021 [ + - ][ + + ]: 342 : if ( IsControlFont() )
1022 [ + - ][ + - ]: 76 : aFont.Merge( GetControlFont() );
[ + - ]
1023 [ + - ][ + - ]: 342 : aFont.SetTransparent( IsPaintTransparent() );
1024 [ + - ]: 342 : SetZoomedPointFont( aFont );
1025 [ + - ]: 342 : Font TheFont = GetFont();
1026 [ + - ]: 342 : TheFont.SetColor( aTextColor );
1027 [ + - ][ + + ]: 342 : if( IsPaintTransparent() )
1028 [ + - ]: 102 : TheFont.SetFillColor( Color( COL_TRANSPARENT ) );
1029 : : else
1030 [ + - ][ - + ]: 240 : TheFont.SetFillColor( IsControlBackground() ? GetControlBackground() : rStyleSettings.GetFieldColor() );
[ # # ][ + - ]
1031 [ + - ]: 342 : pImpSvMEdit->GetTextWindow()->SetFont( TheFont );
1032 [ + - ]: 342 : pImpSvMEdit->GetTextWindow()->GetTextEngine()->SetFont( TheFont );
1033 [ + - ]: 342 : pImpSvMEdit->GetTextWindow()->SetTextColor( aTextColor );
1034 : :
1035 [ + + ]: 342 : if ( bBackground )
1036 : : {
1037 [ + - ][ + + ]: 248 : if( IsPaintTransparent() )
1038 : : {
1039 [ + - ]: 96 : pImpSvMEdit->GetTextWindow()->SetPaintTransparent( sal_True );
1040 [ + - ]: 96 : pImpSvMEdit->GetTextWindow()->SetBackground();
1041 [ + - ]: 96 : pImpSvMEdit->GetTextWindow()->SetControlBackground();
1042 [ + - ]: 96 : SetBackground();
1043 [ + - ]: 96 : SetControlBackground();
1044 : : }
1045 : : else
1046 : : {
1047 [ + - ][ - + ]: 152 : if( IsControlBackground() )
1048 [ # # ][ # # ]: 0 : pImpSvMEdit->GetTextWindow()->SetBackground( GetControlBackground() );
[ # # ][ # # ]
1049 : : else
1050 [ + - ][ + - ]: 152 : pImpSvMEdit->GetTextWindow()->SetBackground( rStyleSettings.GetFieldColor() );
[ + - ]
1051 : : // Auch am VCLMultiLineEdit einstellen, weil die TextComponent
1052 : : // ggf. die Scrollbars hidet.
1053 [ + - ]: 152 : SetBackground( pImpSvMEdit->GetTextWindow()->GetBackground() );
1054 : : }
1055 [ + - ][ + - ]: 342 : }
1056 : 342 : }
1057 : :
1058 : 32 : void VCLMultiLineEdit::Modify()
1059 : : {
1060 : 32 : aModifyHdlLink.Call( this );
1061 : :
1062 : 32 : CallEventListeners( VCLEVENT_EDIT_MODIFY );
1063 : :
1064 [ - + ]: 32 : if ( pUpdateDataTimer )
1065 : 0 : pUpdateDataTimer->Start();
1066 : 32 : }
1067 : :
1068 : 0 : IMPL_LINK_NOARG(VCLMultiLineEdit, ImpUpdateDataHdl)
1069 : : {
1070 : 0 : UpdateData();
1071 : 0 : return 0;
1072 : : }
1073 : :
1074 : 0 : void VCLMultiLineEdit::UpdateData()
1075 : : {
1076 : 0 : aUpdateDataHdlLink.Call( this );
1077 : 0 : }
1078 : :
1079 : 32 : void VCLMultiLineEdit::SetModifyFlag()
1080 : : {
1081 : 32 : pImpSvMEdit->SetModified( sal_True );
1082 : 32 : }
1083 : :
1084 : 0 : void VCLMultiLineEdit::ClearModifyFlag()
1085 : : {
1086 : 0 : pImpSvMEdit->SetModified( sal_False );
1087 : 0 : }
1088 : :
1089 : 0 : sal_Bool VCLMultiLineEdit::IsModified() const
1090 : : {
1091 : 0 : return pImpSvMEdit->IsModified();
1092 : : }
1093 : :
1094 : 0 : void VCLMultiLineEdit::EnableUpdateData( sal_uLong nTimeout )
1095 : : {
1096 [ # # ]: 0 : if ( !nTimeout )
1097 : 0 : DisableUpdateData();
1098 : : else
1099 : : {
1100 [ # # ]: 0 : if ( !pUpdateDataTimer )
1101 : : {
1102 [ # # ]: 0 : pUpdateDataTimer = new Timer;
1103 : 0 : pUpdateDataTimer->SetTimeoutHdl( LINK( this, VCLMultiLineEdit, ImpUpdateDataHdl ) );
1104 : : }
1105 : 0 : pUpdateDataTimer->SetTimeout( nTimeout );
1106 : : }
1107 : 0 : }
1108 : :
1109 : 60 : void VCLMultiLineEdit::SetReadOnly( sal_Bool bReadOnly )
1110 : : {
1111 : 60 : pImpSvMEdit->SetReadOnly( bReadOnly );
1112 : 60 : Edit::SetReadOnly( bReadOnly );
1113 : :
1114 : : // #94921# ReadOnly can be overwritten in InitFromStyle() when WB not set.
1115 : 60 : WinBits nStyle = GetStyle();
1116 [ + + ]: 60 : if ( bReadOnly )
1117 : 22 : nStyle |= WB_READONLY;
1118 : : else
1119 : 38 : nStyle &= ~WB_READONLY;
1120 : 60 : SetStyle( nStyle );
1121 : 60 : }
1122 : :
1123 : 22 : sal_Bool VCLMultiLineEdit::IsReadOnly() const
1124 : : {
1125 : 22 : return pImpSvMEdit->IsReadOnly();
1126 : : }
1127 : :
1128 : 94 : void VCLMultiLineEdit::SetMaxTextLen( xub_StrLen nMaxLen )
1129 : : {
1130 : 94 : pImpSvMEdit->SetMaxTextLen( nMaxLen );
1131 : 94 : }
1132 : :
1133 : 0 : xub_StrLen VCLMultiLineEdit::GetMaxTextLen() const
1134 : : {
1135 : 0 : return pImpSvMEdit->GetMaxTextLen();
1136 : : }
1137 : :
1138 : 0 : void VCLMultiLineEdit::ReplaceSelected( const String& rStr )
1139 : : {
1140 : 0 : pImpSvMEdit->InsertText( rStr );
1141 : 0 : }
1142 : :
1143 : 0 : void VCLMultiLineEdit::DeleteSelected()
1144 : : {
1145 [ # # ]: 0 : pImpSvMEdit->InsertText( String() );
1146 : 0 : }
1147 : :
1148 : 0 : String VCLMultiLineEdit::GetSelected() const
1149 : : {
1150 : 0 : return pImpSvMEdit->GetSelected();
1151 : : }
1152 : :
1153 : 0 : String VCLMultiLineEdit::GetSelected( LineEnd aSeparator ) const
1154 : : {
1155 : 0 : return pImpSvMEdit->GetSelected( aSeparator );
1156 : : }
1157 : :
1158 : 0 : void VCLMultiLineEdit::Cut()
1159 : : {
1160 : 0 : pImpSvMEdit->Cut();
1161 : 0 : }
1162 : :
1163 : 0 : void VCLMultiLineEdit::Copy()
1164 : : {
1165 : 0 : pImpSvMEdit->Copy();
1166 : 0 : }
1167 : :
1168 : 0 : void VCLMultiLineEdit::Paste()
1169 : : {
1170 : 0 : pImpSvMEdit->Paste();
1171 : 0 : }
1172 : :
1173 : 128 : void VCLMultiLineEdit::SetText( const String& rStr )
1174 : : {
1175 : 128 : pImpSvMEdit->SetText( rStr );
1176 : 128 : }
1177 : :
1178 : 0 : String VCLMultiLineEdit::GetText() const
1179 : : {
1180 : 0 : return pImpSvMEdit->GetText();
1181 : : }
1182 : :
1183 : 0 : String VCLMultiLineEdit::GetText( LineEnd aSeparator ) const
1184 : : {
1185 : 0 : return pImpSvMEdit->GetText( aSeparator );
1186 : : }
1187 : :
1188 : 0 : String VCLMultiLineEdit::GetTextLines( LineEnd aSeparator ) const
1189 : : {
1190 : 0 : return pImpSvMEdit->GetTextLines( aSeparator );
1191 : : }
1192 : :
1193 : 156 : void VCLMultiLineEdit::Resize()
1194 : : {
1195 : 156 : pImpSvMEdit->Resize();
1196 : 156 : }
1197 : :
1198 : 0 : void VCLMultiLineEdit::GetFocus()
1199 : : {
1200 [ # # ]: 0 : if ( !pImpSvMEdit ) // might be called from within the dtor, when pImpSvMEdit == NULL is a valid state
1201 : 0 : return;
1202 : :
1203 : 0 : Edit::GetFocus();
1204 : 0 : pImpSvMEdit->GetFocus();
1205 : : }
1206 : :
1207 : 0 : void VCLMultiLineEdit::SetSelection( const Selection& rSelection )
1208 : : {
1209 : 0 : pImpSvMEdit->SetSelection( rSelection );
1210 : 0 : }
1211 : :
1212 : 0 : const Selection& VCLMultiLineEdit::GetSelection() const
1213 : : {
1214 : 0 : return pImpSvMEdit->GetSelection();
1215 : : }
1216 : :
1217 : 0 : Size VCLMultiLineEdit::CalcMinimumSize() const
1218 : : {
1219 [ # # ]: 0 : Size aSz = pImpSvMEdit->CalcMinimumSize();
1220 : :
1221 : : sal_Int32 nLeft, nTop, nRight, nBottom;
1222 [ # # ]: 0 : ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1223 : 0 : aSz.Width() += nLeft+nRight;
1224 : 0 : aSz.Height() += nTop+nBottom;
1225 : :
1226 : 0 : return aSz;
1227 : : }
1228 : :
1229 : 0 : Size VCLMultiLineEdit::CalcAdjustedSize( const Size& rPrefSize ) const
1230 : : {
1231 : 0 : Size aSz = rPrefSize;
1232 : : sal_Int32 nLeft, nTop, nRight, nBottom;
1233 [ # # ]: 0 : ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1234 : :
1235 : : // In der Hoehe auf ganze Zeilen justieren
1236 : :
1237 : 0 : long nHeight = aSz.Height() - nTop - nBottom;
1238 [ # # ]: 0 : long nLineHeight = pImpSvMEdit->CalcSize( 1, 1 ).Height();
1239 : 0 : long nLines = nHeight / nLineHeight;
1240 [ # # ]: 0 : if ( nLines < 1 )
1241 : 0 : nLines = 1;
1242 : :
1243 : 0 : aSz.Height() = nLines * nLineHeight;
1244 : 0 : aSz.Height() += nTop+nBottom;
1245 : :
1246 : 0 : return aSz;
1247 : : }
1248 : :
1249 : 0 : Size VCLMultiLineEdit::CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const
1250 : : {
1251 [ # # ]: 0 : Size aSz = pImpSvMEdit->CalcSize( nColumns, nLines );
1252 : :
1253 : : sal_Int32 nLeft, nTop, nRight, nBottom;
1254 [ # # ]: 0 : ((Window*)this)->GetBorder( nLeft, nTop, nRight, nBottom );
1255 : 0 : aSz.Width() += nLeft+nRight;
1256 : 0 : aSz.Height() += nTop+nBottom;
1257 : 0 : return aSz;
1258 : : }
1259 : :
1260 : 0 : void VCLMultiLineEdit::GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const
1261 : : {
1262 : 0 : pImpSvMEdit->GetMaxVisColumnsAndLines( rnCols, rnLines );
1263 : 0 : }
1264 : :
1265 : 738 : void VCLMultiLineEdit::StateChanged( StateChangedType nType )
1266 : : {
1267 [ + + ]: 738 : if( nType == STATE_CHANGE_ENABLE )
1268 : : {
1269 : 22 : pImpSvMEdit->Enable( IsEnabled() );
1270 : 22 : ImplInitSettings( sal_True, sal_False, sal_False );
1271 : : }
1272 [ + + ]: 716 : else if( nType == STATE_CHANGE_READONLY )
1273 : : {
1274 : 22 : pImpSvMEdit->SetReadOnly( IsReadOnly() );
1275 : : }
1276 [ - + ]: 694 : else if ( nType == STATE_CHANGE_ZOOM )
1277 : : {
1278 : 0 : pImpSvMEdit->GetTextWindow()->SetZoom( GetZoom() );
1279 : 0 : ImplInitSettings( sal_True, sal_False, sal_False );
1280 : 0 : Resize();
1281 : : }
1282 [ + + ]: 694 : else if ( nType == STATE_CHANGE_CONTROLFONT )
1283 : : {
1284 : 66 : ImplInitSettings( sal_True, sal_False, sal_False );
1285 : 66 : Resize();
1286 : 66 : Invalidate();
1287 : : }
1288 [ + + ]: 628 : else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1289 : : {
1290 : 6 : ImplInitSettings( sal_False, sal_True, sal_False );
1291 : 6 : Invalidate();
1292 : : }
1293 [ + + ]: 622 : else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1294 : : {
1295 : 96 : ImplInitSettings( sal_False, sal_False, sal_True );
1296 : 96 : Invalidate();
1297 : : }
1298 [ + + ]: 526 : else if ( nType == STATE_CHANGE_STYLE )
1299 : : {
1300 : 182 : pImpSvMEdit->InitFromStyle( GetStyle() );
1301 : 182 : SetStyle( ImplInitStyle( GetStyle() ) );
1302 : : }
1303 [ + + ]: 344 : else if ( nType == STATE_CHANGE_INITSHOW )
1304 : : {
1305 [ + - ]: 48 : if( IsPaintTransparent() )
1306 : : {
1307 : 48 : pImpSvMEdit->GetTextWindow()->SetPaintTransparent( sal_True );
1308 : 48 : pImpSvMEdit->GetTextWindow()->SetBackground();
1309 : 48 : pImpSvMEdit->GetTextWindow()->SetControlBackground();
1310 : 48 : SetBackground();
1311 : 48 : SetControlBackground();
1312 : : }
1313 : : }
1314 : :
1315 : 738 : Control::StateChanged( nType );
1316 : 738 : }
1317 : :
1318 : 62 : void VCLMultiLineEdit::DataChanged( const DataChangedEvent& rDCEvt )
1319 : : {
1320 [ + - + - ]: 124 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
[ + - ]
1321 : 62 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1322 : : {
1323 : 62 : ImplInitSettings( sal_True, sal_True, sal_True );
1324 : 62 : Resize();
1325 : 62 : Invalidate();
1326 : : }
1327 : : else
1328 : 0 : Control::DataChanged( rDCEvt );
1329 : 62 : }
1330 : :
1331 : 0 : void VCLMultiLineEdit::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
1332 : : {
1333 [ # # ]: 0 : ImplInitSettings( sal_True, sal_True, sal_True );
1334 : :
1335 [ # # ]: 0 : Point aPos = pDev->LogicToPixel( rPos );
1336 [ # # ]: 0 : Size aSize = pDev->LogicToPixel( rSize );
1337 [ # # ]: 0 : Font aFont = pImpSvMEdit->GetTextWindow()->GetDrawPixelFont( pDev );
1338 [ # # ]: 0 : aFont.SetTransparent( sal_True );
1339 : 0 : OutDevType eOutDevType = pDev->GetOutDevType();
1340 : :
1341 [ # # ]: 0 : pDev->Push();
1342 [ # # ]: 0 : pDev->SetMapMode();
1343 [ # # ]: 0 : pDev->SetFont( aFont );
1344 [ # # ]: 0 : pDev->SetTextFillColor();
1345 : :
1346 : : // Border/Background
1347 [ # # ]: 0 : pDev->SetLineColor();
1348 [ # # ]: 0 : pDev->SetFillColor();
1349 [ # # ][ # # ]: 0 : sal_Bool bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER);
[ # # ]
1350 [ # # ][ # # ]: 0 : sal_Bool bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground();
[ # # ]
1351 [ # # ][ # # ]: 0 : if ( bBorder || bBackground )
1352 : : {
1353 [ # # ]: 0 : Rectangle aRect( aPos, aSize );
1354 [ # # ]: 0 : if ( bBorder )
1355 : : {
1356 : 0 : DecorationView aDecoView( pDev );
1357 [ # # ]: 0 : aRect = aDecoView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
1358 : : }
1359 [ # # ]: 0 : if ( bBackground )
1360 : : {
1361 [ # # ][ # # ]: 0 : pDev->SetFillColor( GetControlBackground() );
1362 [ # # ]: 0 : pDev->DrawRect( aRect );
1363 : : }
1364 : : }
1365 : :
1366 : : // Inhalt
1367 [ # # ][ # # ]: 0 : if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) )
1368 [ # # ]: 0 : pDev->SetTextColor( Color( COL_BLACK ) );
1369 : : else
1370 : : {
1371 [ # # ][ # # ]: 0 : if ( !(nFlags & WINDOW_DRAW_NODISABLE ) && !IsEnabled() )
[ # # ][ # # ]
1372 : : {
1373 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1374 [ # # ]: 0 : pDev->SetTextColor( rStyleSettings.GetDisableColor() );
1375 : : }
1376 : : else
1377 : : {
1378 [ # # ]: 0 : pDev->SetTextColor( GetTextColor() );
1379 : : }
1380 : : }
1381 : :
1382 [ # # ][ # # ]: 0 : rtl::OUString aText = GetText();
[ # # ]
1383 [ # # ][ # # ]: 0 : Size aTextSz( pDev->GetTextWidth( aText ), pDev->GetTextHeight() );
[ # # ][ # # ]
1384 : 0 : sal_uLong nLines = (sal_uLong) (aSize.Height() / aTextSz.Height());
1385 [ # # ]: 0 : if ( !nLines )
1386 : 0 : nLines = 1;
1387 : 0 : aTextSz.Height() = nLines*aTextSz.Height();
1388 [ # # ]: 0 : long nOnePixel = GetDrawPixel( pDev, 1 );
1389 : 0 : long nOffX = 3*nOnePixel;
1390 : 0 : long nOffY = 2*nOnePixel;
1391 : :
1392 : : // Clipping?
1393 [ # # ][ # # ]: 0 : if ( ( nOffY < 0 ) || ( (nOffY+aTextSz.Height()) > aSize.Height() ) || ( (nOffX+aTextSz.Width()) > aSize.Width() ) )
[ # # ][ # # ]
1394 : : {
1395 [ # # ]: 0 : Rectangle aClip( aPos, aSize );
1396 [ # # ]: 0 : if ( aTextSz.Height() > aSize.Height() )
1397 : 0 : aClip.Bottom() += aTextSz.Height() - aSize.Height() + 1; // Damit HP-Drucker nicht 'weg-optimieren'
1398 [ # # ]: 0 : pDev->IntersectClipRegion( aClip );
1399 : : }
1400 : :
1401 [ # # ]: 0 : ExtTextEngine aTE;
1402 [ # # ][ # # ]: 0 : aTE.SetText( GetText() );
[ # # ]
1403 [ # # ]: 0 : aTE.SetMaxTextWidth( aSize.Width() );
1404 [ # # ]: 0 : aTE.SetFont( aFont );
1405 [ # # ]: 0 : aTE.SetTextAlign( pImpSvMEdit->GetTextWindow()->GetTextEngine()->GetTextAlign() );
1406 [ # # ]: 0 : aTE.Draw( pDev, Point( aPos.X() + nOffX, aPos.Y() + nOffY ) );
1407 : :
1408 [ # # ][ # # ]: 0 : pDev->Pop();
[ # # ]
1409 : 0 : }
1410 : :
1411 : 144 : long VCLMultiLineEdit::Notify( NotifyEvent& rNEvt )
1412 : : {
1413 : 144 : long nDone = 0;
1414 [ - + ]: 144 : if( rNEvt.GetType() == EVENT_COMMAND )
1415 : : {
1416 : 0 : nDone = pImpSvMEdit->HandleCommand( *rNEvt.GetCommandEvent() );
1417 : : }
1418 [ + - ]: 144 : return nDone ? nDone : Edit::Notify( rNEvt );
1419 : : }
1420 : :
1421 : 0 : long VCLMultiLineEdit::PreNotify( NotifyEvent& rNEvt )
1422 : : {
1423 : 0 : long nDone = 0;
1424 : :
1425 : : #if (OSL_DEBUG_LEVEL > 1) && defined(DBG_UTIL)
1426 : : if( rNEvt.GetType() == EVENT_KEYINPUT )
1427 : : {
1428 : : const KeyEvent& rKEvent = *rNEvt.GetKeyEvent();
1429 : : if ( ( rKEvent.GetKeyCode().GetCode() == KEY_W ) && rKEvent.GetKeyCode().IsMod1() && rKEvent.GetKeyCode().IsMod2() )
1430 : : {
1431 : : SetRightToLeft( !IsRightToLeft() );
1432 : : }
1433 : : }
1434 : : #endif
1435 : :
1436 [ # # ][ # # ]: 0 : if( ( rNEvt.GetType() == EVENT_KEYINPUT ) && ( !GetTextView()->IsCursorEnabled() ) )
[ # # ]
1437 : : {
1438 : 0 : const KeyEvent& rKEvent = *rNEvt.GetKeyEvent();
1439 [ # # ][ # # ]: 0 : if ( !rKEvent.GetKeyCode().IsShift() && ( rKEvent.GetKeyCode().GetGroup() == KEYGROUP_CURSOR ) )
[ # # ]
1440 : : {
1441 : 0 : nDone = 1;
1442 [ # # ]: 0 : TextSelection aSel = pImpSvMEdit->GetTextWindow()->GetTextView()->GetSelection();
1443 [ # # ]: 0 : if ( aSel.HasRange() )
1444 : : {
1445 : 0 : aSel.GetStart() = aSel.GetEnd();
1446 [ # # ]: 0 : pImpSvMEdit->GetTextWindow()->GetTextView()->SetSelection( aSel );
1447 : : }
1448 : : else
1449 : : {
1450 [ # # # # : 0 : switch ( rKEvent.GetKeyCode().GetCode() )
# # # #
# ]
1451 : : {
1452 : : case KEY_UP:
1453 : : {
1454 [ # # ]: 0 : if ( pImpSvMEdit->GetVScrollBar() )
1455 [ # # ]: 0 : pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_LINEUP );
1456 : : }
1457 : 0 : break;
1458 : : case KEY_DOWN:
1459 : : {
1460 [ # # ]: 0 : if ( pImpSvMEdit->GetVScrollBar() )
1461 [ # # ]: 0 : pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_LINEDOWN );
1462 : : }
1463 : 0 : break;
1464 : : case KEY_PAGEUP :
1465 : : {
1466 [ # # ]: 0 : if ( pImpSvMEdit->GetVScrollBar() )
1467 [ # # ]: 0 : pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_PAGEUP );
1468 : : }
1469 : 0 : break;
1470 : : case KEY_PAGEDOWN:
1471 : : {
1472 [ # # ]: 0 : if ( pImpSvMEdit->GetVScrollBar() )
1473 [ # # ]: 0 : pImpSvMEdit->GetVScrollBar()->DoScrollAction( SCROLL_PAGEDOWN );
1474 : : }
1475 : 0 : break;
1476 : : case KEY_LEFT:
1477 : : {
1478 [ # # ]: 0 : if ( pImpSvMEdit->GetHScrollBar() )
1479 [ # # ]: 0 : pImpSvMEdit->GetHScrollBar()->DoScrollAction( SCROLL_LINEUP );
1480 : : }
1481 : 0 : break;
1482 : : case KEY_RIGHT:
1483 : : {
1484 [ # # ]: 0 : if ( pImpSvMEdit->GetHScrollBar() )
1485 [ # # ]: 0 : pImpSvMEdit->GetHScrollBar()->DoScrollAction( SCROLL_LINEDOWN );
1486 : : }
1487 : 0 : break;
1488 : : case KEY_HOME:
1489 : : {
1490 [ # # ]: 0 : if ( rKEvent.GetKeyCode().IsMod1() )
1491 : 0 : pImpSvMEdit->GetTextWindow()->GetTextView()->
1492 [ # # # # ]: 0 : SetSelection( TextSelection( TextPaM( 0, 0 ) ) );
1493 : : }
1494 : 0 : break;
1495 : : case KEY_END:
1496 : : {
1497 [ # # ]: 0 : if ( rKEvent.GetKeyCode().IsMod1() )
1498 : 0 : pImpSvMEdit->GetTextWindow()->GetTextView()->
1499 [ # # # # ]: 0 : SetSelection( TextSelection( TextPaM( 0xFFFF, 0xFFFF ) ) );
1500 : : }
1501 : 0 : break;
1502 : : default:
1503 : : {
1504 : 0 : nDone = 0;
1505 : : }
1506 : : }
1507 : : }
1508 : : }
1509 : : }
1510 : :
1511 [ # # ]: 0 : return nDone ? nDone : Edit::PreNotify( rNEvt );
1512 : : }
1513 : :
1514 : : //
1515 : : // Internas fuer abgeleitete Klassen, z.B. TextComponent
1516 : :
1517 : 0 : ExtTextEngine* VCLMultiLineEdit::GetTextEngine() const
1518 : : {
1519 : 0 : return pImpSvMEdit->GetTextWindow()->GetTextEngine();
1520 : : }
1521 : :
1522 : 0 : ExtTextView* VCLMultiLineEdit::GetTextView() const
1523 : : {
1524 : 0 : return pImpSvMEdit->GetTextWindow()->GetTextView();
1525 : : }
1526 : :
1527 : 0 : ScrollBar* VCLMultiLineEdit::GetVScrollBar() const
1528 : : {
1529 : 0 : return pImpSvMEdit->GetVScrollBar();
1530 : : }
1531 : :
1532 : 26 : void VCLMultiLineEdit::EnableFocusSelectionHide( sal_Bool bHide )
1533 : : {
1534 : 26 : pImpSvMEdit->GetTextWindow()->SetAutoFocusHide( bHide );
1535 : 26 : }
1536 : :
1537 : 0 : void VCLMultiLineEdit::SetLeftMargin( sal_uInt16 n )
1538 : : {
1539 [ # # ]: 0 : if ( GetTextEngine() )
1540 : 0 : GetTextEngine()->SetLeftMargin( n );
1541 : 0 : }
1542 : :
1543 : 0 : void VCLMultiLineEdit::SetRightToLeft( sal_Bool bRightToLeft )
1544 : : {
1545 [ # # ]: 0 : if ( GetTextEngine() )
1546 : : {
1547 : 0 : GetTextEngine()->SetRightToLeft( bRightToLeft );
1548 : 0 : GetTextView()->ShowCursor();
1549 : : }
1550 : 0 : }
1551 : :
1552 : 0 : sal_Bool VCLMultiLineEdit::IsRightToLeft() const
1553 : : {
1554 : 0 : sal_Bool bRightToLeft = sal_False;
1555 : :
1556 [ # # ]: 0 : if ( GetTextEngine() )
1557 : 0 : bRightToLeft = GetTextEngine()->IsRightToLeft();
1558 : :
1559 : 0 : return bRightToLeft;
1560 : : }
1561 : :
1562 : 22 : void VCLMultiLineEdit::DisableSelectionOnFocus()
1563 : : {
1564 : 22 : pImpSvMEdit->GetTextWindow()->DisableSelectionOnFocus();
1565 : 22 : }
1566 : :
1567 : 0 : void VCLMultiLineEdit::SetTextSelectable( sal_Bool bTextSelectable )
1568 : : {
1569 : 0 : pImpSvMEdit->GetTextWindow()->SetTextSelectable( bTextSelectable );
1570 : 0 : }
1571 : :
1572 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|