LibreOffice Module sd (master) 1
fulinend.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <fulinend.hxx>
21#include <svx/xtable.hxx>
22#include <svx/svxdlg.hxx>
23#include <svx/svdobj.hxx>
24#include <svx/svdopath.hxx>
25#include <vcl/svapp.hxx>
26#include <vcl/weld.hxx>
27
28#include <strings.hrc>
29#include <helpids.h>
30#include <sdresid.hxx>
31#include <drawdoc.hxx>
32#include <View.hxx>
33#include <Window.hxx>
34#include <memory>
35
36namespace sd {
37
38
40 SdDrawDocument* pDoc, SfxRequest& rReq)
41 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
42{
43}
44
46{
47 rtl::Reference<FuPoor> xFunc( new FuLineEnd( pViewSh, pWin, pView, pDoc, rReq ) );
48 xFunc->DoExecute(rReq);
49 return xFunc;
50}
51
53{
54 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
55
56 if( rMarkList.GetMarkCount() != 1 )
57 return;
58
59 const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
60 const SdrObject* pNewObj;
61 rtl::Reference<SdrObject> pConvPolyObj;
62
63 if( dynamic_cast< const SdrPathObj *>( pObj ) != nullptr )
64 {
65 pNewObj = pObj;
66 }
67 else
68 {
70 pObj->TakeObjInfo( aInfoRec );
71
72 if( aInfoRec.bCanConvToPath &&
73 pObj->GetObjInventor() == SdrInventor::Default &&
74 pObj->GetObjIdentifier() != SdrObjKind::Group )
75 // bCanConvToPath is sal_True for group objects,
76 // but it crashes on ConvertToPathObj()!
77 {
78 pConvPolyObj = pObj->ConvertToPolyObj( true, false );
79 pNewObj = pConvPolyObj.get();
80
81 if( !pNewObj || dynamic_cast< const SdrPathObj *>( pNewObj ) == nullptr )
82 return; // Cancel, additional security, but it does not help
83 // for group objects
84 }
85 else return; // Cancel
86 }
87
88 const ::basegfx::B2DPolyPolygon aPolyPolygon = static_cast<const SdrPathObj*>(pNewObj)->GetPathPoly();
89
90 // Delete the created poly-object
91 pConvPolyObj.clear();
92
93 XLineEndListRef pLineEndList = mpDoc->GetLineEndList();
94
95 OUString aNewName( SdResId( STR_LINEEND ) );
96 OUString aDesc( SdResId( STR_DESC_LINEEND ) );
97 OUString aName;
98
99 ::tools::Long nCount = pLineEndList->Count();
100 ::tools::Long j = 1;
101 bool bDifferent = false;
102
103 while( !bDifferent )
104 {
105 aName = aNewName + " " + OUString::number(j++);
106 bDifferent = true;
107 for( ::tools::Long i = 0; i < nCount && bDifferent; i++ )
108 {
109 if( aName == pLineEndList->GetLineEnd( i )->GetName() )
110 bDifferent = false;
111 }
112 }
113
115 ScopedVclPtr<AbstractSvxNameDialog> pDlg( pFact->CreateSvxNameDialog( nullptr, aName, aDesc ) );
116
117 pDlg->SetEditHelpId( HID_SD_NAMEDIALOG_LINEEND );
118
119 if( pDlg->Execute() != RET_OK )
120 return;
121
122 pDlg->GetName( aName );
123 bDifferent = true;
124
125 for( ::tools::Long i = 0; i < nCount && bDifferent; i++ )
126 {
127 if( aName == pLineEndList->GetLineEnd( i )->GetName() )
128 bDifferent = false;
129 }
130
131 if( bDifferent )
132 {
133 pLineEndList->Insert(std::make_unique<XLineEndEntry>(aPolyPolygon, aName));
134 }
135 else
136 {
137 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(mpWindow ? mpWindow->GetFrameWeld() : nullptr,
138 VclMessageType::Warning, VclButtonsType::Ok,
139 SdResId(STR_WARN_NAME_DUPLICATE)));
140 xWarn->run();
141 }
142}
143
145{
146}
147
149{
150}
151
152} // end of namespace sd
153
154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
XLineEndListRef GetLineEndList() const
virtual SdrInventor GetObjInventor() const
rtl::Reference< SdrObject > ConvertToPolyObj(bool bBezier, bool bLineToArea) const
virtual SdrObjKind GetObjIdentifier() const
virtual void TakeObjInfo(SdrObjTransformInfoRec &rInfo) const
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
static SvxAbstractDialogFactory * Create()
virtual void Activate() override
activates the function
Definition: fulinend.cxx:144
virtual void Deactivate() override
deactivates the function
Definition: fulinend.cxx:148
virtual void DoExecute(SfxRequest &rReq) override
Definition: fulinend.cxx:52
FuLineEnd(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fulinend.cxx:39
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fulinend.cxx:45
Base class for all functions.
Definition: fupoor.hxx:48
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
VclPtr< ::sd::Window > mpWindow
Definition: fupoor.hxx:146
::sd::View * mpView
Definition: fupoor.hxx:144
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
int nCount
constexpr OUStringLiteral HID_SD_NAMEDIALOG_LINEEND
Definition: helpids.h:42
OUString aName
int i
long Long
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
RET_OK