cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / sdruler.cxx
blob571ffb37f8eb1cd3045dc3724de4733f70f70259
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 <Ruler.hxx>
21 #include <svl/ptitem.hxx>
22 #include <svx/ruler.hxx>
23 #include <svx/svxids.hrc>
24 #include <sfx2/ctrlitem.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <vcl/commandevent.hxx>
28 #include <View.hxx>
29 #include <DrawViewShell.hxx>
30 #include <Window.hxx>
32 #include <helpids.h>
34 namespace sd {
36 /**
37 * Controller-Item for ruler
39 class RulerCtrlItem : public SfxControllerItem
41 Ruler &rRuler;
43 protected:
44 virtual void StateChangedAtToolBoxControl( sal_uInt16 nSId, SfxItemState eState,
45 const SfxPoolItem* pItem ) override;
47 public:
48 RulerCtrlItem(Ruler& rRlr, SfxBindings& rBind);
51 RulerCtrlItem::RulerCtrlItem(Ruler& rRlr, SfxBindings& rBind)
52 : SfxControllerItem(SID_RULER_NULL_OFFSET, rBind)
53 , rRuler(rRlr)
57 void RulerCtrlItem::StateChangedAtToolBoxControl( sal_uInt16 nSId, SfxItemState, const SfxPoolItem* pState )
59 switch( nSId )
61 case SID_RULER_NULL_OFFSET:
63 const SfxPointItem* pItem = dynamic_cast< const SfxPointItem* >(pState);
64 DBG_ASSERT(pState == nullptr || pItem != nullptr, "SfxPointItem expected");
65 if ( pItem )
66 rRuler.SetNullOffset(pItem->GetValue());
68 break;
72 Ruler::Ruler( DrawViewShell& rViewSh, vcl::Window* pParent, ::sd::Window* pWin, SvxRulerSupportFlags nRulerFlags, SfxBindings& rBindings, WinBits nWinStyle)
73 : SvxRuler(pParent, pWin, nRulerFlags, rBindings, nWinStyle)
74 , pDrViewShell(&rViewSh)
76 rBindings.EnterRegistrations();
77 pCtrlItem.reset( new RulerCtrlItem(*this, rBindings) );
78 rBindings.LeaveRegistrations();
80 if ( nWinStyle & WB_HSCROLL )
82 bHorz = true;
83 SetHelpId( HID_SD_RULER_HORIZONTAL );
85 else
87 bHorz = false;
88 SetHelpId( HID_SD_RULER_VERTICAL );
92 Ruler::~Ruler()
94 disposeOnce();
97 void Ruler::dispose()
99 SfxBindings& rBindings = pCtrlItem->GetBindings();
100 rBindings.EnterRegistrations();
101 pCtrlItem.reset();
102 rBindings.LeaveRegistrations();
103 SvxRuler::dispose();
106 void Ruler::MouseButtonDown(const MouseEvent& rMEvt)
108 Point aMPos = rMEvt.GetPosPixel();
109 RulerType eType = GetRulerType(aMPos);
111 if ( !pDrViewShell->GetView()->IsTextEdit() &&
112 rMEvt.IsLeft() && rMEvt.GetClicks() == 1 &&
113 (eType == RulerType::DontKnow || eType == RulerType::Outside) )
115 pDrViewShell->StartRulerDrag(*this, rMEvt);
117 else
118 SvxRuler::MouseButtonDown(rMEvt);
121 void Ruler::SetNullOffset(const Point& rOffset)
123 ::tools::Long nOffset;
125 if ( bHorz ) nOffset = rOffset.X();
126 else nOffset = rOffset.Y();
128 SetNullOffsetLogic(nOffset);
131 void Ruler::Command(const CommandEvent& rCEvt)
133 if( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
134 !pDrViewShell->GetView()->IsTextEdit() )
136 SvxRuler::Command( rCEvt );
140 void Ruler::ExtraDown()
142 if( !pDrViewShell->GetView()->IsTextEdit() )
143 SvxRuler::ExtraDown();
146 } // end of namespace sd
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */