LibreOffice Module sd (master) 1
sdruler.cxx
Go to the documentation of this file.
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 <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>
27
28#include <View.hxx>
29#include <DrawViewShell.hxx>
30#include <Window.hxx>
31
32#include <helpids.h>
33
34namespace sd {
35
40{
42
43 protected:
44 virtual void StateChangedAtToolBoxControl( sal_uInt16 nSId, SfxItemState eState,
45 const SfxPoolItem* pItem ) override;
46
47 public:
48 RulerCtrlItem(Ruler& rRlr, SfxBindings& rBind);
49};
50
52: SfxControllerItem(SID_RULER_NULL_OFFSET, rBind)
53, rRuler(rRlr)
54{
55}
56
58{
59 switch( nSId )
60 {
61 case SID_RULER_NULL_OFFSET:
62 {
63 const SfxPointItem* pItem = dynamic_cast< const SfxPointItem* >(pState);
64 DBG_ASSERT(pState == nullptr || pItem != nullptr, "SfxPointItem expected");
65 if ( pItem )
67 }
68 break;
69 }
70}
71
72Ruler::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)
75{
76 rBindings.EnterRegistrations();
77 pCtrlItem.reset( new RulerCtrlItem(*this, rBindings) );
78 rBindings.LeaveRegistrations();
79
80 if ( nWinStyle & WB_HSCROLL )
81 {
82 bHorz = true;
84 }
85 else
86 {
87 bHorz = false;
89 }
90}
91
93{
94 disposeOnce();
95}
96
98{
99 SfxBindings& rBindings = pCtrlItem->GetBindings();
100 rBindings.EnterRegistrations();
101 pCtrlItem.reset();
102 rBindings.LeaveRegistrations();
104}
105
107{
108 Point aMPos = rMEvt.GetPosPixel();
109 RulerType eType = GetRulerType(aMPos);
110
111 if ( !pDrViewShell->GetView()->IsTextEdit() &&
112 rMEvt.IsLeft() && rMEvt.GetClicks() == 1 &&
113 (eType == RulerType::DontKnow || eType == RulerType::Outside) )
114 {
115 pDrViewShell->StartRulerDrag(*this, rMEvt);
116 }
117 else
118 SvxRuler::MouseButtonDown(rMEvt);
119}
120
121void Ruler::SetNullOffset(const Point& rOffset)
122{
123 ::tools::Long nOffset;
124
125 if ( bHorz ) nOffset = rOffset.X();
126 else nOffset = rOffset.Y();
127
128 SetNullOffsetLogic(nOffset);
129}
130
131void Ruler::Command(const CommandEvent& rCEvt)
132{
133 if( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
135 {
136 SvxRuler::Command( rCEvt );
137 }
138}
139
141{
142 if( !pDrViewShell->GetView()->IsTextEdit() )
144}
145
146} // end of namespace sd
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CommandEventId GetCommand() const
sal_uInt16 GetClicks() const
const Point & GetPosPixel() const
bool IsLeft() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
virtual bool IsTextEdit() const final override
void LeaveRegistrations(std::string_view pFile={}, int nLine=0)
sal_uInt16 EnterRegistrations(std::string_view pFile={}, int nLine=0)
const Point & GetValue() const
virtual void Command(const CommandEvent &rCEvt) override
virtual void ExtraDown() override
void SetNullOffsetLogic(tools::Long lOff)
virtual void dispose() override
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
void StartRulerDrag(const Ruler &rRuler, const MouseEvent &rMEvt)
Start with Drag from ruler (helper lines, origin)
Definition: drviews4.cxx:271
Controller-Item for ruler.
Definition: sdruler.cxx:40
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSId, SfxItemState eState, const SfxPoolItem *pItem) override
Definition: sdruler.cxx:57
RulerCtrlItem(Ruler &rRlr, SfxBindings &rBind)
Definition: sdruler.cxx:51
Ruler & rRuler
Definition: sdruler.cxx:41
Ruler(DrawViewShell &rViewSh, vcl::Window *pParent, ::sd::Window *pWin, SvxRulerSupportFlags nRulerFlags, SfxBindings &rBindings, WinBits nWinStyle)
Definition: sdruler.cxx:72
virtual void Command(const CommandEvent &rCEvt) override
Definition: sdruler.cxx:131
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: sdruler.cxx:106
virtual ~Ruler() override
Definition: sdruler.cxx:92
virtual void dispose() override
Definition: sdruler.cxx:97
virtual void ExtraDown() override
Definition: sdruler.cxx:140
std::unique_ptr< RulerCtrlItem > pCtrlItem
Definition: Ruler.hxx:52
DrawViewShell * pDrViewShell
Definition: Ruler.hxx:51
bool bHorz
Definition: Ruler.hxx:53
void SetNullOffset(const Point &rOffset)
Definition: sdruler.cxx:121
::sd::View * GetView() const
Definition: ViewShell.hxx:144
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
#define DBG_ASSERT(sCon, aError)
virtual void SetHelpId(const OUString &) override
DocumentType eType
constexpr OUStringLiteral HID_SD_RULER_HORIZONTAL
Definition: helpids.h:59
constexpr OUStringLiteral HID_SD_RULER_VERTICAL
Definition: helpids.h:60
long Long
SfxItemState
SvxRulerSupportFlags
RulerType
sal_Int64 WinBits
WinBits const WB_HSCROLL