Line data Source code
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 :
27 : #include "View.hxx"
28 : #include "DrawViewShell.hxx"
29 : #include "Window.hxx"
30 :
31 : #include "helpids.h"
32 :
33 : namespace sd {
34 :
35 : /**
36 : * Controller-Item for ruler
37 : */
38 344 : class RulerCtrlItem : public SfxControllerItem
39 : {
40 : Ruler &rRuler;
41 :
42 : protected:
43 : virtual void StateChanged( sal_uInt16 nSId, SfxItemState eState,
44 : const SfxPoolItem* pItem ) SAL_OVERRIDE;
45 :
46 : public:
47 : RulerCtrlItem(sal_uInt16 nId, Ruler& rRlr, SfxBindings& rBind);
48 : };
49 :
50 172 : RulerCtrlItem::RulerCtrlItem(sal_uInt16 _nId, Ruler& rRlr, SfxBindings& rBind)
51 : : SfxControllerItem(_nId, rBind)
52 172 : , rRuler(rRlr)
53 : {
54 172 : }
55 :
56 78 : void RulerCtrlItem::StateChanged( sal_uInt16 nSId, SfxItemState, const SfxPoolItem* pState )
57 : {
58 78 : switch( nSId )
59 : {
60 : case SID_RULER_NULL_OFFSET:
61 : {
62 78 : const SfxPointItem* pItem = dynamic_cast< const SfxPointItem* >(pState);
63 : DBG_ASSERT(pState == nullptr || pItem != nullptr, "SfxPointItem expected");
64 78 : if ( pItem )
65 78 : rRuler.SetNullOffset(pItem->GetValue());
66 : }
67 78 : break;
68 : }
69 78 : }
70 :
71 172 : 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 172 : , pDrViewShell(&rViewSh)
76 : {
77 172 : rBindings.EnterRegistrations();
78 172 : pCtrlItem = new RulerCtrlItem(SID_RULER_NULL_OFFSET, *this, rBindings);
79 172 : rBindings.LeaveRegistrations();
80 :
81 172 : if ( nWinStyle & WB_HSCROLL )
82 : {
83 86 : bHorz = true;
84 86 : SetHelpId( HID_SD_RULER_HORIZONTAL );
85 : }
86 : else
87 : {
88 86 : bHorz = false;
89 86 : SetHelpId( HID_SD_RULER_VERTICAL );
90 : }
91 172 : }
92 :
93 516 : Ruler::~Ruler()
94 : {
95 172 : disposeOnce();
96 344 : }
97 :
98 172 : void Ruler::dispose()
99 : {
100 172 : SfxBindings& rBindings = pCtrlItem->GetBindings();
101 172 : rBindings.EnterRegistrations();
102 172 : DELETEZ( pCtrlItem );
103 172 : rBindings.LeaveRegistrations();
104 172 : pSdWin.clear();
105 172 : SvxRuler::dispose();
106 172 : }
107 :
108 0 : void Ruler::MouseButtonDown(const MouseEvent& rMEvt)
109 : {
110 0 : Point aMPos = rMEvt.GetPosPixel();
111 0 : RulerType eType = GetType(aMPos);
112 :
113 0 : if ( !pDrViewShell->GetView()->IsTextEdit() &&
114 0 : rMEvt.IsLeft() && rMEvt.GetClicks() == 1 &&
115 0 : (eType == RULER_TYPE_DONTKNOW || eType == RULER_TYPE_OUTSIDE) )
116 : {
117 0 : pDrViewShell->StartRulerDrag(*this, rMEvt);
118 : }
119 : else
120 0 : SvxRuler::MouseButtonDown(rMEvt);
121 0 : }
122 :
123 0 : void Ruler::MouseMove(const MouseEvent& rMEvt)
124 : {
125 0 : SvxRuler::MouseMove(rMEvt);
126 0 : }
127 :
128 0 : void Ruler::MouseButtonUp(const MouseEvent& rMEvt)
129 : {
130 0 : SvxRuler::MouseButtonUp(rMEvt);
131 0 : }
132 :
133 78 : void Ruler::SetNullOffset(const Point& rOffset)
134 : {
135 : long nOffset;
136 :
137 78 : if ( bHorz ) nOffset = rOffset.X();
138 39 : else nOffset = rOffset.Y();
139 :
140 78 : SetNullOffsetLogic(nOffset);
141 78 : }
142 :
143 0 : void Ruler::Command(const CommandEvent& rCEvt)
144 : {
145 0 : if( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
146 0 : !pDrViewShell->GetView()->IsTextEdit() )
147 : {
148 0 : SvxRuler::Command( rCEvt );
149 : }
150 0 : }
151 :
152 0 : void Ruler::ExtraDown()
153 : {
154 0 : if( !pDrViewShell->GetView()->IsTextEdit() )
155 0 : SvxRuler::ExtraDown();
156 0 : }
157 :
158 66 : } // end of namespace sd
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|