Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sc/source/ui/drawfunc/fuconuno.cxx
Line
Count
Source (jump to first uncovered line)
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 <fuconuno.hxx>
21
#include <tabvwsh.hxx>
22
#include <drawview.hxx>
23
24
#include <svx/svxids.hrc>
25
26
FuConstUnoControl::FuConstUnoControl(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP,
27
                                     SdrModel& rDoc, const SfxRequest& rReq)
28
0
    : FuConstruct(rViewSh, pWin, pViewP, rDoc, rReq)
29
0
    , nInventor(SdrInventor::Unknown)
30
0
    , nIdentifier(SdrObjKind::NONE)
31
0
{
32
0
    const SfxUInt32Item* pInventorItem = rReq.GetArg<SfxUInt32Item>(SID_FM_CONTROL_INVENTOR);
33
0
    const SfxUInt16Item* pIdentifierItem = rReq.GetArg<SfxUInt16Item>(SID_FM_CONTROL_IDENTIFIER);
34
0
    if( pInventorItem )
35
0
        nInventor = static_cast<SdrInventor>(pInventorItem->GetValue());
36
0
    if( pIdentifierItem )
37
0
        nIdentifier = static_cast<SdrObjKind>(pIdentifierItem->GetValue());
38
0
}
39
40
FuConstUnoControl::~FuConstUnoControl()
41
0
{
42
0
}
43
44
bool FuConstUnoControl::MouseButtonDown(const MouseEvent& rMEvt)
45
0
{
46
    // remember button state for creation of own MouseEvents
47
0
    SetMouseButtonCode(rMEvt.GetButtons());
48
49
0
    bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
50
51
0
    if ( rMEvt.IsLeft() && !pView->IsAction() )
52
0
    {
53
0
        Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
54
0
        pWindow->CaptureMouse();
55
0
        pView->BegCreateObj(aPnt);
56
0
        bReturn = true;
57
0
    }
58
0
    return bReturn;
59
0
}
60
61
bool FuConstUnoControl::MouseButtonUp(const MouseEvent& rMEvt)
62
0
{
63
    // remember button state for creation of own MouseEvents
64
0
    SetMouseButtonCode(rMEvt.GetButtons());
65
66
0
    bool bReturn = false;
67
68
0
    if ( pView->IsCreateObj() && rMEvt.IsLeft() )
69
0
    {
70
0
        pView->EndCreateObj(SdrCreateCmd::ForceEnd);
71
0
        bReturn = true;
72
0
    }
73
0
    return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
74
0
}
75
76
void FuConstUnoControl::Activate()
77
0
{
78
0
    pView->SetCurrentObj( nIdentifier, nInventor );
79
80
0
    aNewPointer = PointerStyle::DrawRect;
81
0
    aOldPointer = pWindow->GetPointer();
82
0
    rViewShell.SetActivePointer( aNewPointer );
83
84
0
    SdrLayer* pLayer = pView->GetModel().GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
85
0
    if (pLayer)
86
0
        pView->SetActiveLayer( pLayer->GetName() );
87
88
0
    FuConstruct::Activate();
89
0
}
90
91
void FuConstUnoControl::Deactivate()
92
0
{
93
0
    FuConstruct::Deactivate();
94
95
0
    SdrLayer* pLayer = pView->GetModel().GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
96
0
    if (pLayer)
97
0
        pView->SetActiveLayer( pLayer->GetName() );
98
99
0
    rViewShell.SetActivePointer( aOldPointer );
100
0
}
101
102
// Create default drawing objects via keyboard
103
rtl::Reference<SdrObject> FuConstUnoControl::CreateDefaultObject(const sal_uInt16 /* nID */, const tools::Rectangle& rRectangle)
104
0
{
105
    // case SID_FM_CREATE_CONTROL:
106
107
0
    rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
108
0
        rDrDoc,
109
0
        pView->GetCurrentObjInventor(),
110
0
        pView->GetCurrentObjIdentifier()));
111
112
0
    if(pObj)
113
0
    {
114
0
        pObj->SetLogicRect(rRectangle);
115
        // tdf#140252 Controls are always on layer "controls"
116
0
        pObj->NbcSetLayer(SC_LAYER_CONTROLS);
117
0
    }
118
119
0
    return pObj;
120
0
}
121
122
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */