xref: /aoo4110/main/sd/source/ui/view/sdruler.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "Ruler.hxx"
28 #include <svl/ptitem.hxx>
29 #include <svx/ruler.hxx>
30 #ifndef _SVXIDS_HXX //autogen
31 #include <svx/svxids.hrc>
32 #endif
33 #include <sfx2/ctrlitem.hxx>
34 #include <sfx2/bindings.hxx>
35 
36 
37 #include "View.hxx"
38 #include "DrawViewShell.hxx"
39 #include "Window.hxx"
40 
41 #include "helpids.h"
42 
43 namespace sd {
44 
45 /*************************************************************************
46 |*
47 |* Controller-Item fuer Ruler
48 |*
49 \************************************************************************/
50 
51 class RulerCtrlItem : public SfxControllerItem
52 {
53 	Ruler &rRuler;
54 
55  protected:
56 	virtual void StateChanged( sal_uInt16 nSId, SfxItemState eState,
57 								const SfxPoolItem* pItem );
58 
59  public:
60 	RulerCtrlItem(sal_uInt16 nId, Ruler& rRlr, SfxBindings& rBind);
61 };
62 
63 /*************************************************************************
64 |*
65 \************************************************************************/
66 
RulerCtrlItem(sal_uInt16 _nId,Ruler & rRlr,SfxBindings & rBind)67 RulerCtrlItem::RulerCtrlItem(sal_uInt16 _nId, Ruler& rRlr, SfxBindings& rBind)
68 : SfxControllerItem(_nId, rBind)
69 , rRuler(rRlr)
70 {
71 }
72 
73 
74 /*************************************************************************
75 |*
76 \************************************************************************/
77 
StateChanged(sal_uInt16 nSId,SfxItemState,const SfxPoolItem * pState)78 void RulerCtrlItem::StateChanged( sal_uInt16 nSId, SfxItemState, const SfxPoolItem* pState )
79 {
80 	switch( nSId )
81 	{
82 		case SID_RULER_NULL_OFFSET:
83 		{
84 			const SfxPointItem* pItem = dynamic_cast< const SfxPointItem* >(pState);
85 			DBG_ASSERT(pState ? pItem != NULL : sal_True, "SfxPointItem erwartet");
86 			if ( pItem )
87 				rRuler.SetNullOffset(pItem->GetValue());
88 		}
89 		break;
90 	}
91 }
92 
93 
94 /*************************************************************************
95 |*
96 |* Konstruktor
97 |*
98 \************************************************************************/
99 
Ruler(DrawViewShell & rViewSh,::Window * pParent,::sd::Window * pWin,sal_uInt16 nRulerFlags,SfxBindings & rBindings,WinBits nWinStyle)100 Ruler::Ruler( DrawViewShell& rViewSh, ::Window* pParent, ::sd::Window* pWin, sal_uInt16 nRulerFlags,  SfxBindings& rBindings, WinBits nWinStyle)
101 : SvxRuler(pParent, pWin, nRulerFlags, rBindings, nWinStyle)
102 , pSdWin(pWin)
103 , pDrViewShell(&rViewSh)
104 {
105 	rBindings.EnterRegistrations();
106 	pCtrlItem = new RulerCtrlItem(SID_RULER_NULL_OFFSET, *this, rBindings);
107 	rBindings.LeaveRegistrations();
108 
109 	if ( nWinStyle & WB_HSCROLL )
110 	{
111 		bHorz = sal_True;
112 		SetHelpId( HID_SD_RULER_HORIZONTAL );
113 	}
114 	else
115 	{
116 		bHorz = sal_False;
117 		SetHelpId( HID_SD_RULER_VERTICAL );
118 	}
119 }
120 
121 /*************************************************************************
122 |*
123 |* Destruktor
124 |*
125 \************************************************************************/
126 
~Ruler()127 Ruler::~Ruler()
128 {
129 	SfxBindings& rBindings = pCtrlItem->GetBindings();
130 	rBindings.EnterRegistrations();
131 	delete pCtrlItem;
132 	rBindings.LeaveRegistrations();
133 }
134 
135 /*************************************************************************
136 |*
137 |* MouseButtonDown-Handler
138 |*
139 \************************************************************************/
140 
MouseButtonDown(const MouseEvent & rMEvt)141 void Ruler::MouseButtonDown(const MouseEvent& rMEvt)
142 {
143 	Point aMPos = rMEvt.GetPosPixel();
144 	RulerType eType = GetType(aMPos);
145 
146 	if ( !pDrViewShell->GetView()->IsTextEdit() &&
147 		rMEvt.IsLeft() && rMEvt.GetClicks() == 1 &&
148 		(eType == RULER_TYPE_DONTKNOW || eType == RULER_TYPE_OUTSIDE) )
149 	{
150 		pDrViewShell->StartRulerDrag(*this, rMEvt);
151 	}
152 	else
153 		SvxRuler::MouseButtonDown(rMEvt);
154 }
155 
156 /*************************************************************************
157 |*
158 |* MouseMove-Handler
159 |*
160 \************************************************************************/
161 
MouseMove(const MouseEvent & rMEvt)162 void Ruler::MouseMove(const MouseEvent& rMEvt)
163 {
164 	SvxRuler::MouseMove(rMEvt);
165 }
166 
167 /*************************************************************************
168 |*
169 |* MouseButtonUp-Handler
170 |*
171 \************************************************************************/
172 
MouseButtonUp(const MouseEvent & rMEvt)173 void Ruler::MouseButtonUp(const MouseEvent& rMEvt)
174 {
175 	SvxRuler::MouseButtonUp(rMEvt);
176 }
177 
178 /*************************************************************************
179 |*
180 |* NullOffset setzen
181 |*
182 \************************************************************************/
183 
SetNullOffset(const Point & rOffset)184 void Ruler::SetNullOffset(const Point& rOffset)
185 {
186 	long nOffset;
187 
188 	if ( bHorz )	nOffset = rOffset.X();
189 	else			nOffset = rOffset.Y();
190 
191 	SetNullOffsetLogic(nOffset);
192 }
193 
194 /*************************************************************************
195 |*
196 |* Command event
197 |*
198 \************************************************************************/
199 
Command(const CommandEvent & rCEvt)200 void Ruler::Command(const CommandEvent& rCEvt)
201 {
202 	if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
203 		!pDrViewShell->GetView()->IsTextEdit() )
204 	{
205 		SvxRuler::Command( rCEvt );
206 	}
207 }
208 
209 /*************************************************************************
210 |*
211 |* ExtraDown
212 |*
213 \************************************************************************/
214 
ExtraDown()215 void Ruler::ExtraDown()
216 {
217 	if( !pDrViewShell->GetView()->IsTextEdit() )
218 		SvxRuler::ExtraDown();
219 }
220 
221 } // end of namespace sd
222 
223