Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "richtextimplcontrol.hxx"
21 : #include "textattributelistener.hxx"
22 : #include "richtextengine.hxx"
23 : #include <editeng/editeng.hxx>
24 : #include <editeng/editview.hxx>
25 : #include <editeng/eeitem.hxx>
26 : #include <editeng/editstat.hxx>
27 : #include <svx/svxids.hrc>
28 : #include <editeng/scripttypeitem.hxx>
29 :
30 : #include <editeng/editobj.hxx>
31 : #include <svl/itempool.hxx>
32 : #include <svl/itemset.hxx>
33 : #include <tools/mapunit.hxx>
34 : #include <vcl/window.hxx>
35 : #include <vcl/svapp.hxx>
36 : #include <vcl/settings.hxx>
37 :
38 : #define EMPTY_PAPER_SIZE 0x7FFFFFFF
39 :
40 :
41 : namespace frm
42 : {
43 :
44 20 : RichTextControlImpl::RichTextControlImpl( Control* _pAntiImpl, RichTextEngine* _pEngine, ITextAttributeListener* _pTextAttrListener, ITextSelectionListener* _pSelectionListener )
45 : :m_pAntiImpl ( _pAntiImpl )
46 : ,m_pViewport ( NULL )
47 : ,m_pHScroll ( NULL )
48 : ,m_pVScroll ( NULL )
49 : ,m_pScrollCorner ( NULL )
50 : ,m_pEngine ( _pEngine )
51 : ,m_pView ( NULL )
52 : ,m_pTextAttrListener ( _pTextAttrListener )
53 : ,m_pSelectionListener ( _pSelectionListener )
54 20 : ,m_bHasEverBeenShown ( false )
55 : {
56 : OSL_ENSURE( m_pAntiImpl, "RichTextControlImpl::RichTextControlImpl: invalid window!" );
57 : OSL_ENSURE( m_pEngine, "RichTextControlImpl::RichTextControlImpl: invalid edit engine! This will *definitely* crash!" );
58 :
59 20 : m_pViewport = VclPtr<RichTextViewPort>::Create( m_pAntiImpl );
60 20 : m_pViewport->setAttributeInvalidationHandler( LINK( this, RichTextControlImpl, OnInvalidateAllAttributes ) );
61 20 : m_pViewport->Show();
62 :
63 : // ensure that both the window and the reference device have the same map unit
64 20 : MapMode aRefDeviceMapMode( m_pEngine->GetRefDevice()->GetMapMode() );
65 20 : m_pAntiImpl->SetMapMode( aRefDeviceMapMode );
66 20 : m_pViewport->SetMapMode( aRefDeviceMapMode );
67 :
68 20 : m_pView = new EditView( m_pEngine, m_pViewport );
69 20 : m_pEngine->InsertView( m_pView );
70 20 : m_pViewport->setView( *m_pView );
71 :
72 20 : m_pEngine->registerEngineStatusListener( this );
73 :
74 : {
75 20 : EVControlBits nViewControlWord = m_pView->GetControlWord();
76 20 : nViewControlWord |= EVControlBits::AUTOSCROLL;
77 20 : m_pView->SetControlWord( nViewControlWord );
78 : }
79 :
80 : // ensure that it's initially scrolled to the upper left
81 20 : m_pView->SetVisArea( Rectangle( Point( ), m_pViewport->GetOutputSize() ) );
82 :
83 20 : ensureScrollbars();
84 :
85 20 : m_pAntiImpl->SetBackground( Wallpaper( m_pAntiImpl->GetSettings().GetStyleSettings().GetFieldColor() ) );
86 20 : }
87 :
88 :
89 60 : RichTextControlImpl::~RichTextControlImpl( )
90 : {
91 20 : m_pEngine->RemoveView( m_pView );
92 20 : m_pEngine->revokeEngineStatusListener( this );
93 20 : delete m_pView;
94 20 : m_pViewport.disposeAndClear();
95 20 : m_pHScroll.disposeAndClear();
96 20 : m_pVScroll.disposeAndClear();
97 20 : m_pScrollCorner.disposeAndClear();
98 40 : }
99 :
100 :
101 0 : void RichTextControlImpl::implUpdateAttribute( AttributeHandlerPool::const_iterator _pHandler )
102 : {
103 0 : if ( ( _pHandler->first == SID_ATTR_CHAR_WEIGHT )
104 0 : || ( _pHandler->first == SID_ATTR_CHAR_POSTURE )
105 0 : || ( _pHandler->first == SID_ATTR_CHAR_FONT )
106 0 : || ( _pHandler->first == SID_ATTR_CHAR_FONTHEIGHT )
107 : )
108 : {
109 : // these are attributes whose value depends on the current script type.
110 : // I.e., in real, there are *three* items in the ItemSet: One for each script
111 : // type (Latin, Asian, Complex). However, if we have an observer who is interested
112 : // in the state of this attribute, we have to kind of *merge* the three attributes
113 : // to only one.
114 : // This is useful in case the observer is for instance a toolbox which contains only
115 : // an, e.g., "bold" slot, and thus not interested in the particular script type of the
116 : // current selection.
117 0 : SvxScriptSetItem aNormalizedSet( (WhichId)_pHandler->first, *m_pView->GetAttribs().GetPool() );
118 0 : normalizeScriptDependentAttribute( aNormalizedSet );
119 :
120 0 : implCheckUpdateCache( _pHandler->first, _pHandler->second->getState( aNormalizedSet.GetItemSet() ) );
121 : }
122 : else
123 0 : implCheckUpdateCache( _pHandler->first, _pHandler->second->getState( m_pView->GetAttribs() ) );
124 0 : }
125 :
126 :
127 0 : void RichTextControlImpl::updateAttribute( AttributeId _nAttribute )
128 : {
129 0 : AttributeHandlerPool::const_iterator pHandler = m_aAttributeHandlers.find( _nAttribute );
130 0 : if ( pHandler != m_aAttributeHandlers.end() )
131 0 : implUpdateAttribute( pHandler );
132 0 : }
133 :
134 :
135 0 : void RichTextControlImpl::updateAllAttributes( )
136 : {
137 0 : for ( AttributeHandlerPool::const_iterator pHandler = m_aAttributeHandlers.begin();
138 0 : pHandler != m_aAttributeHandlers.end();
139 : ++pHandler
140 : )
141 : {
142 0 : implUpdateAttribute( pHandler );
143 : }
144 :
145 : // notify changes of the selection, if necessary
146 0 : if ( m_pSelectionListener && m_pView )
147 : {
148 0 : ESelection aCurrentSelection = m_pView->GetSelection();
149 0 : if ( !aCurrentSelection.IsEqual( m_aLastKnownSelection ) )
150 : {
151 0 : m_aLastKnownSelection = aCurrentSelection;
152 0 : m_pSelectionListener->onSelectionChanged( m_aLastKnownSelection );
153 : }
154 : }
155 0 : }
156 :
157 :
158 0 : AttributeState RichTextControlImpl::getAttributeState( AttributeId _nAttributeId ) const
159 : {
160 0 : StateCache::const_iterator aCachedStatePos = m_aLastKnownStates.find( _nAttributeId );
161 0 : if ( aCachedStatePos == m_aLastKnownStates.end() )
162 : {
163 : OSL_FAIL( "RichTextControlImpl::getAttributeState: Don't ask for the state of an attribute which I never encountered!" );
164 0 : return AttributeState( eIndetermined );
165 : }
166 0 : return aCachedStatePos->second;
167 : }
168 :
169 :
170 0 : bool RichTextControlImpl::executeAttribute( const SfxItemSet& _rCurrentAttribs, SfxItemSet& _rAttribs, AttributeId _nAttribute, const SfxPoolItem* _pArgument, SvtScriptType _nForScriptType )
171 : {
172 : // let's see whether we have a handler for this attribute
173 0 : AttributeHandlerPool::const_iterator aHandlerPos = m_aAttributeHandlers.find( _nAttribute );
174 0 : if ( aHandlerPos != m_aAttributeHandlers.end() )
175 : {
176 0 : aHandlerPos->second->executeAttribute( _rCurrentAttribs, _rAttribs, _pArgument, _nForScriptType );
177 0 : return true;
178 : }
179 0 : return false;
180 : }
181 :
182 :
183 0 : void RichTextControlImpl::enableAttributeNotification( AttributeId _nAttributeId, ITextAttributeListener* _pListener )
184 : {
185 0 : AttributeHandlerPool::const_iterator aHandlerPos = m_aAttributeHandlers.find( _nAttributeId );
186 0 : if ( aHandlerPos == m_aAttributeHandlers.end() )
187 : {
188 0 : ::rtl::Reference< IAttributeHandler > aHandler = AttributeHandlerFactory::getHandlerFor( _nAttributeId, *m_pEngine->GetEmptyItemSet().GetPool() );
189 : OSL_ENSURE( aHandler.is(), "RichTextControlImpl::enableAttributeNotification: no handler available for this attribute!" );
190 0 : if ( !aHandler.is() )
191 0 : return;
192 : SAL_WARN_IF( _nAttributeId != aHandler->getAttributeId(), "forms.richtext", "RichTextControlImpl::enableAttributeNotification: suspicious handler!" );
193 :
194 0 : aHandlerPos = m_aAttributeHandlers.insert( AttributeHandlerPool::value_type( _nAttributeId , aHandler ) ).first;
195 : }
196 :
197 : // remember the listener
198 0 : if ( _pListener )
199 0 : m_aAttributeListeners.insert( AttributeListenerPool::value_type( _nAttributeId, _pListener ) );
200 :
201 : // update (and broadcast) the state of this attribute
202 0 : updateAttribute( _nAttributeId );
203 : }
204 :
205 :
206 0 : void RichTextControlImpl::disableAttributeNotification( AttributeId _nAttributeId )
207 : {
208 : // forget the handler for this attribute
209 0 : AttributeHandlerPool::iterator aHandlerPos = m_aAttributeHandlers.find( _nAttributeId );
210 0 : if ( aHandlerPos != m_aAttributeHandlers.end() )
211 0 : m_aAttributeHandlers.erase( aHandlerPos );
212 :
213 : // as well as the listener
214 0 : AttributeListenerPool::iterator aListenerPos = m_aAttributeListeners.find( _nAttributeId );
215 0 : if ( aListenerPos != m_aAttributeListeners.end() )
216 0 : m_aAttributeListeners.erase( aListenerPos );
217 0 : }
218 :
219 :
220 0 : void RichTextControlImpl::normalizeScriptDependentAttribute( SvxScriptSetItem& _rScriptSetItem )
221 : {
222 0 : _rScriptSetItem.GetItemSet().Put( m_pView->GetAttribs(), false );
223 0 : const SfxPoolItem* pNormalizedItem = _rScriptSetItem.GetItemOfScript( getSelectedScriptType() );
224 :
225 0 : WhichId nNormalizedWhichId = _rScriptSetItem.GetItemSet().GetPool()->GetWhich( _rScriptSetItem.Which() );
226 0 : if ( pNormalizedItem )
227 : {
228 0 : SfxPoolItem* pProperWhich = pNormalizedItem->Clone();
229 0 : pProperWhich->SetWhich( nNormalizedWhichId );
230 0 : _rScriptSetItem.GetItemSet().Put( *pProperWhich );
231 0 : DELETEZ( pProperWhich );
232 : }
233 : else
234 0 : _rScriptSetItem.GetItemSet().InvalidateItem( nNormalizedWhichId );
235 0 : }
236 :
237 :
238 0 : void RichTextControlImpl::implCheckUpdateCache( AttributeId _nAttribute, const AttributeState& _rState )
239 : {
240 0 : StateCache::iterator aCachePos = m_aLastKnownStates.find( _nAttribute );
241 0 : if ( aCachePos == m_aLastKnownStates.end() )
242 : { // nothing known about this attribute, yet
243 0 : m_aLastKnownStates.insert( StateCache::value_type( _nAttribute, _rState ) );
244 : }
245 : else
246 : {
247 0 : if ( aCachePos->second == _rState )
248 : {
249 : // nothing to do
250 0 : return;
251 : }
252 0 : aCachePos->second = _rState;
253 : }
254 :
255 : // is there a dedicated listener for this particular attribute?
256 0 : AttributeListenerPool::const_iterator aListenerPos = m_aAttributeListeners.find( _nAttribute );
257 0 : if ( aListenerPos != m_aAttributeListeners.end( ) )
258 0 : aListenerPos->second->onAttributeStateChanged( _nAttribute, _rState );
259 :
260 : // call our global listener, if there is one
261 0 : if ( m_pTextAttrListener )
262 0 : m_pTextAttrListener->onAttributeStateChanged( _nAttribute, _rState );
263 : }
264 :
265 :
266 0 : SvtScriptType RichTextControlImpl::getSelectedScriptType() const
267 : {
268 0 : SvtScriptType nScript = m_pView->GetSelectedScriptType();
269 0 : if ( nScript == SvtScriptType::NONE )
270 0 : nScript = SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
271 0 : return nScript;
272 : }
273 :
274 :
275 0 : void RichTextControlImpl::EditEngineStatusChanged( const EditStatus& _rStatus )
276 : {
277 0 : EditStatusFlags nStatusWord( _rStatus.GetStatusWord() );
278 0 : if ( ( nStatusWord & EditStatusFlags::TEXTWIDTHCHANGED )
279 0 : || ( nStatusWord & EditStatusFlags::TEXTHEIGHTCHANGED )
280 : )
281 : {
282 0 : if ( ( nStatusWord & EditStatusFlags::TEXTHEIGHTCHANGED ) && windowHasAutomaticLineBreak() )
283 0 : m_pEngine->SetPaperSize( Size( m_pEngine->GetPaperSize().Width(), m_pEngine->GetTextHeight() ) );
284 :
285 0 : updateScrollbars();
286 : }
287 :
288 0 : bool bHScroll = bool( nStatusWord & EditStatusFlags::HSCROLL );
289 0 : bool bVScroll = bool( nStatusWord & EditStatusFlags::VSCROLL );
290 :
291 : // In case of *no* automatic line breaks, we also need to check for the *range* here.
292 : // Normally, we would do this only after a EditStatusFlags::TEXTWIDTHCHANGED. However, due to a bug
293 : // in the EditEngine (I believe so) this is not fired when the engine does not have
294 : // the AutoPaperSize bits set.
295 : // So in order to be properly notified, we would need the AutoPaperSize. But, with
296 : // AutoPaperSize, other things do not work anymore: Either, when we set a MaxAutoPaperSize,
297 : // then the view does automatic soft line breaks at the paper end - which we definitely do
298 : // want. Or, if we did not set a MaxAutoPaperSize, then the view does not automatically scroll
299 : // anymore in horizontal direction.
300 : // So this is some kind of lose-lose situation ... :(
301 0 : if ( !windowHasAutomaticLineBreak() && bHScroll )
302 : {
303 0 : updateScrollbars();
304 0 : return;
305 : }
306 :
307 0 : if ( bHScroll && m_pHScroll )
308 0 : m_pHScroll->SetThumbPos( m_pView->GetVisArea().Left() );
309 0 : if ( bVScroll && m_pVScroll )
310 0 : m_pVScroll->SetThumbPos( m_pView->GetVisArea().Top() );
311 : }
312 :
313 :
314 0 : IMPL_LINK_NOARG( RichTextControlImpl, OnInvalidateAllAttributes )
315 : {
316 0 : updateAllAttributes();
317 0 : return 0L;
318 : }
319 :
320 :
321 0 : IMPL_LINK( RichTextControlImpl, OnHScroll, ScrollBar*, _pScrollbar )
322 : {
323 0 : m_pView->Scroll( -_pScrollbar->GetDelta(), 0, RGCHK_PAPERSZ1 );
324 0 : return 0L;
325 : }
326 :
327 :
328 0 : IMPL_LINK( RichTextControlImpl, OnVScroll, ScrollBar*, _pScrollbar )
329 : {
330 0 : m_pView->Scroll( 0, -_pScrollbar->GetDelta(), RGCHK_PAPERSZ1 );
331 0 : return 0L;
332 : }
333 :
334 :
335 64 : void RichTextControlImpl::ensureScrollbars()
336 : {
337 64 : bool bNeedVScroll = 0 != ( m_pAntiImpl->GetStyle() & WB_VSCROLL );
338 64 : bool bNeedHScroll = 0 != ( m_pAntiImpl->GetStyle() & WB_HSCROLL );
339 :
340 64 : if ( ( bNeedVScroll == hasVScrollBar() ) && ( bNeedHScroll == hasHScrollBar( ) ) )
341 : // nothing to do
342 113 : return;
343 :
344 : // create or delete the scrollbars, as necessary
345 15 : if ( !bNeedVScroll )
346 : {
347 5 : m_pVScroll.disposeAndClear();
348 : }
349 : else
350 : {
351 10 : m_pVScroll = VclPtr<ScrollBar>::Create( m_pAntiImpl, WB_VSCROLL | WB_DRAG | WB_REPEAT );
352 10 : m_pVScroll->SetScrollHdl ( LINK( this, RichTextControlImpl, OnVScroll ) );
353 10 : m_pVScroll->Show();
354 : }
355 :
356 15 : if ( !bNeedHScroll )
357 : {
358 6 : m_pHScroll.disposeAndClear();
359 : }
360 : else
361 : {
362 9 : m_pHScroll = VclPtr<ScrollBar>::Create( m_pAntiImpl, WB_HSCROLL | WB_DRAG | WB_REPEAT );
363 9 : m_pHScroll->SetScrollHdl ( LINK( this, RichTextControlImpl, OnHScroll ) );
364 9 : m_pHScroll->Show();
365 : }
366 :
367 15 : if ( m_pHScroll && m_pVScroll )
368 : {
369 4 : m_pScrollCorner.disposeAndClear();
370 4 : m_pScrollCorner = VclPtr<ScrollBarBox>::Create( m_pAntiImpl );
371 4 : m_pScrollCorner->Show();
372 : }
373 : else
374 : {
375 11 : m_pScrollCorner.disposeAndClear();
376 : }
377 :
378 15 : layoutWindow();
379 : }
380 :
381 :
382 44 : void RichTextControlImpl::ensureLineBreakSetting()
383 : {
384 44 : if ( !windowHasAutomaticLineBreak() )
385 22 : m_pEngine->SetPaperSize( Size( EMPTY_PAPER_SIZE, EMPTY_PAPER_SIZE ) );
386 :
387 44 : layoutWindow();
388 44 : }
389 :
390 :
391 59 : void RichTextControlImpl::layoutWindow()
392 : {
393 59 : if ( !m_bHasEverBeenShown )
394 : // no need to do anything. Especially, no need to set the paper size on the
395 : // EditEngine to anything ....
396 118 : return;
397 :
398 0 : const StyleSettings& rStyleSettings = m_pAntiImpl->GetSettings().GetStyleSettings();
399 :
400 0 : long nScrollBarWidth = m_pVScroll ? rStyleSettings.GetScrollBarSize() : 0;
401 0 : long nScrollBarHeight = m_pHScroll ? rStyleSettings.GetScrollBarSize() : 0;
402 :
403 0 : if ( m_pAntiImpl->IsZoom() )
404 : {
405 0 : nScrollBarWidth = m_pAntiImpl->CalcZoom( nScrollBarWidth );
406 0 : nScrollBarHeight = m_pAntiImpl->CalcZoom( nScrollBarHeight );
407 : }
408 :
409 : // the overall size we can use
410 0 : Size aPlaygroundSizePixel( m_pAntiImpl->GetOutputSizePixel() );
411 :
412 : // the size of the viewport - note that the viewport does *not* occupy all the place
413 : // which is left when subtracting the scrollbar width/height
414 0 : Size aViewportPlaygroundPixel( aPlaygroundSizePixel );
415 0 : aViewportPlaygroundPixel.Width() = ::std::max( long( 10 ), long( aViewportPlaygroundPixel.Width() - nScrollBarWidth ) );
416 0 : aViewportPlaygroundPixel.Height() = ::std::max( long( 10 ), long( aViewportPlaygroundPixel.Height() - nScrollBarHeight ) );
417 0 : Size aViewportPlaygroundLogic( m_pViewport->PixelToLogic( aViewportPlaygroundPixel ) );
418 :
419 0 : const long nOffset = 2;
420 0 : Size aViewportSizePixel( aViewportPlaygroundPixel.Width() - 2 * nOffset, aViewportPlaygroundPixel.Height() - 2 * nOffset );
421 0 : Size aViewportSizeLogic( m_pViewport->PixelToLogic( aViewportSizePixel ) );
422 :
423 : // position the viewport
424 0 : m_pViewport->SetPosSizePixel( Point( nOffset, nOffset ), aViewportSizePixel );
425 : // position the scrollbars
426 0 : if ( m_pVScroll )
427 0 : m_pVScroll->SetPosSizePixel( Point( aViewportPlaygroundPixel.Width(), 0 ), Size( nScrollBarWidth, aViewportPlaygroundPixel.Height() ) );
428 0 : if ( m_pHScroll )
429 0 : m_pHScroll->SetPosSizePixel( Point( 0, aViewportPlaygroundPixel.Height() ), Size( aViewportPlaygroundPixel.Width(), nScrollBarHeight ) );
430 0 : if ( m_pScrollCorner )
431 0 : m_pScrollCorner->SetPosSizePixel( Point( aViewportPlaygroundPixel.Width(), aViewportPlaygroundPixel.Height() ), Size( nScrollBarWidth, nScrollBarHeight ) );
432 :
433 : // paper size
434 0 : if ( windowHasAutomaticLineBreak() )
435 0 : m_pEngine->SetPaperSize( Size( aViewportSizeLogic.Width(), m_pEngine->GetTextHeight() ) );
436 :
437 : // output area of the view
438 0 : m_pView->SetOutputArea( Rectangle( Point( ), aViewportSizeLogic ) );
439 0 : m_pView->SetVisArea( Rectangle( Point( ), aViewportSizeLogic ) );
440 :
441 0 : if ( m_pVScroll )
442 : {
443 0 : m_pVScroll->SetVisibleSize( aViewportPlaygroundLogic.Height() );
444 :
445 : // the default height of a text line ....
446 0 : long nFontHeight = m_pEngine->GetStandardFont(0).GetSize().Height();
447 : // ... is the scroll size for the vertical scrollbar
448 0 : m_pVScroll->SetLineSize( nFontHeight );
449 : // the viewport width, minus one line, is the page scroll size
450 0 : m_pVScroll->SetPageSize( ::std::max( nFontHeight, aViewportPlaygroundLogic.Height() - nFontHeight ) );
451 : }
452 :
453 : // the font width
454 0 : if ( m_pHScroll )
455 : {
456 0 : m_pHScroll->SetVisibleSize( aViewportPlaygroundLogic.Width() );
457 :
458 0 : long nFontWidth = m_pEngine->GetStandardFont(0).GetSize().Width();
459 0 : if ( !nFontWidth )
460 : {
461 0 : m_pViewport->Push( PushFlags::FONT );
462 0 : m_pViewport->SetFont( m_pEngine->GetStandardFont(0) );
463 0 : nFontWidth = m_pViewport->GetTextWidth( "x" );
464 0 : m_pViewport->Pop();
465 : }
466 : // ... is the scroll size for the horizontal scrollbar
467 0 : m_pHScroll->SetLineSize( 5 * nFontWidth );
468 : // the viewport height, minus one character, is the page scroll size
469 0 : m_pHScroll->SetPageSize( ::std::max( nFontWidth, aViewportPlaygroundLogic.Width() - nFontWidth ) );
470 : }
471 :
472 : // update range and position of the scrollbars
473 0 : updateScrollbars();
474 : }
475 :
476 :
477 0 : void RichTextControlImpl::updateScrollbars()
478 : {
479 0 : if ( m_pVScroll )
480 : {
481 0 : long nOverallTextHeight = m_pEngine->GetTextHeight();
482 0 : m_pVScroll->SetRange( Range( 0, nOverallTextHeight ) );
483 0 : m_pVScroll->SetThumbPos( m_pView->GetVisArea().Top() );
484 : }
485 :
486 0 : if ( m_pHScroll )
487 : {
488 0 : Size aPaperSize( m_pEngine->GetPaperSize() );
489 0 : long nOverallTextWidth = ( aPaperSize.Width() == EMPTY_PAPER_SIZE ) ? m_pEngine->CalcTextWidth() : aPaperSize.Width();
490 0 : m_pHScroll->SetRange( Range( 0, nOverallTextWidth ) );
491 0 : m_pHScroll->SetThumbPos( m_pView->GetVisArea().Left() );
492 : }
493 0 : }
494 :
495 :
496 0 : void RichTextControlImpl::notifyInitShow()
497 : {
498 0 : if ( !m_bHasEverBeenShown )
499 : {
500 0 : m_bHasEverBeenShown = true;
501 0 : layoutWindow();
502 : }
503 0 : }
504 :
505 :
506 44 : void RichTextControlImpl::notifyStyleChanged()
507 : {
508 44 : ensureScrollbars();
509 44 : ensureLineBreakSetting();
510 44 : }
511 :
512 :
513 0 : void RichTextControlImpl::notifyZoomChanged()
514 : {
515 0 : const Fraction& rZoom = m_pAntiImpl->GetZoom();
516 :
517 0 : MapMode aMapMode( m_pAntiImpl->GetMapMode() );
518 0 : aMapMode.SetScaleX( rZoom );
519 0 : aMapMode.SetScaleY( rZoom );
520 0 : m_pAntiImpl->SetMapMode( aMapMode );
521 :
522 0 : m_pViewport->SetZoom( rZoom );
523 0 : m_pViewport->SetMapMode( aMapMode );
524 :
525 0 : layoutWindow();
526 0 : }
527 :
528 :
529 44 : bool RichTextControlImpl::windowHasAutomaticLineBreak()
530 : {
531 44 : return ( m_pAntiImpl->GetStyle() & WB_WORDBREAK ) != 0;
532 : }
533 :
534 :
535 24 : void RichTextControlImpl::SetReadOnly( bool _bReadOnly )
536 : {
537 24 : m_pView->SetReadOnly( _bReadOnly );
538 24 : }
539 :
540 :
541 24 : bool RichTextControlImpl::IsReadOnly() const
542 : {
543 24 : return m_pView->IsReadOnly( );
544 : }
545 :
546 :
547 : namespace
548 : {
549 399 : static void lcl_inflate( Rectangle& _rRect, long _nInflateX, long _nInflateY )
550 : {
551 399 : _rRect.Left() -= _nInflateX;
552 399 : _rRect.Right() += _nInflateX;
553 399 : _rRect.Top() -= _nInflateY;
554 399 : _rRect.Bottom() += _nInflateY;
555 399 : }
556 : }
557 :
558 0 : long RichTextControlImpl::HandleCommand( const CommandEvent& _rEvent )
559 : {
560 0 : if ( ( _rEvent.GetCommand() == CommandEventId::Wheel )
561 0 : || ( _rEvent.GetCommand() == CommandEventId::StartAutoScroll )
562 0 : || ( _rEvent.GetCommand() == CommandEventId::AutoScroll )
563 : )
564 : {
565 0 : m_pAntiImpl->HandleScrollCommand( _rEvent, m_pHScroll, m_pVScroll );
566 0 : return 1;
567 : }
568 0 : return 0;
569 : }
570 :
571 :
572 133 : void RichTextControlImpl::Draw( OutputDevice* _pDev, const Point& _rPos, const Size& _rSize, DrawFlags /*_nFlags*/ )
573 : {
574 : // need to normalize the map mode of the device - every paint operation on any device needs
575 : // to use the same map mode
576 133 : _pDev->Push( PushFlags::MAPMODE | PushFlags::LINECOLOR | PushFlags::FILLCOLOR );
577 :
578 : // enforce our "normalize map mode" on the device
579 133 : MapMode aRefMapMode( m_pEngine->GetRefDevice()->GetMapMode() );
580 266 : MapMode aOriginalMapMode( _pDev->GetMapMode() );
581 266 : MapMode aNormalizedMapMode( aRefMapMode.GetMapUnit(), aRefMapMode.GetOrigin(), aOriginalMapMode.GetScaleX(), aOriginalMapMode.GetScaleY() );
582 133 : _pDev->SetMapMode( aNormalizedMapMode );
583 :
584 : // translate coordinates
585 133 : Point aPos( _rPos );
586 133 : Size aSize( _rSize );
587 133 : if ( aOriginalMapMode.GetMapUnit() == MAP_PIXEL )
588 : {
589 133 : aPos = _pDev->PixelToLogic( _rPos, aNormalizedMapMode );
590 133 : aSize = _pDev->PixelToLogic( _rSize, aNormalizedMapMode );
591 : }
592 : else
593 : {
594 0 : aPos = OutputDevice::LogicToLogic( _rPos, aOriginalMapMode, aNormalizedMapMode );
595 0 : aSize = OutputDevice::LogicToLogic( _rSize, aOriginalMapMode, aNormalizedMapMode );
596 : }
597 :
598 133 : Rectangle aPlayground( aPos, aSize );
599 133 : Size aOnePixel( _pDev->PixelToLogic( Size( 1, 1 ) ) );
600 133 : aPlayground.Right() -= aOnePixel.Width();
601 133 : aPlayground.Bottom() -= aOnePixel.Height();
602 :
603 : // background
604 133 : _pDev->SetLineColor();
605 133 : _pDev->DrawRect( aPlayground );
606 :
607 : // do we need to draw a border?
608 133 : bool bBorder = ( m_pAntiImpl->GetStyle() & WB_BORDER );
609 133 : if ( bBorder )
610 133 : _pDev->SetLineColor( m_pAntiImpl->GetSettings().GetStyleSettings().GetMonoColor() );
611 : else
612 0 : _pDev->SetLineColor();
613 133 : _pDev->SetFillColor( m_pAntiImpl->GetBackground().GetColor() );
614 133 : _pDev->DrawRect( aPlayground );
615 :
616 133 : if ( bBorder )
617 : // don't draw the text over the border
618 133 : lcl_inflate( aPlayground, -aOnePixel.Width(), -aOnePixel.Height() );
619 :
620 : // leave a space of two pixels between the "surroundings" of the control
621 : // and the content
622 133 : lcl_inflate( aPlayground, -aOnePixel.Width(), -aOnePixel.Height() );
623 133 : lcl_inflate( aPlayground, -aOnePixel.Width(), -aOnePixel.Height() );
624 :
625 : // actually draw the content
626 133 : m_pEngine->Draw( _pDev, aPlayground, Point(), true );
627 :
628 266 : _pDev->Pop();
629 133 : }
630 :
631 :
632 20 : void RichTextControlImpl::SetBackgroundColor( )
633 : {
634 20 : SetBackgroundColor( Application::GetSettings().GetStyleSettings().GetFieldColor() );
635 20 : }
636 :
637 :
638 20 : void RichTextControlImpl::SetBackgroundColor( const Color& _rColor )
639 : {
640 20 : Wallpaper aWallpaper( _rColor );
641 20 : m_pAntiImpl->SetBackground( aWallpaper );
642 20 : m_pViewport->SetBackground( aWallpaper );
643 20 : }
644 :
645 :
646 24 : void RichTextControlImpl::SetHideInactiveSelection( bool _bHide )
647 : {
648 24 : m_pViewport->SetHideInactiveSelection( _bHide );
649 24 : }
650 :
651 :
652 24 : bool RichTextControlImpl::GetHideInactiveSelection() const
653 : {
654 24 : return m_pViewport->GetHideInactiveSelection( );
655 : }
656 :
657 :
658 : } // namespace frm
659 :
660 :
661 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|