android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / func / fuoltext.cxx
blobfe64cac47dfbcde6e6cb573417f53a27add8f2f5
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/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>
32 #include <app.hrc>
33 #include <OutlineView.hxx>
34 #include <Window.hxx>
35 #include <DrawDocShell.hxx>
36 #include <ViewShell.hxx>
37 #include <OutlineViewShell.hxx>
39 #include <memory>
41 namespace sd {
43 const sal_uInt16 SidArray[] = {
44 SID_STYLE_FAMILY2,
45 SID_STYLE_FAMILY3,
46 SID_STYLE_FAMILY5,
47 SID_STYLE_UPDATE_BY_EXAMPLE,
48 SID_CUT,
49 SID_COPY,
50 SID_PASTE,
51 SID_SELECTALL,
52 SID_ATTR_CHAR_FONT,
53 SID_ATTR_CHAR_POSTURE,
54 SID_ATTR_CHAR_WEIGHT,
55 SID_ATTR_CHAR_SHADOWED,
56 SID_ATTR_CHAR_STRIKEOUT,
57 SID_ATTR_CHAR_UNDERLINE,
58 SID_ATTR_CHAR_FONTHEIGHT,
59 SID_ATTR_CHAR_COLOR,
60 SID_ATTR_CHAR_KERNING,
61 SID_OUTLINE_UP,
62 SID_OUTLINE_DOWN,
63 SID_OUTLINE_LEFT,
64 SID_OUTLINE_RIGHT,
65 //SID_OUTLINE_FORMAT,
66 SID_OUTLINE_COLLAPSE_ALL,
67 //SID_OUTLINE_BULLET,
68 SID_OUTLINE_COLLAPSE,
69 SID_OUTLINE_EXPAND_ALL,
70 SID_OUTLINE_EXPAND,
71 SID_SET_SUPER_SCRIPT,
72 SID_SET_SUB_SCRIPT,
73 SID_HYPERLINK_GETLINK,
74 SID_DEC_INDENT,
75 SID_INC_INDENT,
76 SID_PARASPACE_INCREASE,
77 SID_PARASPACE_DECREASE,
78 SID_SCALE,
79 SID_STATUS_PAGE,
80 SID_STATUS_LAYOUT,
81 SID_EXPAND_PAGE,
82 SID_SUMMARY_PAGE,
83 0 };
86 FuOutlineText::FuOutlineText(ViewShell* pViewShell, ::sd::Window* pWindow,
87 ::sd::View* pView, SdDrawDocument* pDoc,
88 SfxRequest& rReq)
89 : FuPoor(pViewShell, pWindow, pView, pDoc, rReq),
90 pOutlineViewShell (static_cast<OutlineViewShell*>(pViewShell)),
91 pOutlineView (static_cast<OutlineView*>(pView))
95 /**
96 * forward to OutlinerView
98 bool FuOutlineText::Command(const CommandEvent& rCEvt)
100 bool bResult = false;
102 OutlinerView* pOlView =
103 static_cast<OutlineView*>(mpView)->GetViewByWindow(mpWindow);
104 DBG_ASSERT (pOlView, "no OutlineView found");
106 if (pOlView)
108 pOlView->Command(rCEvt); // unfortunately, we do not get a return value
109 bResult = true;
111 return bResult;
115 rtl::Reference<FuPoor> FuOutlineText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
117 rtl::Reference<FuPoor> xFunc( new FuOutlineText( pViewSh, pWin, pView, pDoc, rReq ) );
118 xFunc->DoExecute( rReq );
119 return xFunc;
122 bool FuOutlineText::MouseButtonDown(const MouseEvent& rMEvt)
124 mpWindow->GrabFocus();
126 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonDown(rMEvt);
128 if (bReturn)
130 // Now the attributes of the current text position can be different
131 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
133 else
135 bReturn = FuPoor::MouseButtonDown(rMEvt);
138 return bReturn;
141 bool FuOutlineText::MouseMove(const MouseEvent& rMEvt)
143 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseMove(rMEvt);
145 if (!bReturn)
147 bReturn = FuPoor::MouseMove(rMEvt);
150 return bReturn;
153 bool FuOutlineText::MouseButtonUp(const MouseEvent& rMEvt)
155 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonUp(rMEvt);
157 if (bReturn)
159 // Now the attributes of the current text position can be different
160 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
162 else
164 const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( mpWindow )->GetFieldUnderMousePointer();
165 if( pFieldItem )
167 const SvxFieldData* pField = pFieldItem->GetField();
169 if( auto pURLField = dynamic_cast< const SvxURLField *>( pField ) )
171 bReturn = true;
172 mpWindow->ReleaseMouse();
173 SfxStringItem aStrItem( SID_FILE_NAME, pURLField->GetURL() );
174 SfxStringItem aReferer( SID_REFERER, mpDocSh->GetMedium()->GetName() );
175 SfxBoolItem aBrowseItem( SID_BROWSE, true );
176 SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
178 if ( rMEvt.IsMod1() )
180 // open in new frame
181 pFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
182 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
183 { &aStrItem, &aBrowseItem, &aReferer });
185 else
187 // open in current frame
188 SfxFrameItem aFrameItem( SID_DOCFRAME, pFrame );
189 pFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
190 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
191 { &aStrItem, &aFrameItem, &aBrowseItem, &aReferer });
197 if( !bReturn )
198 bReturn = FuPoor::MouseButtonUp(rMEvt);
200 return bReturn;
204 * Process keyboard input
205 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
207 bool FuOutlineText::KeyInput(const KeyEvent& rKEvt)
209 bool bReturn = false;
211 sal_uInt16 nKeyGroup = rKEvt.GetKeyCode().GetGroup();
212 if( !mpDocSh->IsReadOnly() || nKeyGroup == KEYGROUP_CURSOR )
214 mpWindow->GrabFocus();
216 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
217 if( (nKeyGroup != KEYGROUP_CURSOR) && (nKeyGroup != KEYGROUP_FKEYS) )
218 aGuard.reset( new OutlineViewModelChangeGuard( *pOutlineView ) );
220 bReturn = pOutlineView->GetViewByWindow(mpWindow)->PostKeyEvent(rKEvt);
222 if (bReturn)
224 UpdateForKeyPress (rKEvt);
226 else
228 bReturn = FuPoor::KeyInput(rKEvt);
232 return bReturn;
235 void FuOutlineText::UpdateForKeyPress (const KeyEvent& rEvent)
237 // Attributes at the current text position may have changed.
238 mpViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);
240 bool bUpdatePreview = true;
241 switch (rEvent.GetKeyCode().GetCode())
243 // When just the cursor has been moved the preview only changes when
244 // it moved to entries of another page. To prevent unnecessary
245 // updates we check this here. This is an early rejection test, so
246 // missing a key is not a problem.
247 case KEY_UP:
248 case KEY_DOWN:
249 case KEY_LEFT:
250 case KEY_RIGHT:
251 case KEY_HOME:
252 case KEY_END:
253 case KEY_PAGEUP:
254 case KEY_PAGEDOWN:
256 SdPage* pCurrentPage = pOutlineViewShell->GetActualPage();
257 bUpdatePreview = (pCurrentPage != pOutlineViewShell->GetActualPage());
259 break;
261 if (bUpdatePreview)
262 pOutlineViewShell->UpdatePreview (pOutlineViewShell->GetActualPage());
266 * Cut object to clipboard
268 void FuOutlineText::DoCut()
270 pOutlineView->GetViewByWindow(mpWindow)->Cut();
274 * Copy object to clipboard
276 void FuOutlineText::DoCopy()
278 pOutlineView->GetViewByWindow(mpWindow)->Copy();
282 * Paste object from clipboard
284 void FuOutlineText::DoPaste()
286 pOutlineView->GetViewByWindow(mpWindow)->PasteSpecial();
290 * Paste object as unformatted text from clipboard
292 void FuOutlineText::DoPasteUnformatted()
294 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewShell->GetActiveWindow() ) );
295 if (aDataHelper.GetTransferable().is())
297 OUString aText;
298 if (aDataHelper.GetString(SotClipboardFormatId::STRING, aText))
299 pOutlineView->GetViewByWindow(mpWindow)->InsertText(aText);
303 } // end of namespace sd
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */