xref: /aoo41x/main/sc/source/ui/view/selectionstate.cxx (revision cdf0e10c)
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 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 #include "selectionstate.hxx"
31 
32 #include <editeng/editview.hxx>
33 #include "viewdata.hxx"
34 
35 // ============================================================================
36 
37 ScSelectionState::ScSelectionState( ScViewData& rViewData ) :
38     meType( SC_SELECTTYPE_NONE )
39 {
40     maCursor.SetTab( rViewData.GetTabNo() );
41     ScSplitPos eWhich = rViewData.GetActivePart();
42 
43     if( rViewData.HasEditView( eWhich ) )
44     {
45         meType = SC_SELECTTYPE_EDITCELL;
46         maCursor.SetCol( rViewData.GetEditViewCol() );
47         maCursor.SetRow( rViewData.GetEditViewRow() );
48         maEditSel = rViewData.GetEditView( eWhich )->GetSelection();
49     }
50     else
51     {
52         maCursor.SetCol( rViewData.GetCurX() );
53         maCursor.SetRow( rViewData.GetCurY() );
54 
55         ScMarkData& rMarkData = rViewData.GetMarkData();
56         rMarkData.MarkToMulti();
57         if( rMarkData.IsMultiMarked() )
58         {
59             meType = SC_SELECTTYPE_SHEET;
60             rMarkData.FillRangeListWithMarks( &maSheetSel, sal_False );
61         }
62         // else type is SC_SELECTTYPE_NONE - already initialized
63     }
64 }
65 
66 bool operator==( const ScSelectionState& rL, const ScSelectionState& rR )
67 {
68     bool bEqual = rL.GetSelectionType() == rR.GetSelectionType();
69     if( bEqual ) switch( rL.GetSelectionType() )
70     {
71         case SC_SELECTTYPE_EDITCELL:
72             bEqual &= ( rL.GetEditSelection().IsEqual( rR.GetEditSelection() ) != sal_False );
73         // run through!
74         case SC_SELECTTYPE_SHEET:
75             bEqual &= (rL.GetSheetSelection() == rR.GetSheetSelection()) == sal_True;
76         // run through!
77         case SC_SELECTTYPE_NONE:
78             bEqual &= rL.GetCellCursor() == rR.GetCellCursor();
79         break;
80         default:
81         {
82             // added to avoid warnings
83         }
84     }
85     return bEqual;
86 }
87 
88 // ============================================================================
89 
90