xref: /aoo41x/main/sd/source/ui/view/sdruler.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "Ruler.hxx"
32 #include <svl/ptitem.hxx>
33 #include <svx/ruler.hxx>
34 #ifndef _SVXIDS_HXX //autogen
35 #include <svx/svxids.hrc>
36 #endif
37 #include <sfx2/ctrlitem.hxx>
38 #include <sfx2/bindings.hxx>
39 
40 
41 #include "View.hxx"
42 #include "DrawViewShell.hxx"
43 #include "Window.hxx"
44 
45 #include "helpids.h"
46 
47 namespace sd {
48 
49 /*************************************************************************
50 |*
51 |* Controller-Item fuer Ruler
52 |*
53 \************************************************************************/
54 
55 class RulerCtrlItem : public SfxControllerItem
56 {
57 	Ruler &rRuler;
58 
59  protected:
60 	virtual void StateChanged( sal_uInt16 nSId, SfxItemState eState,
61 								const SfxPoolItem* pItem );
62 
63  public:
64 	RulerCtrlItem(sal_uInt16 nId, Ruler& rRlr, SfxBindings& rBind);
65 };
66 
67 /*************************************************************************
68 |*
69 \************************************************************************/
70 
71 RulerCtrlItem::RulerCtrlItem(sal_uInt16 _nId, Ruler& rRlr, SfxBindings& rBind)
72 : SfxControllerItem(_nId, rBind)
73 , rRuler(rRlr)
74 {
75 }
76 
77 
78 /*************************************************************************
79 |*
80 \************************************************************************/
81 
82 void RulerCtrlItem::StateChanged( sal_uInt16 nSId, SfxItemState, const SfxPoolItem* pState )
83 {
84 	switch( nSId )
85 	{
86 		case SID_RULER_NULL_OFFSET:
87 		{
88 			const SfxPointItem* pItem = dynamic_cast< const SfxPointItem* >(pState);
89 			DBG_ASSERT(pState ? pItem != NULL : sal_True, "SfxPointItem erwartet");
90 			if ( pItem )
91 				rRuler.SetNullOffset(pItem->GetValue());
92 		}
93 		break;
94 	}
95 }
96 
97 
98 /*************************************************************************
99 |*
100 |* Konstruktor
101 |*
102 \************************************************************************/
103 
104 Ruler::Ruler( DrawViewShell& rViewSh, ::Window* pParent, ::sd::Window* pWin, sal_uInt16 nRulerFlags,  SfxBindings& rBindings, WinBits nWinStyle)
105 : SvxRuler(pParent, pWin, nRulerFlags, rBindings, nWinStyle)
106 , pSdWin(pWin)
107 , pDrViewShell(&rViewSh)
108 {
109 	rBindings.EnterRegistrations();
110 	pCtrlItem = new RulerCtrlItem(SID_RULER_NULL_OFFSET, *this, rBindings);
111 	rBindings.LeaveRegistrations();
112 
113 	if ( nWinStyle & WB_HSCROLL )
114 	{
115 		bHorz = sal_True;
116 		SetHelpId( HID_SD_RULER_HORIZONTAL );
117 	}
118 	else
119 	{
120 		bHorz = sal_False;
121 		SetHelpId( HID_SD_RULER_VERTICAL );
122 	}
123 }
124 
125 /*************************************************************************
126 |*
127 |* Destruktor
128 |*
129 \************************************************************************/
130 
131 Ruler::~Ruler()
132 {
133 	SfxBindings& rBindings = pCtrlItem->GetBindings();
134 	rBindings.EnterRegistrations();
135 	delete pCtrlItem;
136 	rBindings.LeaveRegistrations();
137 }
138 
139 /*************************************************************************
140 |*
141 |* MouseButtonDown-Handler
142 |*
143 \************************************************************************/
144 
145 void Ruler::MouseButtonDown(const MouseEvent& rMEvt)
146 {
147 	Point aMPos = rMEvt.GetPosPixel();
148 	RulerType eType = GetType(aMPos);
149 
150 	if ( !pDrViewShell->GetView()->IsTextEdit() &&
151 		rMEvt.IsLeft() && rMEvt.GetClicks() == 1 &&
152 		(eType == RULER_TYPE_DONTKNOW || eType == RULER_TYPE_OUTSIDE) )
153 	{
154 		pDrViewShell->StartRulerDrag(*this, rMEvt);
155 	}
156 	else
157 		SvxRuler::MouseButtonDown(rMEvt);
158 }
159 
160 /*************************************************************************
161 |*
162 |* MouseMove-Handler
163 |*
164 \************************************************************************/
165 
166 void Ruler::MouseMove(const MouseEvent& rMEvt)
167 {
168 	SvxRuler::MouseMove(rMEvt);
169 }
170 
171 /*************************************************************************
172 |*
173 |* MouseButtonUp-Handler
174 |*
175 \************************************************************************/
176 
177 void Ruler::MouseButtonUp(const MouseEvent& rMEvt)
178 {
179 	SvxRuler::MouseButtonUp(rMEvt);
180 }
181 
182 /*************************************************************************
183 |*
184 |* NullOffset setzen
185 |*
186 \************************************************************************/
187 
188 void Ruler::SetNullOffset(const Point& rOffset)
189 {
190 	long nOffset;
191 
192 	if ( bHorz )	nOffset = rOffset.X();
193 	else			nOffset = rOffset.Y();
194 
195 	SetNullOffsetLogic(nOffset);
196 }
197 
198 /*************************************************************************
199 |*
200 |* Command event
201 |*
202 \************************************************************************/
203 
204 void Ruler::Command(const CommandEvent& rCEvt)
205 {
206 	if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
207 		!pDrViewShell->GetView()->IsTextEdit() )
208 	{
209 		SvxRuler::Command( rCEvt );
210 	}
211 }
212 
213 /*************************************************************************
214 |*
215 |* ExtraDown
216 |*
217 \************************************************************************/
218 
219 void Ruler::ExtraDown()
220 {
221 	if( !pDrViewShell->GetView()->IsTextEdit() )
222 		SvxRuler::ExtraDown();
223 }
224 
225 } // end of namespace sd
226 
227