bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuoltext.cxx
blob79c13a17a444b5f424e6c4e8157c38712114da99
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 <stdio.h>
40 namespace sd {
42 static sal_uInt16 SidArray[] = {
43 SID_STYLE_FAMILY2,
44 SID_STYLE_FAMILY3,
45 SID_STYLE_FAMILY5,
46 SID_STYLE_UPDATE_BY_EXAMPLE,
47 SID_CUT,
48 SID_COPY,
49 SID_PASTE,
50 SID_SELECTALL,
51 SID_ATTR_CHAR_FONT,
52 SID_ATTR_CHAR_POSTURE,
53 SID_ATTR_CHAR_WEIGHT,
54 SID_ATTR_CHAR_SHADOWED,
55 SID_ATTR_CHAR_STRIKEOUT,
56 SID_ATTR_CHAR_UNDERLINE,
57 SID_ATTR_CHAR_FONTHEIGHT,
58 SID_ATTR_CHAR_COLOR,
59 SID_ATTR_CHAR_KERNING,
60 SID_OUTLINE_UP,
61 SID_OUTLINE_DOWN,
62 SID_OUTLINE_LEFT,
63 SID_OUTLINE_RIGHT,
64 //SID_OUTLINE_FORMAT,
65 SID_OUTLINE_COLLAPSE_ALL,
66 //SID_OUTLINE_BULLET,
67 SID_OUTLINE_COLLAPSE,
68 SID_OUTLINE_EXPAND_ALL,
69 SID_OUTLINE_EXPAND,
70 SID_SET_SUPER_SCRIPT,
71 SID_SET_SUB_SCRIPT,
72 SID_HYPERLINK_GETLINK,
73 SID_PRESENTATION_TEMPLATES,
74 SID_STATUS_PAGE,
75 SID_STATUS_LAYOUT,
76 SID_EXPAND_PAGE,
77 SID_SUMMARY_PAGE,
78 SID_PARASPACE_INCREASE,
79 SID_PARASPACE_DECREASE,
80 0 };
82 TYPEINIT1( FuOutlineText, FuOutline );
84 FuOutlineText::FuOutlineText(ViewShell* pViewShell, ::sd::Window* pWindow,
85 ::sd::View* pView, SdDrawDocument* pDoc,
86 SfxRequest& rReq)
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 );
95 return xFunc;
98 bool FuOutlineText::MouseButtonDown(const MouseEvent& rMEvt)
100 mpWindow->GrabFocus();
102 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonDown(rMEvt);
104 if (bReturn)
106 // Now the attributes of the current text position can be different
107 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
109 else
111 bReturn = FuOutline::MouseButtonDown(rMEvt);
114 return bReturn;
117 bool FuOutlineText::MouseMove(const MouseEvent& rMEvt)
119 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseMove(rMEvt);
121 if (!bReturn)
123 bReturn = FuOutline::MouseMove(rMEvt);
126 return bReturn;
129 bool FuOutlineText::MouseButtonUp(const MouseEvent& rMEvt)
131 bool bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonUp(rMEvt);
133 if (bReturn)
135 // Now the attributes of the current text position can be different
136 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
138 else
140 const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( mpWindow )->GetFieldUnderMousePointer();
141 if( pFieldItem )
143 const SvxFieldData* pField = pFieldItem->GetField();
145 if( pField && pField->ISA( SvxURLField ) )
147 bReturn = true;
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() )
156 // open in new frame
157 pFrame->GetDispatcher()->Execute(SID_OPENDOC, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
158 &aStrItem, &aBrowseItem, &aReferer, 0L);
160 else
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);
171 if( !bReturn )
172 bReturn = FuOutline::MouseButtonUp(rMEvt);
174 return bReturn;
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);
196 if (bReturn)
198 UpdateForKeyPress (rKEvt);
200 else
202 bReturn = FuOutline::KeyInput(rKEvt);
206 return bReturn;
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.
221 case KEY_UP:
222 case KEY_DOWN:
223 case KEY_LEFT:
224 case KEY_RIGHT:
225 case KEY_HOME:
226 case KEY_END:
227 case KEY_PAGEUP:
228 case KEY_PAGEDOWN:
230 SdPage* pCurrentPage = pOutlineViewShell->GetActualPage();
231 bUpdatePreview = (pCurrentPage != pOutlineViewShell->GetActualPage());
233 break;
235 if (bUpdatePreview)
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())
281 OUString aText;
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: */