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>
28 #include "DrawViewShell.hxx"
36 * Controller-Item for ruler
38 class RulerCtrlItem
: public SfxControllerItem
43 virtual void StateChanged( sal_uInt16 nSId
, SfxItemState eState
,
44 const SfxPoolItem
* pItem
) SAL_OVERRIDE
;
47 RulerCtrlItem(sal_uInt16 nId
, Ruler
& rRlr
, SfxBindings
& rBind
);
50 RulerCtrlItem::RulerCtrlItem(sal_uInt16 _nId
, Ruler
& rRlr
, SfxBindings
& rBind
)
51 : SfxControllerItem(_nId
, rBind
)
56 void RulerCtrlItem::StateChanged( sal_uInt16 nSId
, SfxItemState
, const SfxPoolItem
* pState
)
60 case SID_RULER_NULL_OFFSET
:
62 const SfxPointItem
* pItem
= dynamic_cast< const SfxPointItem
* >(pState
);
63 DBG_ASSERT(pState
== nullptr || pItem
!= nullptr, "SfxPointItem expected");
65 rRuler
.SetNullOffset(pItem
->GetValue());
71 Ruler::Ruler( DrawViewShell
& rViewSh
, vcl::Window
* pParent
, ::sd::Window
* pWin
, SvxRulerSupportFlags nRulerFlags
, SfxBindings
& rBindings
, WinBits nWinStyle
)
72 : SvxRuler(pParent
, pWin
, nRulerFlags
, rBindings
, nWinStyle
)
75 , pDrViewShell(&rViewSh
)
77 rBindings
.EnterRegistrations();
78 pCtrlItem
= new RulerCtrlItem(SID_RULER_NULL_OFFSET
, *this, rBindings
);
79 rBindings
.LeaveRegistrations();
81 if ( nWinStyle
& WB_HSCROLL
)
84 SetHelpId( HID_SD_RULER_HORIZONTAL
);
89 SetHelpId( HID_SD_RULER_VERTICAL
);
100 SfxBindings
& rBindings
= pCtrlItem
->GetBindings();
101 rBindings
.EnterRegistrations();
102 DELETEZ( pCtrlItem
);
103 rBindings
.LeaveRegistrations();
108 void Ruler::MouseButtonDown(const MouseEvent
& rMEvt
)
110 Point aMPos
= rMEvt
.GetPosPixel();
111 RulerType eType
= GetType(aMPos
);
113 if ( !pDrViewShell
->GetView()->IsTextEdit() &&
114 rMEvt
.IsLeft() && rMEvt
.GetClicks() == 1 &&
115 (eType
== RULER_TYPE_DONTKNOW
|| eType
== RULER_TYPE_OUTSIDE
) )
117 pDrViewShell
->StartRulerDrag(*this, rMEvt
);
120 SvxRuler::MouseButtonDown(rMEvt
);
123 void Ruler::MouseMove(const MouseEvent
& rMEvt
)
125 SvxRuler::MouseMove(rMEvt
);
128 void Ruler::MouseButtonUp(const MouseEvent
& rMEvt
)
130 SvxRuler::MouseButtonUp(rMEvt
);
133 void Ruler::SetNullOffset(const Point
& rOffset
)
137 if ( bHorz
) nOffset
= rOffset
.X();
138 else nOffset
= rOffset
.Y();
140 SetNullOffsetLogic(nOffset
);
143 void Ruler::Command(const CommandEvent
& rCEvt
)
145 if( rCEvt
.GetCommand() == CommandEventId::ContextMenu
&&
146 !pDrViewShell
->GetView()->IsTextEdit() )
148 SvxRuler::Command( rCEvt
);
152 void Ruler::ExtraDown()
154 if( !pDrViewShell
->GetView()->IsTextEdit() )
155 SvxRuler::ExtraDown();
158 } // end of namespace sd
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */