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