1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "fuoltext.hxx"
22 #include <sfx2/viewfrm.hxx>
23 #include <editeng/outliner.hxx>
24 #include <editeng/eeitem.hxx>
25 #include <editeng/flditem.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/docfile.hxx>
28 #include <sfx2/dispatch.hxx>
30 #include <svx/svxids.hrc>
32 #include "OutlineView.hxx"
34 #include "DrawDocShell.hxx"
35 #include "ViewShell.hxx"
36 #include "OutlineViewShell.hxx"
42 static sal_uInt16 SidArray
[] = {
46 SID_STYLE_UPDATE_BY_EXAMPLE
,
52 SID_ATTR_CHAR_POSTURE
,
54 SID_ATTR_CHAR_SHADOWED
,
55 SID_ATTR_CHAR_STRIKEOUT
,
56 SID_ATTR_CHAR_UNDERLINE
,
57 SID_ATTR_CHAR_FONTHEIGHT
,
59 SID_ATTR_CHAR_KERNING
,
65 SID_OUTLINE_COLLAPSE_ALL
,
68 SID_OUTLINE_EXPAND_ALL
,
72 SID_HYPERLINK_GETLINK
,
73 SID_PRESENTATION_TEMPLATES
,
78 SID_PARASPACE_INCREASE
,
79 SID_PARASPACE_DECREASE
,
82 TYPEINIT1( FuOutlineText
, FuOutline
);
84 FuOutlineText::FuOutlineText(ViewShell
* pViewShell
, ::sd::Window
* pWindow
,
85 ::sd::View
* pView
, SdDrawDocument
* pDoc
,
87 : FuOutline(pViewShell
, pWindow
, pView
, pDoc
, rReq
)
91 rtl::Reference
<FuPoor
> FuOutlineText::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
93 rtl::Reference
<FuPoor
> xFunc( new FuOutlineText( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
94 xFunc
->DoExecute( rReq
);
98 bool FuOutlineText::MouseButtonDown(const MouseEvent
& rMEvt
)
100 mpWindow
->GrabFocus();
102 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseButtonDown(rMEvt
);
106 // Now the attributes of the current text position can be different
107 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArray
);
111 bReturn
= FuOutline::MouseButtonDown(rMEvt
);
117 bool FuOutlineText::MouseMove(const MouseEvent
& rMEvt
)
119 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseMove(rMEvt
);
123 bReturn
= FuOutline::MouseMove(rMEvt
);
129 bool FuOutlineText::MouseButtonUp(const MouseEvent
& rMEvt
)
131 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseButtonUp(rMEvt
);
135 // Now the attributes of the current text position can be different
136 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArray
);
140 const SvxFieldItem
* pFieldItem
= pOutlineView
->GetViewByWindow( mpWindow
)->GetFieldUnderMousePointer();
143 const SvxFieldData
* pField
= pFieldItem
->GetField();
145 if( pField
&& pField
->ISA( SvxURLField
) )
148 mpWindow
->ReleaseMouse();
149 SfxStringItem
aStrItem( SID_FILE_NAME
, static_cast<const SvxURLField
*>(pField
)->GetURL() );
150 SfxStringItem
aReferer( SID_REFERER
, mpDocSh
->GetMedium()->GetName() );
151 SfxBoolItem
aBrowseItem( SID_BROWSE
, true );
152 SfxViewFrame
* pFrame
= mpViewShell
->GetViewFrame();
154 if ( rMEvt
.IsMod1() )
157 pFrame
->GetDispatcher()->Execute(SID_OPENDOC
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
158 &aStrItem
, &aBrowseItem
, &aReferer
, 0L);
162 // open in current frame
163 SfxFrameItem
aFrameItem( SID_DOCFRAME
, pFrame
);
164 pFrame
->GetDispatcher()->Execute(SID_OPENDOC
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
165 &aStrItem
, &aFrameItem
, &aBrowseItem
, &aReferer
, 0L);
172 bReturn
= FuOutline::MouseButtonUp(rMEvt
);
178 * Process keyboard input
179 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
181 bool FuOutlineText::KeyInput(const KeyEvent
& rKEvt
)
183 bool bReturn
= false;
185 sal_uInt16 nKeyGroup
= rKEvt
.GetKeyCode().GetGroup();
186 if( !mpDocSh
->IsReadOnly() || nKeyGroup
== KEYGROUP_CURSOR
)
188 mpWindow
->GrabFocus();
190 boost::scoped_ptr
< OutlineViewModelChangeGuard
> aGuard
;
191 if( (nKeyGroup
!= KEYGROUP_CURSOR
) && (nKeyGroup
!= KEYGROUP_FKEYS
) )
192 aGuard
.reset( new OutlineViewModelChangeGuard( *pOutlineView
) );
194 bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->PostKeyEvent(rKEvt
);
198 UpdateForKeyPress (rKEvt
);
202 bReturn
= FuOutline::KeyInput(rKEvt
);
209 void FuOutlineText::UpdateForKeyPress (const KeyEvent
& rEvent
)
211 // Attributes at the current text position may have changed.
212 mpViewShell
->GetViewFrame()->GetBindings().Invalidate(SidArray
);
214 bool bUpdatePreview
= true;
215 switch (rEvent
.GetKeyCode().GetCode())
217 // When just the cursor has been moved the preview only changes when
218 // it moved to entries of another page. To prevent unnecessary
219 // updates we check this here. This is an early rejection test, so
220 // missing a key is not a problem.
230 SdPage
* pCurrentPage
= pOutlineViewShell
->GetActualPage();
231 bUpdatePreview
= (pCurrentPage
!= pOutlineViewShell
->GetActualPage());
236 pOutlineViewShell
->UpdatePreview (pOutlineViewShell
->GetActualPage());
239 void FuOutlineText::Activate()
241 FuOutline::Activate();
244 void FuOutlineText::Deactivate()
246 FuOutline::Deactivate();
250 * Cut object to clipboard
252 void FuOutlineText::DoCut()
254 pOutlineView
->GetViewByWindow(mpWindow
)->Cut();
258 * Copy object to clipboard
260 void FuOutlineText::DoCopy()
262 pOutlineView
->GetViewByWindow(mpWindow
)->Copy();
266 * Paste object from clipboard
268 void FuOutlineText::DoPaste()
270 pOutlineView
->GetViewByWindow(mpWindow
)->PasteSpecial();
274 * Paste object as unformatted text from clipboard
276 void FuOutlineText::DoPasteUnformatted()
278 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewShell
->GetActiveWindow() ) );
279 if (aDataHelper
.GetTransferable().is())
282 if (aDataHelper
.GetString(SotClipboardFormatId::STRING
, aText
))
283 pOutlineView
->GetViewByWindow(mpWindow
)->InsertText(aText
);
287 } // end of namespace sd
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */