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