tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / func / fuoltext.cxx
blob6cebc1c55cb448b6685086a07c4193ce65992886
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 };
85 void FuOutlineText::UpdateForKeyPress (const KeyEvent& rEvent)
87 FuSimpleOutlinerText::UpdateForKeyPress(rEvent);
88 pOutlineViewShell->UpdatePreview(pOutlineViewShell->GetActualPage());
91 /**
92 * Process keyboard input
93 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
95 bool FuOutlineText::KeyInput(const KeyEvent& rKEvt)
97 sal_uInt16 nKeyGroup = rKEvt.GetKeyCode().GetGroup();
98 if( !mpDocSh->IsReadOnly() || nKeyGroup == KEYGROUP_CURSOR )
100 std::unique_ptr<OutlineViewModelChangeGuard, o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
101 if( (nKeyGroup != KEYGROUP_CURSOR) && (nKeyGroup != KEYGROUP_FKEYS) )
102 aGuard.reset( new OutlineViewModelChangeGuard( *static_cast<OutlineView*>(mpSimpleOutlinerView) ) );
104 return FuSimpleOutlinerText::KeyInput(rKEvt);
107 return false;
110 rtl::Reference<FuPoor> FuOutlineText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::SimpleOutlinerView* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
112 rtl::Reference<FuPoor> xFunc( new FuOutlineText( pViewSh, pWin, pView, pDoc, rReq ) );
113 xFunc->DoExecute( rReq );
114 return xFunc;
117 FuOutlineText::FuOutlineText(ViewShell* pViewShell, ::sd::Window* pWindow,
118 ::sd::SimpleOutlinerView* pView, SdDrawDocument* pDoc,
119 SfxRequest& rReq)
120 : FuSimpleOutlinerText(pViewShell, pWindow, pView, pDoc, rReq)
123 FuSimpleOutlinerText::FuSimpleOutlinerText(ViewShell* pViewShell, ::sd::Window* pWindow,
124 ::sd::SimpleOutlinerView* pView, SdDrawDocument* pDoc,
125 SfxRequest& rReq)
126 : FuPoor(pViewShell, pWindow, pView, pDoc, rReq),
127 pOutlineViewShell (pViewShell),
128 mpSimpleOutlinerView (pView)
133 * forward to OutlinerView
135 bool FuSimpleOutlinerText::Command(const CommandEvent& rCEvt)
137 bool bResult = false;
139 OutlinerView* pOlView = mpSimpleOutlinerView->GetViewByWindow(mpWindow);
141 DBG_ASSERT (pOlView, "no OutlineView found");
143 if (pOlView)
145 pOlView->Command(rCEvt); // unfortunately, we do not get a return value
146 bResult = true;
148 return bResult;
152 rtl::Reference<FuPoor> FuSimpleOutlinerText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::SimpleOutlinerView* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
154 rtl::Reference<FuPoor> xFunc( new FuSimpleOutlinerText( pViewSh, pWin, pView, pDoc, rReq ) );
155 xFunc->DoExecute( rReq );
156 return xFunc;
159 bool FuSimpleOutlinerText::MouseButtonDown(const MouseEvent& rMEvt)
161 mpWindow->GrabFocus();
163 bool bReturn = mpSimpleOutlinerView->GetViewByWindow(mpWindow)->MouseButtonDown(rMEvt);
165 if (bReturn)
167 // Now the attributes of the current text position can be different
168 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
170 else
172 bReturn = FuPoor::MouseButtonDown(rMEvt);
175 return bReturn;
178 bool FuSimpleOutlinerText::MouseMove(const MouseEvent& rMEvt)
180 bool bReturn = mpSimpleOutlinerView->GetViewByWindow(mpWindow)->MouseMove(rMEvt);
182 if (!bReturn)
184 bReturn = FuPoor::MouseMove(rMEvt);
187 return bReturn;
190 bool FuSimpleOutlinerText::MouseButtonUp(const MouseEvent& rMEvt)
192 bool bReturn = mpSimpleOutlinerView->GetViewByWindow(mpWindow)->MouseButtonUp(rMEvt);
194 if (bReturn)
196 // Now the attributes of the current text position can be different
197 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
199 else
201 const SvxFieldItem* pFieldItem = mpSimpleOutlinerView->GetViewByWindow( mpWindow )->GetFieldUnderMousePointer();
202 if( pFieldItem )
204 const SvxFieldData* pField = pFieldItem->GetField();
206 if( auto pURLField = dynamic_cast< const SvxURLField *>( pField ) )
208 bReturn = true;
209 mpWindow->ReleaseMouse();
210 SfxStringItem aStrItem( SID_FILE_NAME, pURLField->GetURL() );
211 SfxStringItem aReferer( SID_REFERER, mpDocSh->GetMedium()->GetName() );
212 SfxBoolItem aBrowseItem( SID_BROWSE, true );
213 SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
215 if ( rMEvt.IsMod1() )
217 // open in new frame
218 pFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
219 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
220 { &aStrItem, &aBrowseItem, &aReferer });
222 else
224 // open in current frame
225 SfxFrameItem aFrameItem( SID_DOCFRAME, pFrame );
226 pFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
227 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
228 { &aStrItem, &aFrameItem, &aBrowseItem, &aReferer });
234 if( !bReturn )
235 bReturn = FuPoor::MouseButtonUp(rMEvt);
237 return bReturn;
241 * Process keyboard input
242 * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
244 bool FuSimpleOutlinerText::KeyInput(const KeyEvent& rKEvt)
246 bool bReturn = false;
248 sal_uInt16 nKeyGroup = rKEvt.GetKeyCode().GetGroup();
249 if( !mpDocSh->IsReadOnly() || nKeyGroup == KEYGROUP_CURSOR )
251 mpWindow->GrabFocus();
253 bReturn = mpSimpleOutlinerView->GetViewByWindow(mpWindow)->PostKeyEvent(rKEvt);
255 if (bReturn)
257 UpdateForKeyPress (rKEvt);
259 else
261 bReturn = FuPoor::KeyInput(rKEvt);
265 return bReturn;
268 void FuSimpleOutlinerText::UpdateForKeyPress (const KeyEvent& /*rEvent*/)
270 // Attributes at the current text position may have changed.
271 mpViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);
275 * Cut object to clipboard
277 void FuSimpleOutlinerText::DoCut()
279 mpSimpleOutlinerView->GetViewByWindow(mpWindow)->Cut();
283 * Copy object to clipboard
285 void FuSimpleOutlinerText::DoCopy()
287 mpSimpleOutlinerView->GetViewByWindow(mpWindow)->Copy();
291 * Paste object from clipboard
293 void FuSimpleOutlinerText::DoPaste()
295 mpSimpleOutlinerView->GetViewByWindow(mpWindow)->PasteSpecial();
299 * Paste object as unformatted text from clipboard
301 void FuSimpleOutlinerText::DoPasteUnformatted()
303 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpViewShell->GetActiveWindow() ) );
304 if (aDataHelper.GetTransferable().is())
306 OUString aText;
307 if (aDataHelper.GetString(SotClipboardFormatId::STRING, aText))
308 mpSimpleOutlinerView->GetViewByWindow(mpWindow)->InsertText(aText);
312 } // end of namespace sd
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */