Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / func / fuoltext.cxx
blob5510866ae957ec602dc00d679ff21958a6d1073c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
31 #include <app.hrc>
32 #include <OutlineView.hxx>
33 #include <Window.hxx>
34 #include <DrawDocShell.hxx>
35 #include <ViewShell.hxx>
36 #include <OutlineViewShell.hxx>
38 #include <memory>
40 #include <stdio.h>
42 namespace sd {
44 static const sal_uInt16 SidArray[] = {
45 SID_STYLE_FAMILY2,
46 SID_STYLE_FAMILY3,
47 SID_STYLE_FAMILY5,
48 SID_STYLE_UPDATE_BY_EXAMPLE,
49 SID_CUT,
50 SID_COPY,
51 SID_PASTE,
52 SID_SELECTALL,
53 SID_ATTR_CHAR_FONT,
54 SID_ATTR_CHAR_POSTURE,
55 SID_ATTR_CHAR_WEIGHT,
56 SID_ATTR_CHAR_SHADOWED,
57 SID_ATTR_CHAR_STRIKEOUT,
58 SID_ATTR_CHAR_UNDERLINE,
59 SID_ATTR_CHAR_FONTHEIGHT,
60 SID_ATTR_CHAR_COLOR,
61 SID_ATTR_CHAR_KERNING,
62 SID_OUTLINE_UP,
63 SID_OUTLINE_DOWN,
64 SID_OUTLINE_LEFT,
65 SID_OUTLINE_RIGHT,
66 //SID_OUTLINE_FORMAT,
67 SID_OUTLINE_COLLAPSE_ALL,
68 //SID_OUTLINE_BULLET,
69 SID_OUTLINE_COLLAPSE,
70 SID_OUTLINE_EXPAND_ALL,
71 SID_OUTLINE_EXPAND,
72 SID_SET_SUPER_SCRIPT,
73 SID_SET_SUB_SCRIPT,
74 SID_HYPERLINK_GETLINK,
75 SID_PARASPACE_INCREASE,
76 SID_PARASPACE_DECREASE,
77 SID_STATUS_PAGE,
78 SID_STATUS_LAYOUT,
79 SID_EXPAND_PAGE,
80 SID_SUMMARY_PAGE,
81 0 };
84 FuOutlineText::FuOutlineText(ViewShell* pViewShell, ::sd::Window* pWindow,
85 ::sd::View* pView, SdDrawDocument* pDoc,
86 SfxRequest& rReq)
87 : FuPoor(pViewShell, pWindow, pView, pDoc, rReq),
88 pOutlineViewShell (static_cast<OutlineViewShell*>(pViewShell)),
89 pOutlineView (static_cast<OutlineView*>(pView))
93 /**
94 * forward to OutlinerView
96 bool FuOutlineText::Command(const CommandEvent& rCEvt)
98 bool bResult = false;
100 OutlinerView* pOlView =
101 static_cast<OutlineView*>(mpView)->GetViewByWindow(mpWindow);
102 DBG_ASSERT (pOlView, "no OutlineView found");
104 if (pOlView)
106 pOlView->Command(rCEvt); // unfortunately, we do not get a return value
107 bResult = true;
109 return bResult;
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 );
117 return xFunc;
120 bool FuOutlineText::MouseButtonDown(const MouseEvent& rMEvt)
122 mpWindow->GrabFocus();
124 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonDown(rMEvt);
126 if (bReturn)
128 // Now the attributes of the current text position can be different
129 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
131 else
133 bReturn = FuPoor::MouseButtonDown(rMEvt);
136 return bReturn;
139 bool FuOutlineText::MouseMove(const MouseEvent& rMEvt)
141 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseMove(rMEvt);
143 if (!bReturn)
145 bReturn = FuPoor::MouseMove(rMEvt);
148 return bReturn;
151 bool FuOutlineText::MouseButtonUp(const MouseEvent& rMEvt)
153 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonUp(rMEvt);
155 if (bReturn)
157 // Now the attributes of the current text position can be different
158 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
160 else
162 const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( mpWindow )->GetFieldUnderMousePointer();
163 if( pFieldItem )
165 const SvxFieldData* pField = pFieldItem->GetField();
167 if( pField && dynamic_cast< const SvxURLField *>( pField ) != nullptr )
169 bReturn = true;
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() )
178 // open in new frame
179 pFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
180 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
181 { &aStrItem, &aBrowseItem, &aReferer });
183 else
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 });
195 if( !bReturn )
196 bReturn = FuPoor::MouseButtonUp(rMEvt);
198 return bReturn;
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);
220 if (bReturn)
222 UpdateForKeyPress (rKEvt);
224 else
226 bReturn = FuPoor::KeyInput(rKEvt);
230 return bReturn;
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.
245 case KEY_UP:
246 case KEY_DOWN:
247 case KEY_LEFT:
248 case KEY_RIGHT:
249 case KEY_HOME:
250 case KEY_END:
251 case KEY_PAGEUP:
252 case KEY_PAGEDOWN:
254 SdPage* pCurrentPage = pOutlineViewShell->GetActualPage();
255 bUpdatePreview = (pCurrentPage != pOutlineViewShell->GetActualPage());
257 break;
259 if (bUpdatePreview)
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())
295 OUString aText;
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: */