1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdruler.cxx,v $
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"
35 #include <svtools/ptitem.hxx>
36 #include <svx/ruler.hxx>
37 #ifndef _SVXIDS_HXX //autogen
38 #include <svx/svxids.hrc>
40 #include <sfx2/ctrlitem.hxx>
41 #include <sfx2/bindings.hxx>
45 #include "DrawViewShell.hxx"
52 /*************************************************************************
54 |* Controller-Item fuer Ruler
56 \************************************************************************/
58 class RulerCtrlItem
: public SfxControllerItem
63 virtual void StateChanged( USHORT nSId
, SfxItemState eState
,
64 const SfxPoolItem
* pItem
);
67 RulerCtrlItem(USHORT nId
, Ruler
& rRlr
, SfxBindings
& rBind
);
70 /*************************************************************************
72 \************************************************************************/
74 RulerCtrlItem::RulerCtrlItem(USHORT _nId
, Ruler
& rRlr
, SfxBindings
& rBind
)
75 : SfxControllerItem(_nId
, rBind
)
81 /*************************************************************************
83 \************************************************************************/
85 void RulerCtrlItem::StateChanged( USHORT nSId
, SfxItemState
, const SfxPoolItem
* pState
)
89 case SID_RULER_NULL_OFFSET
:
91 const SfxPointItem
* pItem
= dynamic_cast< const SfxPointItem
* >(pState
);
92 DBG_ASSERT(pState
? pItem
!= NULL
: TRUE
, "SfxPointItem erwartet");
94 rRuler
.SetNullOffset(pItem
->GetValue());
101 /*************************************************************************
105 \************************************************************************/
107 Ruler::Ruler( DrawViewShell
& rViewSh
, ::Window
* pParent
, ::sd::Window
* pWin
, USHORT nRulerFlags
, SfxBindings
& rBindings
, WinBits nWinStyle
)
108 : SvxRuler(pParent
, pWin
, nRulerFlags
, rBindings
, nWinStyle
)
110 , pDrViewShell(&rViewSh
)
112 rBindings
.EnterRegistrations();
113 pCtrlItem
= new RulerCtrlItem(SID_RULER_NULL_OFFSET
, *this, rBindings
);
114 rBindings
.LeaveRegistrations();
116 if ( nWinStyle
& WB_HSCROLL
)
119 SetHelpId( HID_SD_RULER_HORIZONTAL
);
124 SetHelpId( HID_SD_RULER_VERTICAL
);
128 /*************************************************************************
132 \************************************************************************/
136 SfxBindings
& rBindings
= pCtrlItem
->GetBindings();
137 rBindings
.EnterRegistrations();
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
);
160 SvxRuler::MouseButtonDown(rMEvt
);
163 /*************************************************************************
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 /*************************************************************************
189 \************************************************************************/
191 void Ruler::SetNullOffset(const Point
& rOffset
)
195 if ( bHorz
) nOffset
= rOffset
.X();
196 else nOffset
= rOffset
.Y();
198 SetNullOffsetLogic(nOffset
);
201 /*************************************************************************
205 \************************************************************************/
207 void Ruler::Command(const CommandEvent
& rCEvt
)
209 if( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
&&
210 !pDrViewShell
->GetView()->IsTextEdit() )
212 SvxRuler::Command( rCEvt
);
216 /*************************************************************************
220 \************************************************************************/
222 void Ruler::ExtraDown()
224 if( !pDrViewShell
->GetView()->IsTextEdit() )
225 SvxRuler::ExtraDown();
228 } // end of namespace sd