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 .
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>
29 #include <DrawViewShell.hxx>
37 * Controller-Item for ruler
39 class RulerCtrlItem
: public SfxControllerItem
44 virtual void StateChangedAtToolBoxControl( sal_uInt16 nSId
, SfxItemState eState
,
45 const SfxPoolItem
* pItem
) override
;
48 RulerCtrlItem(Ruler
& rRlr
, SfxBindings
& rBind
);
51 RulerCtrlItem::RulerCtrlItem(Ruler
& rRlr
, SfxBindings
& rBind
)
52 : SfxControllerItem(SID_RULER_NULL_OFFSET
, rBind
)
57 void RulerCtrlItem::StateChangedAtToolBoxControl( sal_uInt16 nSId
, SfxItemState
, const SfxPoolItem
* pState
)
61 case SID_RULER_NULL_OFFSET
:
63 const SfxPointItem
* pItem
= dynamic_cast< const SfxPointItem
* >(pState
);
64 DBG_ASSERT(pState
== nullptr || pItem
!= nullptr, "SfxPointItem expected");
66 rRuler
.SetNullOffset(pItem
->GetValue());
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
)
83 SetHelpId( HID_SD_RULER_HORIZONTAL
);
88 SetHelpId( HID_SD_RULER_VERTICAL
);
99 SfxBindings
& rBindings
= pCtrlItem
->GetBindings();
100 rBindings
.EnterRegistrations();
102 rBindings
.LeaveRegistrations();
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
);
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: */