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/flditem.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <tools/debug.hxx>
29 #include <svl/stritem.hxx>
31 #include <svx/svxids.hrc>
33 #include <OutlineView.hxx>
35 #include <DrawDocShell.hxx>
36 #include <ViewShell.hxx>
37 #include <OutlineViewShell.hxx>
43 static const sal_uInt16 SidArray
[] = {
47 SID_STYLE_UPDATE_BY_EXAMPLE
,
53 SID_ATTR_CHAR_POSTURE
,
55 SID_ATTR_CHAR_SHADOWED
,
56 SID_ATTR_CHAR_STRIKEOUT
,
57 SID_ATTR_CHAR_UNDERLINE
,
58 SID_ATTR_CHAR_FONTHEIGHT
,
60 SID_ATTR_CHAR_KERNING
,
66 SID_OUTLINE_COLLAPSE_ALL
,
69 SID_OUTLINE_EXPAND_ALL
,
73 SID_HYPERLINK_GETLINK
,
76 SID_PARASPACE_INCREASE
,
77 SID_PARASPACE_DECREASE
,
85 FuOutlineText::FuOutlineText(ViewShell
* pViewShell
, ::sd::Window
* pWindow
,
86 ::sd::View
* pView
, SdDrawDocument
* pDoc
,
88 : FuPoor(pViewShell
, pWindow
, pView
, pDoc
, rReq
),
89 pOutlineViewShell (static_cast<OutlineViewShell
*>(pViewShell
)),
90 pOutlineView (static_cast<OutlineView
*>(pView
))
95 * forward to OutlinerView
97 bool FuOutlineText::Command(const CommandEvent
& rCEvt
)
101 OutlinerView
* pOlView
=
102 static_cast<OutlineView
*>(mpView
)->GetViewByWindow(mpWindow
);
103 DBG_ASSERT (pOlView
, "no OutlineView found");
107 pOlView
->Command(rCEvt
); // unfortunately, we do not get a return value
114 rtl::Reference
<FuPoor
> FuOutlineText::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
116 rtl::Reference
<FuPoor
> xFunc( new FuOutlineText( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
117 xFunc
->DoExecute( rReq
);
121 bool FuOutlineText::MouseButtonDown(const MouseEvent
& rMEvt
)
123 mpWindow
->GrabFocus();
125 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseButtonDown(rMEvt
);
129 // Now the attributes of the current text position can be different
130 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArray
);
134 bReturn
= FuPoor::MouseButtonDown(rMEvt
);
140 bool FuOutlineText::MouseMove(const MouseEvent
& rMEvt
)
142 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseMove(rMEvt
);
146 bReturn
= FuPoor::MouseMove(rMEvt
);
152 bool FuOutlineText::MouseButtonUp(const MouseEvent
& rMEvt
)
154 bool bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->MouseButtonUp(rMEvt
);
158 // Now the attributes of the current text position can be different
159 mpViewShell
->GetViewFrame()->GetBindings().Invalidate( SidArray
);
163 const SvxFieldItem
* pFieldItem
= pOutlineView
->GetViewByWindow( mpWindow
)->GetFieldUnderMousePointer();
166 const SvxFieldData
* pField
= pFieldItem
->GetField();
168 if( auto pURLField
= dynamic_cast< const SvxURLField
*>( pField
) )
171 mpWindow
->ReleaseMouse();
172 SfxStringItem
aStrItem( SID_FILE_NAME
, pURLField
->GetURL() );
173 SfxStringItem
aReferer( SID_REFERER
, mpDocSh
->GetMedium()->GetName() );
174 SfxBoolItem
aBrowseItem( SID_BROWSE
, true );
175 SfxViewFrame
* pFrame
= mpViewShell
->GetViewFrame();
177 if ( rMEvt
.IsMod1() )
180 pFrame
->GetDispatcher()->ExecuteList(SID_OPENDOC
,
181 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
182 { &aStrItem
, &aBrowseItem
, &aReferer
});
186 // open in current frame
187 SfxFrameItem
aFrameItem( SID_DOCFRAME
, pFrame
);
188 pFrame
->GetDispatcher()->ExecuteList(SID_OPENDOC
,
189 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
190 { &aStrItem
, &aFrameItem
, &aBrowseItem
, &aReferer
});
197 bReturn
= FuPoor::MouseButtonUp(rMEvt
);
203 * Process keyboard input
204 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
206 bool FuOutlineText::KeyInput(const KeyEvent
& rKEvt
)
208 bool bReturn
= false;
210 sal_uInt16 nKeyGroup
= rKEvt
.GetKeyCode().GetGroup();
211 if( !mpDocSh
->IsReadOnly() || nKeyGroup
== KEYGROUP_CURSOR
)
213 mpWindow
->GrabFocus();
215 std::unique_ptr
<OutlineViewModelChangeGuard
, o3tl::default_delete
<OutlineViewModelChangeGuard
>> aGuard
;
216 if( (nKeyGroup
!= KEYGROUP_CURSOR
) && (nKeyGroup
!= KEYGROUP_FKEYS
) )
217 aGuard
.reset( new OutlineViewModelChangeGuard( *pOutlineView
) );
219 bReturn
= pOutlineView
->GetViewByWindow(mpWindow
)->PostKeyEvent(rKEvt
);
223 UpdateForKeyPress (rKEvt
);
227 bReturn
= FuPoor::KeyInput(rKEvt
);
234 void FuOutlineText::UpdateForKeyPress (const KeyEvent
& rEvent
)
236 // Attributes at the current text position may have changed.
237 mpViewShell
->GetViewFrame()->GetBindings().Invalidate(SidArray
);
239 bool bUpdatePreview
= true;
240 switch (rEvent
.GetKeyCode().GetCode())
242 // When just the cursor has been moved the preview only changes when
243 // it moved to entries of another page. To prevent unnecessary
244 // updates we check this here. This is an early rejection test, so
245 // missing a key is not a problem.
255 SdPage
* pCurrentPage
= pOutlineViewShell
->GetActualPage();
256 bUpdatePreview
= (pCurrentPage
!= pOutlineViewShell
->GetActualPage());
261 pOutlineViewShell
->UpdatePreview (pOutlineViewShell
->GetActualPage());
265 * Cut object to clipboard
267 void FuOutlineText::DoCut()
269 pOutlineView
->GetViewByWindow(mpWindow
)->Cut();
273 * Copy object to clipboard
275 void FuOutlineText::DoCopy()
277 pOutlineView
->GetViewByWindow(mpWindow
)->Copy();
281 * Paste object from clipboard
283 void FuOutlineText::DoPaste()
285 pOutlineView
->GetViewByWindow(mpWindow
)->PasteSpecial();
289 * Paste object as unformatted text from clipboard
291 void FuOutlineText::DoPasteUnformatted()
293 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewShell
->GetActiveWindow() ) );
294 if (aDataHelper
.GetTransferable().is())
297 if (aDataHelper
.GetString(SotClipboardFormatId::STRING
, aText
))
298 pOutlineView
->GetViewByWindow(mpWindow
)->InsertText(aText
);
302 } // end of namespace sd
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */