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 #pragma once 21 22 #include <vcl/timer.hxx> 23 #include <tools/link.hxx> 24 #include <tools/gen.hxx> 25 #include <vcl/vclptr.hxx> 26 #include <svx/svdobj.hxx> 27 28 #include <helper/simplereferencecomponent.hxx> 29 30 class SdDrawDocument; 31 class SfxRequest; 32 class CommandEvent; 33 class HelpEvent; 34 class KeyEvent; 35 class MouseEvent; 36 37 namespace sd { 38 39 class DrawDocShell; 40 class View; 41 class ViewShell; 42 class Window; 43 44 /** 45 * Base class for all functions 46 */ 47 class FuPoor : public SimpleReferenceComponent 48 { 49 public: 50 static const int HITPIX = 2; // hit tolerance in pixel 51 static const int HITLOG = 53; // hit tolerance in mm100 52 static const int DRGPIX = 2; // minimal drag move in pixel 53 static const int DRGLOG = 53; // minimal drag move in mm100 54 55 56 virtual void DoExecute( SfxRequest& rReq ); 57 SetMouseButtonCode(sal_uInt16 nNew)58 void SetMouseButtonCode(sal_uInt16 nNew) { if(nNew != mnCode) mnCode = nNew; } GetMouseButtonCode() const59 sal_uInt16 GetMouseButtonCode() const { return mnCode; } 60 GetDocSh()61 DrawDocShell* GetDocSh() { return mpDocSh; } 62 63 virtual void DoCut(); 64 virtual void DoCopy(); 65 virtual void DoPaste(); 66 virtual void DoPasteUnformatted(); 67 68 // mouse & key events; return value = sal_True: event has been handled 69 virtual bool KeyInput(const KeyEvent& rKEvt); 70 virtual bool MouseMove(const MouseEvent& ); 71 virtual bool MouseButtonUp(const MouseEvent& rMEvt); 72 73 // moved from inline to *.cxx 74 virtual bool MouseButtonDown(const MouseEvent& rMEvt); 75 76 virtual bool Command(const CommandEvent& rCEvt); 77 virtual bool RequestHelp(const HelpEvent& rHEvt); 78 virtual void ReceiveRequest(SfxRequest& rReq); 79 80 virtual void Activate(); ///< activates the function 81 virtual void Deactivate(); ///< deactivates the function 82 83 void SetWindow(::sd::Window* pWin); 84 85 virtual void SelectionHasChanged(); 86 GetSlotID() const87 sal_uInt16 GetSlotID() const { return nSlotId; } 88 89 void StartDelayToScrollTimer (); 90 91 virtual SdrObjectUniquePtr CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle); 92 93 /** is called when the current function should be aborted. <p> 94 This is used when a function gets a KEY_ESCAPE but can also 95 be called directly. 96 97 @returns true if an active function was aborted 98 */ 99 virtual bool cancel(); 100 101 // #i33136# 102 /** Decide if the object to be created should be created 103 orthogonal. Default implementation uses nSlotID 104 to decide. May be overridden to use other criteria 105 for this decision 106 107 @returns true if the to be created object should be orthogonal. 108 */ 109 virtual bool doConstructOrthogonal() const; 110 111 protected: 112 /** 113 @param pViewSh 114 May be NULL. 115 */ 116 FuPoor (ViewShell* pViewSh, 117 ::sd::Window* pWin, 118 ::sd::View* pView, 119 SdDrawDocument* pDoc, 120 SfxRequest& rReq); 121 virtual ~FuPoor() override; 122 123 DECL_LINK( DelayHdl, Timer *, void ); 124 125 static void ImpForceQuadratic(::tools::Rectangle& rRect); 126 127 /** Switch to another layer. The layer to switch to is specified by an 128 offset relative to the active layer. With respect to the layer bar 129 control at the lower left of the document window positive values 130 move to the right and negative values move to the left. 131 132 <p>Switching the layer is independent of the view's layer mode. The 133 layers are switched even when the layer mode is turned off and the 134 layer control is not visible.</p> 135 @param nOffset 136 If the offset is positive skip that many layers in selecting the 137 next layer. If it is negative then select a previous one. An 138 offset or zero does not change the current layer. If the 139 resulting index lies outside the valid range of indices then it 140 is set to either the minimal or maximal valid index, whichever 141 is nearer. 142 */ 143 void SwitchLayer (sal_Int32 nOffset); 144 145 ::sd::View* mpView; 146 ViewShell* mpViewShell; 147 VclPtr< ::sd::Window> mpWindow; 148 DrawDocShell* mpDocSh; 149 SdDrawDocument* mpDoc; 150 151 sal_uInt16 nSlotId; 152 153 Timer aScrollTimer; ///< for auto-scrolling 154 DECL_LINK( ScrollHdl, Timer *, void ); 155 void ForceScroll(const Point& aPixPos); 156 157 Timer aDragTimer; ///< for Drag&Drop 158 DECL_LINK(DragHdl, Timer *, void); 159 bool bIsInDragMode; 160 Point aMDPos; ///< position of MouseButtonDown 161 162 /// Flag to prevent auto-scrolling until one drags from outside into the window 163 bool bNoScrollUntilInside; 164 165 /// timer to delay scrolling (~ 1 sec) when dragging out of the window 166 Timer aDelayToScrollTimer; 167 bool bScrollable; 168 bool bDelayActive; 169 bool bFirstMouseMove; 170 171 /// member to hold state of the mouse buttons for creation of own MouseEvents (like in ScrollHdl) 172 173 private: 174 sal_uInt16 mnCode; 175 176 }; 177 178 } // end of namespace sd 179 180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 181