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 "richtextvclcontrol.hxx"
30 : : #include "richtextimplcontrol.hxx"
31 : : #include <svl/itempool.hxx>
32 : : #include <svl/itemset.hxx>
33 : : #include <svl/languageoptions.hxx>
34 : : #if OSL_DEBUG_LEVEL > 0
35 : : #include <unotools/ucbstreamhelper.hxx>
36 : : #include <vcl/msgbox.hxx>
37 : : #include <sfx2/filedlghelper.hxx>
38 : : #include <tools/urlobj.hxx>
39 : : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
40 : : #endif
41 : : #include <editeng/scripttypeitem.hxx>
42 : : #include <editeng/editeng.hxx>
43 : : #include <editeng/editview.hxx>
44 : : #include <editeng/eeitem.hxx>
45 : : #include <editeng/fontitem.hxx>
46 : : #include <editeng/fhgtitem.hxx>
47 : : #include <editeng/editids.hrc>
48 : : #include <svx/svxids.hrc>
49 : : #include <memory>
50 : :
51 : : //........................................................................
52 : : namespace frm
53 : : {
54 : : //........................................................................
55 : :
56 : : using namespace ::com::sun::star::awt;
57 : :
58 : : //====================================================================
59 : : //= RichTextControl
60 : : //====================================================================
61 : : //--------------------------------------------------------------------
62 : 40 : RichTextControl::RichTextControl( RichTextEngine* _pEngine, Window* _pParent, WinBits _nStyle,
63 : : ITextAttributeListener* _pTextAttribListener, ITextSelectionListener* _pSelectionListener )
64 : : :Control( _pParent, implInitStyle( _nStyle ) )
65 : 40 : ,m_pImpl( NULL )
66 : : {
67 [ + - ]: 40 : implInit( _pEngine, _pTextAttribListener, _pSelectionListener );
68 : 40 : }
69 : :
70 : : //--------------------------------------------------------------------
71 : 40 : void RichTextControl::implInit( RichTextEngine* _pEngine, ITextAttributeListener* _pTextAttribListener, ITextSelectionListener* _pSelectionListener )
72 : : {
73 [ + - ]: 40 : m_pImpl = new RichTextControlImpl( this, _pEngine, _pTextAttribListener, _pSelectionListener );
74 : 40 : SetCompoundControl( sal_True );
75 : 40 : }
76 : :
77 : : //--------------------------------------------------------------------
78 : 40 : RichTextControl::~RichTextControl( )
79 : : {
80 [ + - ][ + - ]: 40 : delete m_pImpl;
81 [ - + ]: 80 : }
82 : :
83 : : //--------------------------------------------------------------------
84 : 0 : AttributeState RichTextControl::getState( AttributeId _nAttributeId ) const
85 : : {
86 : 0 : return m_pImpl->getAttributeState( _nAttributeId );
87 : : }
88 : :
89 : : //--------------------------------------------------------------------
90 : 0 : void RichTextControl::executeAttribute( AttributeId _nAttributeId, const SfxPoolItem* _pArgument )
91 : : {
92 [ # # ][ # # ]: 0 : SfxItemSet aToApplyAttributes( getView().GetEmptyItemSet() );
93 [ # # ][ # # ]: 0 : if ( !m_pImpl->executeAttribute( getView().GetAttribs(), aToApplyAttributes, _nAttributeId, _pArgument, m_pImpl->getSelectedScriptType() ) )
[ # # ][ # # ]
[ # # ]
94 : : {
95 : : OSL_FAIL( "RichTextControl::executeAttribute: cannot handle the given attribute!" );
96 : 0 : return;
97 : : }
98 : :
99 [ # # ][ # # ]: 0 : applyAttributes( aToApplyAttributes );
[ # # ]
100 : : }
101 : :
102 : : //--------------------------------------------------------------------
103 : 0 : void RichTextControl::applyAttributes( const SfxItemSet& _rAttributesToApply )
104 : : {
105 : : // apply
106 [ # # ]: 0 : if ( HasChildPathFocus() )
107 : 0 : getView().HideCursor();
108 : :
109 : 0 : sal_Bool bOldUpdateMode = getEngine().GetUpdateMode(); // TODO: guard?
110 : 0 : getEngine().SetUpdateMode( sal_False );
111 : :
112 : 0 : getView().SetAttribs( _rAttributesToApply );
113 : :
114 : 0 : getEngine().SetUpdateMode( bOldUpdateMode );
115 : 0 : getView().Invalidate();
116 : :
117 [ # # ]: 0 : if ( HasChildPathFocus() )
118 : 0 : getView().ShowCursor();
119 : :
120 : 0 : m_pImpl->updateAllAttributes();
121 : : // TODO: maybe we should have a list of attributes which need to be updated
122 : : // (the handler for the just executed attribute should know)
123 : 0 : }
124 : :
125 : : //--------------------------------------------------------------------
126 : 0 : void RichTextControl::enableAttributeNotification( AttributeId _nAttributeId, ITextAttributeListener* _pListener )
127 : : {
128 : 0 : m_pImpl->enableAttributeNotification( _nAttributeId, _pListener );
129 : 0 : }
130 : :
131 : : //--------------------------------------------------------------------
132 : 0 : void RichTextControl::disableAttributeNotification( AttributeId _nAttributeId )
133 : : {
134 : 0 : m_pImpl->disableAttributeNotification( _nAttributeId );
135 : 0 : }
136 : :
137 : : //--------------------------------------------------------------------
138 : 0 : bool RichTextControl::isMappableSlot( SfxSlotId _nSlotId )
139 : : {
140 [ # # ]: 0 : switch ( _nSlotId )
141 : : {
142 : : case SID_ATTR_PARA_ADJUST_LEFT:
143 : : case SID_ATTR_PARA_ADJUST_CENTER:
144 : : case SID_ATTR_PARA_ADJUST_RIGHT:
145 : : case SID_ATTR_PARA_ADJUST_BLOCK:
146 : : case SID_SET_SUPER_SCRIPT:
147 : : case SID_SET_SUB_SCRIPT:
148 : : case SID_ATTR_PARA_LINESPACE_10:
149 : : case SID_ATTR_PARA_LINESPACE_15:
150 : : case SID_ATTR_PARA_LINESPACE_20:
151 : : case SID_ATTR_PARA_LEFT_TO_RIGHT:
152 : : case SID_ATTR_PARA_RIGHT_TO_LEFT:
153 : : case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
154 : : case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
155 : : case SID_ATTR_CHAR_LATIN_FONT:
156 : : case SID_ATTR_CHAR_LATIN_FONTHEIGHT:
157 : : case SID_ATTR_CHAR_LATIN_LANGUAGE:
158 : : case SID_ATTR_CHAR_LATIN_POSTURE:
159 : : case SID_ATTR_CHAR_LATIN_WEIGHT:
160 : 0 : return true;
161 : : }
162 : 0 : return false;
163 : : }
164 : :
165 : : //--------------------------------------------------------------------
166 : 0 : void RichTextControl::Resize()
167 : : {
168 : 0 : m_pImpl->layoutWindow();
169 : 0 : Invalidate();
170 : 0 : }
171 : :
172 : : //--------------------------------------------------------------------
173 : 0 : void RichTextControl::GetFocus()
174 : : {
175 : 0 : getViewport().GrabFocus();
176 : 0 : }
177 : :
178 : : //--------------------------------------------------------------------
179 : 128 : WinBits RichTextControl::implInitStyle( WinBits nStyle )
180 : : {
181 [ + - ]: 128 : if ( !( nStyle & WB_NOTABSTOP ) )
182 : 128 : nStyle |= WB_TABSTOP;
183 : 128 : return nStyle;
184 : : }
185 : :
186 : : //--------------------------------------------------------------------
187 : 432 : void RichTextControl::StateChanged( StateChangedType _nStateChange )
188 : : {
189 [ + + ]: 432 : if ( _nStateChange == STATE_CHANGE_STYLE )
190 : : {
191 : 88 : SetStyle( implInitStyle( GetStyle() ) );
192 : 88 : m_pImpl->notifyStyleChanged();
193 : : }
194 [ - + ]: 344 : else if ( _nStateChange == STATE_CHANGE_ZOOM )
195 : : {
196 : 0 : m_pImpl->notifyZoomChanged();
197 : : }
198 [ - + ]: 344 : else if ( _nStateChange == STATE_CHANGE_INITSHOW )
199 : : {
200 : 0 : m_pImpl->notifyInitShow();
201 : : }
202 : 432 : Control::StateChanged( _nStateChange );
203 : 432 : }
204 : :
205 : : //--------------------------------------------------------------------
206 : 0 : long RichTextControl::PreNotify( NotifyEvent& _rNEvt )
207 : : {
208 [ # # ]: 0 : if ( IsWindowOrChild( _rNEvt.GetWindow() ) )
209 : : {
210 [ # # ]: 0 : if ( EVENT_KEYINPUT == _rNEvt.GetType() )
211 : : {
212 : 0 : const ::KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
213 : :
214 : 0 : sal_uInt16 nCode = pKeyEvent->GetKeyCode().GetCode();
215 : 0 : sal_Bool bShift = pKeyEvent->GetKeyCode().IsShift();
216 : 0 : sal_Bool bCtrl = pKeyEvent->GetKeyCode().IsMod1();
217 : 0 : sal_Bool bAlt = pKeyEvent->GetKeyCode().IsMod2();
218 [ # # ][ # # ]: 0 : if ( ( KEY_TAB == nCode ) && bCtrl && !bAlt )
[ # # ]
219 : : {
220 : : // Ctrl-Tab is used to step out of the control
221 : : // -> build a new key event without the Ctrl-key, and let the very base class handle it
222 [ # # ]: 0 : KeyCode aNewCode( KEY_TAB, bShift, sal_False, sal_False, sal_False );
223 [ # # ]: 0 : ::KeyEvent aNewEvent( pKeyEvent->GetCharCode(), aNewCode );
224 [ # # ]: 0 : Control::KeyInput( aNewEvent );
225 : 0 : return 1; // handled
226 : : }
227 : :
228 : : #if OSL_DEBUG_LEVEL > 0
229 : : if ( ( ( KEY_F12 == nCode )
230 : : || ( KEY_F11 == nCode )
231 : : )
232 : : && bCtrl
233 : : && bAlt
234 : : )
235 : : {
236 : : bool bLoad = KEY_F11 == nCode;
237 : : struct
238 : : {
239 : : const sal_Char* pDescription;
240 : : const sal_Char* pExtension;
241 : : EETextFormat eFormat;
242 : : } aExportFormats[] =
243 : : {
244 : : { "OASIS OpenDocument (*.xml)", "*.xml", EE_FORMAT_XML },
245 : : { "HyperText Markup Language (*.html)", "*.html", EE_FORMAT_HTML },
246 : : { "Rich Text format (*.rtf)", "*.rtf", EE_FORMAT_RTF },
247 : : { "Text (*.txt)", "*.txt", EE_FORMAT_TEXT }
248 : : };
249 : :
250 : : ::sfx2::FileDialogHelper aFP( bLoad ? com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, 0, this );
251 : :
252 : : for ( size_t i = 0; i < SAL_N_ELEMENTS( aExportFormats ); ++i )
253 : : {
254 : : aFP.AddFilter(
255 : : rtl::OUString::createFromAscii( aExportFormats[i].pDescription ),
256 : : rtl::OUString::createFromAscii( aExportFormats[i].pExtension ) );
257 : : }
258 : : ErrCode nResult = aFP.Execute();
259 : : if ( nResult == 0 )
260 : : {
261 : : String sFileName = aFP.GetPath();
262 : : SvStream* pStream = ::utl::UcbStreamHelper::CreateStream(
263 : : sFileName, ( bLoad ? STREAM_READ : STREAM_WRITE | STREAM_TRUNC ) | STREAM_SHARE_DENYALL
264 : : );
265 : : if ( pStream )
266 : : {
267 : : EETextFormat eFormat = EE_FORMAT_XML;
268 : : String sFilter = aFP.GetCurrentFilter();
269 : : for ( size_t i = 0; i < SAL_N_ELEMENTS( aExportFormats ); ++i )
270 : : {
271 : : if ( sFilter.EqualsAscii( aExportFormats[i].pDescription ) )
272 : : {
273 : : eFormat = aExportFormats[i].eFormat;
274 : : break;
275 : : }
276 : : }
277 : : if ( bLoad )
278 : : {
279 : : INetURLObject aURL( sFileName );
280 : : aURL.removeSegment();
281 : : getEngine().Read( *pStream, aURL.GetMainURL( INetURLObject::NO_DECODE ), eFormat );
282 : : }
283 : : else
284 : : {
285 : : getEngine().Write( *pStream, eFormat );
286 : : }
287 : : }
288 : : DELETEZ( pStream );
289 : : }
290 : : return 1; // handled
291 : : }
292 : : #endif
293 : : }
294 : : }
295 : 0 : return Control::PreNotify( _rNEvt );
296 : : }
297 : :
298 : : //--------------------------------------------------------------------
299 : 198 : long RichTextControl::Notify( NotifyEvent& _rNEvt )
300 : : {
301 : 198 : long nDone = 0;
302 [ - + ]: 198 : if ( _rNEvt.GetType() == EVENT_COMMAND )
303 : : {
304 : 0 : const CommandEvent& rEvent = *_rNEvt.GetCommandEvent();
305 : 0 : nDone = m_pImpl->HandleCommand( rEvent );
306 : : }
307 [ + - ]: 198 : return nDone ? nDone : Control::Notify( _rNEvt );
308 : : }
309 : :
310 : : //--------------------------------------------------------------------
311 : 106 : void RichTextControl::Draw( OutputDevice* _pDev, const Point& _rPos, const Size& _rSize, sal_uLong _nFlags )
312 : : {
313 : 106 : m_pImpl->Draw( _pDev, _rPos, _rSize, _nFlags );
314 : 106 : }
315 : :
316 : : //--------------------------------------------------------------------
317 : 0 : EditView& RichTextControl::getView()
318 : : {
319 : 0 : return *m_pImpl->getView( RichTextControlImpl::GrantAccess() );
320 : : }
321 : :
322 : : //--------------------------------------------------------------------
323 : 0 : const EditView& RichTextControl::getView() const
324 : : {
325 : 0 : return *m_pImpl->getView( RichTextControlImpl::GrantAccess() );
326 : : }
327 : :
328 : : //--------------------------------------------------------------------
329 : 0 : EditEngine& RichTextControl::getEngine() const
330 : : {
331 : 0 : return *m_pImpl->getEngine( RichTextControlImpl::GrantAccess() );
332 : : }
333 : :
334 : : //--------------------------------------------------------------------
335 : 0 : Window& RichTextControl::getViewport() const
336 : : {
337 : 0 : return *m_pImpl->getViewport( RichTextControlImpl::GrantAccess() );
338 : : }
339 : :
340 : : //--------------------------------------------------------------------
341 : 48 : void RichTextControl::SetReadOnly( bool _bReadOnly )
342 : : {
343 : 48 : m_pImpl->SetReadOnly( _bReadOnly );
344 : 48 : }
345 : :
346 : : //--------------------------------------------------------------------
347 : 48 : bool RichTextControl::IsReadOnly() const
348 : : {
349 : 48 : return m_pImpl->IsReadOnly();
350 : : }
351 : :
352 : : //--------------------------------------------------------------------
353 : 40 : void RichTextControl::SetBackgroundColor( )
354 : : {
355 : 40 : m_pImpl->SetBackgroundColor( );
356 : 40 : }
357 : :
358 : : //--------------------------------------------------------------------
359 : 0 : void RichTextControl::SetBackgroundColor( const Color& _rColor )
360 : : {
361 : 0 : m_pImpl->SetBackgroundColor( _rColor );
362 : 0 : }
363 : :
364 : : //--------------------------------------------------------------------
365 : 48 : void RichTextControl::SetHideInactiveSelection( bool _bHide )
366 : : {
367 : 48 : m_pImpl->SetHideInactiveSelection( _bHide );
368 : 48 : }
369 : :
370 : : //--------------------------------------------------------------------
371 : 48 : bool RichTextControl::GetHideInactiveSelection() const
372 : : {
373 : 48 : return m_pImpl->GetHideInactiveSelection( );
374 : : }
375 : :
376 : : //........................................................................
377 : : } // namespace frm
378 : : //........................................................................
379 : :
380 : :
381 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|