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