1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <fuconuno.hxx>
21 #include <rtl/ustring.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <sfx2/request.hxx>
25 #include <svl/intitem.hxx>
26 #include <svx/svxids.hrc>
27 #include <vcl/ptrstyle.hxx>
29 #include <ViewShell.hxx>
32 #include <ViewShellBase.hxx>
33 #include <ToolBarManager.hxx>
34 #include <unokywds.hxx>
40 FuConstructUnoControl::FuConstructUnoControl (
46 : FuConstruct(pViewSh
, pWin
, pView
, pDoc
, rReq
)
47 , nInventor(SdrInventor::Unknown
)
52 rtl::Reference
<FuPoor
> FuConstructUnoControl::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool bPermanent
)
54 FuConstructUnoControl
* pFunc
;
55 rtl::Reference
<FuPoor
> xFunc( pFunc
= new FuConstructUnoControl( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
56 xFunc
->DoExecute(rReq
);
57 pFunc
->SetPermanent(bPermanent
);
61 void FuConstructUnoControl::DoExecute( SfxRequest
& rReq
)
63 FuConstruct::DoExecute( rReq
);
65 const SfxUInt32Item
* pInventorItem
= rReq
.GetArg
<SfxUInt32Item
>(SID_FM_CONTROL_INVENTOR
);
66 const SfxUInt16Item
* pIdentifierItem
= rReq
.GetArg
<SfxUInt16Item
>(SID_FM_CONTROL_IDENTIFIER
);
68 nInventor
= static_cast<SdrInventor
>(pInventorItem
->GetValue());
70 nIdentifier
= pIdentifierItem
->GetValue();
72 mpViewShell
->GetViewShellBase().GetToolBarManager()->SetToolBar(
73 ToolBarManager::ToolBarGroup::Function
,
74 ToolBarManager::msDrawingObjectToolBar
);
77 bool FuConstructUnoControl::MouseButtonDown(const MouseEvent
& rMEvt
)
79 bool bReturn
= FuConstruct::MouseButtonDown(rMEvt
);
81 if ( rMEvt
.IsLeft() && !mpView
->IsAction() )
83 Point
aPnt( mpWindow
->PixelToLogic( rMEvt
.GetPosPixel() ) );
84 mpWindow
->CaptureMouse();
85 sal_uInt16 nDrgLog
= sal_uInt16 ( mpWindow
->PixelToLogic(Size(DRGPIX
,0)).Width() );
86 mpView
->BegCreateObj(aPnt
, nullptr, nDrgLog
);
92 bool FuConstructUnoControl::MouseButtonUp(const MouseEvent
& rMEvt
)
96 if ( mpView
->IsCreateObj() && rMEvt
.IsLeft() )
98 mpView
->EndCreateObj(SdrCreateCmd::ForceEnd
);
102 bReturn
= (FuConstruct::MouseButtonUp(rMEvt
) || bReturn
);
105 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SfxCallMode::ASYNCHRON
);
110 void FuConstructUnoControl::Activate()
112 mpView
->SetCurrentObj( nIdentifier
, nInventor
);
114 aNewPointer
= PointerStyle::DrawRect
;
115 aOldPointer
= mpWindow
->GetPointer();
116 mpWindow
->SetPointer( aNewPointer
);
118 aOldLayer
= mpView
->GetActiveLayer();
119 mpView
->SetActiveLayer(sUNO_LayerName_controls
);
121 FuConstruct::Activate();
124 void FuConstructUnoControl::Deactivate()
126 FuConstruct::Deactivate();
127 mpView
->SetActiveLayer( aOldLayer
);
128 mpWindow
->SetPointer( aOldPointer
);
131 SdrObjectUniquePtr
FuConstructUnoControl::CreateDefaultObject(const sal_uInt16
, const ::tools::Rectangle
& rRectangle
)
133 // case SID_FM_CREATE_CONTROL:
135 SdrObjectUniquePtr
pObj(SdrObjFactory::MakeNewObject(
136 mpView
->getSdrModelFromSdrView(),
137 mpView
->GetCurrentObjInventor(),
138 mpView
->GetCurrentObjIdentifier()));
142 pObj
->SetLogicRect(rRectangle
);
148 } // end of namespace sd
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */