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>
44 static const sal_uInt16 SidArray
[] = {
48 SID_STYLE_UPDATE_BY_EXAMPLE
,
54 SID_ATTR_CHAR_POSTURE
,
56 SID_ATTR_CHAR_SHADOWED
,
57 SID_ATTR_CHAR_STRIKEOUT
,
58 SID_ATTR_CHAR_UNDERLINE
,
59 SID_ATTR_CHAR_FONTHEIGHT
,
61 SID_ATTR_CHAR_KERNING
,
67 SID_OUTLINE_COLLAPSE_ALL
,
70 SID_OUTLINE_EXPAND_ALL
,
74 SID_HYPERLINK_GETLINK
,
75 SID_PARASPACE_INCREASE
,
76 SID_PARASPACE_DECREASE
,
84 FuOutlineText::FuOutlineText(ViewShell
* pViewShell
, ::sd::Window
* pWindow
,
85 ::sd::View
* pView
, SdDrawDocument
* pDoc
,
87 : FuPoor(pViewShell
, pWindow
, pView
, pDoc
, rReq
),
88 pOutlineViewShell (static_cast<OutlineViewShell
*>(pViewShell
)),
89 pOutlineView (static_cast<OutlineView
*>(pView
))
94 * forward to OutlinerView
96 bool FuOutlineText::Command(const CommandEvent
& rCEvt
)
100 OutlinerView
* pOlView
=
101 static_cast<OutlineView
*>(mpView
)->GetViewByWindow(mpWindow
);
102 DBG_ASSERT (pOlView
, "no OutlineView found");
106 pOlView
->Command(rCEvt
); // unfortunately, we do not get a return value
113 rtl::Reference
<FuPoor
> FuOutlineText::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
115 rtl::Reference
<FuPoor
> xFunc( new FuOutlineText( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
116 xFunc
->DoExecute( rReq
);
120 bool FuOutlineText::MouseButtonDown(const MouseEvent
& rMEvt
)
122 mpWindow
->GrabFocus();
124 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseButtonDown(rMEvt
);
128 // Now the attributes of the current text position can be different
129 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArray
);
133 bReturn
= FuPoor::MouseButtonDown(rMEvt
);
139 bool FuOutlineText::MouseMove(const MouseEvent
& rMEvt
)
141 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseMove(rMEvt
);
145 bReturn
= FuPoor::MouseMove(rMEvt
);
151 bool FuOutlineText::MouseButtonUp(const MouseEvent
& rMEvt
)
153 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseButtonUp(rMEvt
);
157 // Now the attributes of the current text position can be different
158 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArray
);
162 const SvxFieldItem
* pFieldItem
= pOutlineView
->GetViewByWindow( mpWindow
)->GetFieldUnderMousePointer();
165 const SvxFieldData
* pField
= pFieldItem
->GetField();
167 if( pField
&& dynamic_cast< const SvxURLField
*>( pField
) != nullptr )
170 mpWindow
->ReleaseMouse();
171 SfxStringItem
aStrItem( SID_FILE_NAME
, static_cast<const SvxURLField
*>(pField
)->GetURL() );
172 SfxStringItem
aReferer( SID_REFERER
, mpDocSh
->GetMedium()->GetName() );
173 SfxBoolItem
aBrowseItem( SID_BROWSE
, true );
174 SfxViewFrame
* pFrame
= mpViewShell
->GetViewFrame();
176 if ( rMEvt
.IsMod1() )
179 pFrame
->GetDispatcher()->ExecuteList(SID_OPENDOC
,
180 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
181 { &aStrItem
, &aBrowseItem
, &aReferer
});
185 // open in current frame
186 SfxFrameItem
aFrameItem( SID_DOCFRAME
, pFrame
);
187 pFrame
->GetDispatcher()->ExecuteList(SID_OPENDOC
,
188 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
189 { &aStrItem
, &aFrameItem
, &aBrowseItem
, &aReferer
});
196 bReturn
= FuPoor::MouseButtonUp(rMEvt
);
202 * Process keyboard input
203 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
205 bool FuOutlineText::KeyInput(const KeyEvent
& rKEvt
)
207 bool bReturn
= false;
209 sal_uInt16 nKeyGroup
= rKEvt
.GetKeyCode().GetGroup();
210 if( !mpDocSh
->IsReadOnly() || nKeyGroup
== KEYGROUP_CURSOR
)
212 mpWindow
->GrabFocus();
214 std::unique_ptr
<OutlineViewModelChangeGuard
, o3tl::default_delete
<OutlineViewModelChangeGuard
>> aGuard
;
215 if( (nKeyGroup
!= KEYGROUP_CURSOR
) && (nKeyGroup
!= KEYGROUP_FKEYS
) )
216 aGuard
.reset( new OutlineViewModelChangeGuard( *pOutlineView
) );
218 bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->PostKeyEvent(rKEvt
);
222 UpdateForKeyPress (rKEvt
);
226 bReturn
= FuPoor::KeyInput(rKEvt
);
233 void FuOutlineText::UpdateForKeyPress (const KeyEvent
& rEvent
)
235 // Attributes at the current text position may have changed.
236 mpViewShell
->GetViewFrame()->GetBindings().Invalidate(SidArray
);
238 bool bUpdatePreview
= true;
239 switch (rEvent
.GetKeyCode().GetCode())
241 // When just the cursor has been moved the preview only changes when
242 // it moved to entries of another page. To prevent unnecessary
243 // updates we check this here. This is an early rejection test, so
244 // missing a key is not a problem.
254 SdPage
* pCurrentPage
= pOutlineViewShell
->GetActualPage();
255 bUpdatePreview
= (pCurrentPage
!= pOutlineViewShell
->GetActualPage());
260 pOutlineViewShell
->UpdatePreview (pOutlineViewShell
->GetActualPage());
264 * Cut object to clipboard
266 void FuOutlineText::DoCut()
268 pOutlineView
->GetViewByWindow(mpWindow
)->Cut();
272 * Copy object to clipboard
274 void FuOutlineText::DoCopy()
276 pOutlineView
->GetViewByWindow(mpWindow
)->Copy();
280 * Paste object from clipboard
282 void FuOutlineText::DoPaste()
284 pOutlineView
->GetViewByWindow(mpWindow
)->PasteSpecial();
288 * Paste object as unformatted text from clipboard
290 void FuOutlineText::DoPasteUnformatted()
292 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewShell
->GetActiveWindow() ) );
293 if (aDataHelper
.GetTransferable().is())
296 if (aDataHelper
.GetString(SotClipboardFormatId::STRING
, aText
))
297 pOutlineView
->GetViewByWindow(mpWindow
)->InsertText(aText
);
301 } // end of namespace sd
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */