1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CHART2_SELECTIONHELPER_HXX
28 #define _CHART2_SELECTIONHELPER_HXX
29 
30 #include "DrawViewWrapper.hxx"
31 #include "ObjectIdentifier.hxx"
32 
33 class SdrObject;
34 // header for enum SdrDragMode
35 #include <svx/svdtypes.hxx>
36 #include <com/sun/star/drawing/XShape.hpp>
37 
38 //.............................................................................
39 namespace chart
40 {
41 //.............................................................................
42 
43 class ObjectIdentifier;
44 
45 //-----------------------------------------------------------------------------
46 /**
47 */
48 class Selection
49 {
50 public: //methods
51     bool hasSelection();
52 
53     rtl::OUString getSelectedCID();
54     ::com::sun::star::uno::Reference<
55                     ::com::sun::star::drawing::XShape > getSelectedAdditionalShape();
56     ObjectIdentifier getSelectedOID() const;
57 
58     bool isResizeableObjectSelected();
59     bool isRotateableObjectSelected( const ::com::sun::star::uno::Reference<
60                         ::com::sun::star::frame::XModel >& xChartModel );
61     bool isDragableObjectSelected();
62 
63     bool isAdditionalShapeSelected() const;
64 
65     //returns true if selection has changed
66     bool setSelection( const ::rtl::OUString& rCID );
67     bool setSelection( const ::com::sun::star::uno::Reference<
68                     ::com::sun::star::drawing::XShape >& xShape );
69 
70     void clearSelection();
71 
72     //returns true if the selection has changed
73     bool maybeSwitchSelectionAfterSingleClickWasEnsured();
74     void resetPossibleSelectionAfterSingleClickWasEnsured();
75 
76     void remindSelectionBeforeMouseDown();
77     bool isSelectionDifferentFromBeforeMouseDown();
78 
79     void adaptSelectionToNewPos( const Point& rMousePos, DrawViewWrapper* pDrawViewWrapper
80                                        , bool bIsRightMouse, bool bWaitingForDoubleClick );
81 
82     void applySelection( DrawViewWrapper* pDrawViewWrapper );
83 
84 private: //member
85     //the selection could be given by a CID or by a shape
86     //if m_aSelectedObjectCID is not empty this indicates the selection
87     //the content of m_xSelectedShape is ignored in that case
88     //the strings are used for autogenerated chart specific objects
89     //the shape reference is used for additional shapes
90     ObjectIdentifier    m_aSelectedOID; //only single object selection so far
91     ObjectIdentifier    m_aSelectedOID_beforeMouseDown;
92     ObjectIdentifier    m_aSelectedOID_selectOnlyIfNoDoubleClickIsFollowing;
93 };
94 
95 class SelectionHelper : public MarkHandleProvider
96 {
97 public:
98     static bool             findNamedParent( SdrObject*& pInOutObject
99                                 , rtl::OUString& rOutName
100                                 , bool bGivenObjectMayBeResult );
101     static bool             findNamedParent( SdrObject*& pInOutObject
102                                 , ObjectIdentifier& rOutObject
103                                 , bool bGivenObjectMayBeResult );
104     static SdrObject*       getMarkHandlesObject( SdrObject* pObj );
105     static E3dScene*        getSceneToRotate( SdrObject* pObj );
106     static bool             isDragableObjectHitTwice( const Point& rMPos
107                                 , const rtl::OUString& rNameOfSelectedObject
108                                 , const DrawViewWrapper& rDrawViewWrapper );
109 
110     static ::rtl::OUString getHitObjectCID(
111         const Point& rMPos,
112         DrawViewWrapper& rDrawViewWrapper,
113         bool bGetDiagramInsteadOf_Wall=false );
114 
115     static bool isRotateableObject( const ::rtl::OUString& rCID
116                     , const ::com::sun::star::uno::Reference<
117                         ::com::sun::star::frame::XModel >& xChartModel );
118 
119 
120     SelectionHelper( SdrObject* pSelectedObj );
121     virtual ~SelectionHelper();
122 
123 
124     //MarkHandleProvider:
125     virtual bool getMarkHandles( SdrHdlList& rHdlList );
126     virtual bool getFrameDragSingles();
127 
128     SdrObject*   getObjectToMark();//sets also internally the mark object
129     //-> getMarkHandles will behave different if this method has found a Mark Object different from m_pSelectedObj
130 
131 private:
132     SdrObject*      m_pSelectedObj;//hit and logically selected object
133     SdrObject*      m_pMarkObj;//object that is marked instead to have more pretty handles
134 };
135 
136 //.............................................................................
137 } //namespace chart
138 //.............................................................................
139 #endif
140