bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / sdruler.cxx
blob3c2b12a4ecff25b0470545d1a185b44ff89b2509
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>
27 #include "View.hxx"
28 #include "DrawViewShell.hxx"
29 #include "Window.hxx"
31 #include "helpids.h"
33 namespace sd {
35 /**
36 * Controller-Item for ruler
38 class RulerCtrlItem : public SfxControllerItem
40 Ruler &rRuler;
42 protected:
43 virtual void StateChanged( sal_uInt16 nSId, SfxItemState eState,
44 const SfxPoolItem* pItem ) SAL_OVERRIDE;
46 public:
47 RulerCtrlItem(sal_uInt16 nId, Ruler& rRlr, SfxBindings& rBind);
50 RulerCtrlItem::RulerCtrlItem(sal_uInt16 _nId, Ruler& rRlr, SfxBindings& rBind)
51 : SfxControllerItem(_nId, rBind)
52 , rRuler(rRlr)
56 void RulerCtrlItem::StateChanged( sal_uInt16 nSId, SfxItemState, const SfxPoolItem* pState )
58 switch( nSId )
60 case SID_RULER_NULL_OFFSET:
62 const SfxPointItem* pItem = dynamic_cast< const SfxPointItem* >(pState);
63 DBG_ASSERT(pState == nullptr || pItem != nullptr, "SfxPointItem expected");
64 if ( pItem )
65 rRuler.SetNullOffset(pItem->GetValue());
67 break;
71 Ruler::Ruler( DrawViewShell& rViewSh, vcl::Window* pParent, ::sd::Window* pWin, SvxRulerSupportFlags nRulerFlags, SfxBindings& rBindings, WinBits nWinStyle)
72 : SvxRuler(pParent, pWin, nRulerFlags, rBindings, nWinStyle)
73 , pSdView(NULL)
74 , pSdWin(pWin)
75 , pDrViewShell(&rViewSh)
77 rBindings.EnterRegistrations();
78 pCtrlItem = new RulerCtrlItem(SID_RULER_NULL_OFFSET, *this, rBindings);
79 rBindings.LeaveRegistrations();
81 if ( nWinStyle & WB_HSCROLL )
83 bHorz = true;
84 SetHelpId( HID_SD_RULER_HORIZONTAL );
86 else
88 bHorz = false;
89 SetHelpId( HID_SD_RULER_VERTICAL );
93 Ruler::~Ruler()
95 disposeOnce();
98 void Ruler::dispose()
100 SfxBindings& rBindings = pCtrlItem->GetBindings();
101 rBindings.EnterRegistrations();
102 DELETEZ( pCtrlItem );
103 rBindings.LeaveRegistrations();
104 pSdWin.clear();
105 SvxRuler::dispose();
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);
119 else
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)
135 long nOffset;
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: */