update dev300-m58
[ooovba.git] / applied_patches / 0182-calc-selection-protected-cells.diff
blobfa7a882e386add1dd9e6c8c14c8f890ae64a6517
1 diff --git sc/source/ui/inc/gridwin.hxx sc/source/ui/inc/gridwin.hxx
2 index 3ab93fd..29cd088 100644
3 --- sc/source/ui/inc/gridwin.hxx
4 +++ sc/source/ui/inc/gridwin.hxx
5 @@ -345,7 +345,7 @@ private:
7 void PasteSelection( const Point& rPosPixel );
9 - void SelectForContextMenu( const Point& rPosPixel );
10 + void SelectForContextMenu( const Point& rPosPixel, SCsCOL nCellX, SCsROW nCellY );
12 void GetSelectionRects( ::std::vector< Rectangle >& rPixelRects );
13 struct RectangleConverter {
14 diff --git sc/source/ui/inc/hdrcont.hxx sc/source/ui/inc/hdrcont.hxx
15 index 20cc822..497140f 100644
16 --- sc/source/ui/inc/hdrcont.hxx
17 +++ sc/source/ui/inc/hdrcont.hxx
18 @@ -80,7 +80,7 @@ private:
20 long GetScrPos( SCCOLROW nEntryNo );
21 SCCOLROW GetMousePos( const MouseEvent& rMEvt, BOOL& rBorder );
23 + bool IsSelectionAllowed(SCCOLROW nPos) const;
24 void ShowDragHelp();
26 void DoPaint( SCCOLROW nStart, SCCOLROW nEnd );
27 diff --git sc/source/ui/view/gridwin.cxx sc/source/ui/view/gridwin.cxx
28 index adb2f20..1079b9d 100644
29 --- sc/source/ui/view/gridwin.cxx
30 +++ sc/source/ui/view/gridwin.cxx
31 @@ -2753,9 +2753,32 @@ void __EXPORT ScGridWindow::Command( const CommandEvent& rCEvt )
33 if ( bMouse )
35 + SCsCOL nCellX = -1;
36 + SCsROW nCellY = -1;
37 + pViewData->GetPosFromPixel(aPosPixel.X(), aPosPixel.Y(), eWhich, nCellX, nCellY);
38 + ScDocument* pDoc = pViewData->GetDocument();
39 + SCTAB nTab = pViewData->GetTabNo();
40 + const ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
41 + bool bSelectAllowed = true;
42 + if ( pProtect && pProtect->isProtected() )
43 + {
44 + // This sheet is protected. Check if a context menu is allowed on this cell.
45 + bool bCellProtected = pDoc->HasAttrib(nCellX, nCellY, nTab, nCellX, nCellY, nTab, HASATTR_PROTECTED);
46 + bool bSelProtected = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
47 + bool bSelUnprotected = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
49 + if (bCellProtected)
50 + bSelectAllowed = bSelProtected;
51 + else
52 + bSelectAllowed = bSelUnprotected;
53 + }
54 + if (!bSelectAllowed)
55 + // Selecting this cell is not allowed, neither is context menu.
56 + return;
58 // #i18735# First select the item under the mouse pointer.
59 // This can change the selection, and the view state (edit mode, etc).
60 - SelectForContextMenu( aPosPixel );
61 + SelectForContextMenu( aPosPixel, nCellX, nCellY );
64 BOOL bDone = FALSE;
65 @@ -2850,15 +2873,12 @@ void __EXPORT ScGridWindow::Command( const CommandEvent& rCEvt )
69 -void ScGridWindow::SelectForContextMenu( const Point& rPosPixel )
70 +void ScGridWindow::SelectForContextMenu( const Point& rPosPixel, SCsCOL nCellX, SCsROW nCellY )
72 // #i18735# if the click was outside of the current selection,
73 // the cursor is moved or an object at the click position selected.
74 // (see SwEditWin::SelectMenuPosition in Writer)
76 - SCsCOL nCellX;
77 - SCsROW nCellY;
78 - pViewData->GetPosFromPixel( rPosPixel.X(), rPosPixel.Y(), eWhich, nCellX, nCellY );
79 ScTabView* pView = pViewData->GetView();
80 ScDrawView* pDrawView = pView->GetScDrawView();
82 diff --git sc/source/ui/view/hdrcont.cxx sc/source/ui/view/hdrcont.cxx
83 index 89e871c..5cfe8f8 100644
84 --- sc/source/ui/view/hdrcont.cxx
85 +++ sc/source/ui/view/hdrcont.cxx
86 @@ -47,6 +47,7 @@
87 #include "scmod.hxx" // Optionen
88 #include "inputopt.hxx" // Optionen
89 #include "gridmerg.hxx"
90 +#include "document.hxx"
92 // -----------------------------------------------------------------------
94 @@ -655,6 +656,39 @@ SCCOLROW ScHeaderControl::GetMousePos( const MouseEvent& rMEvt, BOOL& rBorder )
95 return nHitNo;
98 +bool ScHeaderControl::IsSelectionAllowed(SCCOLROW nPos) const
100 + ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
101 + if (!pViewSh)
102 + return false;
104 + ScViewData* pViewData = pViewSh->GetViewData();
105 + USHORT nTab = pViewData->GetTabNo();
106 + ScDocument* pDoc = pViewData->GetDocument();
107 + const ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
108 + bool bSelectAllowed = true;
109 + if ( pProtect && pProtect->isProtected() )
111 + // This sheet is protected. Check if a context menu is allowed on this cell.
112 + bool bCellsProtected = false;
113 + if (bVertical)
114 + // row header
115 + bCellsProtected = pDoc->HasAttrib(0, nPos, nTab, MAXCOL, nPos, nTab, HASATTR_PROTECTED);
116 + else
117 + // column header
118 + bCellsProtected = pDoc->HasAttrib(nPos, 0, nTab, nPos, MAXROW, nTab, HASATTR_PROTECTED);
120 + bool bSelProtected = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
121 + bool bSelUnprotected = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
123 + if (bCellsProtected)
124 + bSelectAllowed = bSelProtected;
125 + else
126 + bSelectAllowed = bSelUnprotected;
128 + return bSelectAllowed;
131 void __EXPORT ScHeaderControl::MouseButtonDown( const MouseEvent& rMEvt )
133 if (IsDisabled())
134 @@ -665,6 +699,8 @@ void __EXPORT ScHeaderControl::MouseButtonDown( const MouseEvent& rMEvt )
136 BOOL bFound;
137 SCCOLROW nHitNo = GetMousePos( rMEvt, bFound );
138 + if (!IsSelectionAllowed(nHitNo))
139 + return;
141 if ( bFound && rMEvt.IsLeft() && ResizeAllowed() )
143 @@ -848,8 +884,11 @@ void __EXPORT ScHeaderControl::Command( const CommandEvent& rCEvt )
144 MouseEvent aMEvt( rCEvt.GetMousePosPixel() );
145 BOOL bBorder;
146 SCCOLROW nPos = GetMousePos( aMEvt, bBorder );
147 - USHORT nTab = pViewData->GetTabNo();
148 + if (!IsSelectionAllowed(nPos))
149 + // Selecting this cell is not allowed, neither is context menu.
150 + return;
152 + SCTAB nTab = pViewData->GetTabNo();
153 ScRange aNewRange;
154 if ( bVertical )
155 aNewRange = ScRange( 0, sal::static_int_cast<SCROW>(nPos), nTab,