update dev300-m58
[ooovba.git] / sd / source / ui / view / sdruler.cxx
blob0c9f44a373c2a02f5e2f19e8231d53a82c96c3dd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdruler.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "Ruler.hxx"
35 #include <svtools/ptitem.hxx>
36 #include <svx/ruler.hxx>
37 #ifndef _SVXIDS_HXX //autogen
38 #include <svx/svxids.hrc>
39 #endif
40 #include <sfx2/ctrlitem.hxx>
41 #include <sfx2/bindings.hxx>
44 #include "View.hxx"
45 #include "DrawViewShell.hxx"
46 #include "Window.hxx"
48 #include "helpids.h"
50 namespace sd {
52 /*************************************************************************
54 |* Controller-Item fuer Ruler
56 \************************************************************************/
58 class RulerCtrlItem : public SfxControllerItem
60 Ruler &rRuler;
62 protected:
63 virtual void StateChanged( USHORT nSId, SfxItemState eState,
64 const SfxPoolItem* pItem );
66 public:
67 RulerCtrlItem(USHORT nId, Ruler& rRlr, SfxBindings& rBind);
70 /*************************************************************************
72 \************************************************************************/
74 RulerCtrlItem::RulerCtrlItem(USHORT _nId, Ruler& rRlr, SfxBindings& rBind)
75 : SfxControllerItem(_nId, rBind)
76 , rRuler(rRlr)
81 /*************************************************************************
83 \************************************************************************/
85 void RulerCtrlItem::StateChanged( USHORT nSId, SfxItemState, const SfxPoolItem* pState )
87 switch( nSId )
89 case SID_RULER_NULL_OFFSET:
91 const SfxPointItem* pItem = dynamic_cast< const SfxPointItem* >(pState);
92 DBG_ASSERT(pState ? pItem != NULL : TRUE, "SfxPointItem erwartet");
93 if ( pItem )
94 rRuler.SetNullOffset(pItem->GetValue());
96 break;
101 /*************************************************************************
103 |* Konstruktor
105 \************************************************************************/
107 Ruler::Ruler( DrawViewShell& rViewSh, ::Window* pParent, ::sd::Window* pWin, USHORT nRulerFlags, SfxBindings& rBindings, WinBits nWinStyle)
108 : SvxRuler(pParent, pWin, nRulerFlags, rBindings, nWinStyle)
109 , pSdWin(pWin)
110 , pDrViewShell(&rViewSh)
112 rBindings.EnterRegistrations();
113 pCtrlItem = new RulerCtrlItem(SID_RULER_NULL_OFFSET, *this, rBindings);
114 rBindings.LeaveRegistrations();
116 if ( nWinStyle & WB_HSCROLL )
118 bHorz = TRUE;
119 SetHelpId( HID_SD_RULER_HORIZONTAL );
121 else
123 bHorz = FALSE;
124 SetHelpId( HID_SD_RULER_VERTICAL );
128 /*************************************************************************
130 |* Destruktor
132 \************************************************************************/
134 Ruler::~Ruler()
136 SfxBindings& rBindings = pCtrlItem->GetBindings();
137 rBindings.EnterRegistrations();
138 delete pCtrlItem;
139 rBindings.LeaveRegistrations();
142 /*************************************************************************
144 |* MouseButtonDown-Handler
146 \************************************************************************/
148 void Ruler::MouseButtonDown(const MouseEvent& rMEvt)
150 Point aMPos = rMEvt.GetPosPixel();
151 RulerType eType = GetType(aMPos);
153 if ( !pDrViewShell->GetView()->IsTextEdit() &&
154 rMEvt.IsLeft() && rMEvt.GetClicks() == 1 &&
155 (eType == RULER_TYPE_DONTKNOW || eType == RULER_TYPE_OUTSIDE) )
157 pDrViewShell->StartRulerDrag(*this, rMEvt);
159 else
160 SvxRuler::MouseButtonDown(rMEvt);
163 /*************************************************************************
165 |* MouseMove-Handler
167 \************************************************************************/
169 void Ruler::MouseMove(const MouseEvent& rMEvt)
171 SvxRuler::MouseMove(rMEvt);
174 /*************************************************************************
176 |* MouseButtonUp-Handler
178 \************************************************************************/
180 void Ruler::MouseButtonUp(const MouseEvent& rMEvt)
182 SvxRuler::MouseButtonUp(rMEvt);
185 /*************************************************************************
187 |* NullOffset setzen
189 \************************************************************************/
191 void Ruler::SetNullOffset(const Point& rOffset)
193 long nOffset;
195 if ( bHorz ) nOffset = rOffset.X();
196 else nOffset = rOffset.Y();
198 SetNullOffsetLogic(nOffset);
201 /*************************************************************************
203 |* Command event
205 \************************************************************************/
207 void Ruler::Command(const CommandEvent& rCEvt)
209 if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
210 !pDrViewShell->GetView()->IsTextEdit() )
212 SvxRuler::Command( rCEvt );
216 /*************************************************************************
218 |* ExtraDown
220 \************************************************************************/
222 void Ruler::ExtraDown()
224 if( !pDrViewShell->GetView()->IsTextEdit() )
225 SvxRuler::ExtraDown();
228 } // end of namespace sd