xref: /AOO41X/main/sc/source/ui/view/gridwin.cxx (revision 0deba7fbda3d9908785c25a443701a293b6f4e71)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "scitems.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <memory> //auto_ptr
30cdf0e10cSrcweir #include <editeng/adjitem.hxx>
31cdf0e10cSrcweir #include <svx/algitem.hxx>
32cdf0e10cSrcweir #include <svx/dbexch.hrc>
33cdf0e10cSrcweir #include <editeng/editview.hxx>
34cdf0e10cSrcweir #include <editeng/editstat.hxx>
35cdf0e10cSrcweir #include <editeng/flditem.hxx>
36cdf0e10cSrcweir #include <svx/svdetc.hxx>
37cdf0e10cSrcweir #include <editeng/editobj.hxx>
38cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
39cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
40cdf0e10cSrcweir #include <sfx2/docfile.hxx>
41cdf0e10cSrcweir #include <svl/stritem.hxx>
42cdf0e10cSrcweir #include <svtools/svlbox.hxx>
43cdf0e10cSrcweir #include <svtools/svtabbx.hxx>
44cdf0e10cSrcweir #include <svl/urlbmk.hxx>
45cdf0e10cSrcweir #include <tools/urlobj.hxx>
46cdf0e10cSrcweir #include <vcl/cursor.hxx>
47cdf0e10cSrcweir #include <vcl/sound.hxx>
48cdf0e10cSrcweir #include <vcl/graph.hxx>
49cdf0e10cSrcweir #include <vcl/hatch.hxx>
50cdf0e10cSrcweir #include <sot/formats.hxx>
51cdf0e10cSrcweir #include <sot/clsids.hxx>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #include <svx/svdview.hxx>		// fuer Command-Handler (COMMAND_INSERTTEXT)
54cdf0e10cSrcweir #include <editeng/outliner.hxx>		// fuer Command-Handler (COMMAND_INSERTTEXT)
55cdf0e10cSrcweir #include <svx/svditer.hxx>
56cdf0e10cSrcweir #include <svx/svdocapt.hxx>
57cdf0e10cSrcweir #include <svx/svdpagv.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
60cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
61cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
62cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTableResultData.hpp>
63cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
64cdf0e10cSrcweir #include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
65cdf0e10cSrcweir #include <com/sun/star/sheet/MemberResultFlags.hpp>
66cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
67cdf0e10cSrcweir #include <com/sun/star/awt/MouseButton.hpp>
68cdf0e10cSrcweir #include <com/sun/star/script/vba/VBAEventId.hpp>
69cdf0e10cSrcweir #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #include "gridwin.hxx"
72cdf0e10cSrcweir #include "tabvwsh.hxx"
73cdf0e10cSrcweir #include "docsh.hxx"
74cdf0e10cSrcweir #include "viewdata.hxx"
75cdf0e10cSrcweir #include "tabview.hxx"
76cdf0e10cSrcweir #include "select.hxx"
77cdf0e10cSrcweir #include "scmod.hxx"
78cdf0e10cSrcweir #include "document.hxx"
79cdf0e10cSrcweir #include "attrib.hxx"
80cdf0e10cSrcweir #include "dbcolect.hxx"
81cdf0e10cSrcweir #include "stlpool.hxx"
82cdf0e10cSrcweir #include "printfun.hxx"
83cdf0e10cSrcweir #include "cbutton.hxx"
84cdf0e10cSrcweir #include "sc.hrc"
85cdf0e10cSrcweir #include "globstr.hrc"
86cdf0e10cSrcweir #include "editutil.hxx"
87cdf0e10cSrcweir #include "scresid.hxx"
88cdf0e10cSrcweir #include "inputhdl.hxx"
89cdf0e10cSrcweir #include "uiitems.hxx"			// Filter-Dialog - auslagern !!!
90cdf0e10cSrcweir #include "filtdlg.hxx"
91cdf0e10cSrcweir #include "impex.hxx"			// Sylk-ID fuer CB
92cdf0e10cSrcweir #include "cell.hxx"				// fuer Edit-Felder
93cdf0e10cSrcweir #include "patattr.hxx"
94cdf0e10cSrcweir #include "notemark.hxx"
95cdf0e10cSrcweir #include "rfindlst.hxx"
96cdf0e10cSrcweir #include "docpool.hxx"
97cdf0e10cSrcweir #include "output.hxx"
98cdf0e10cSrcweir #include "docfunc.hxx"
99cdf0e10cSrcweir #include "dbdocfun.hxx"
100cdf0e10cSrcweir #include "dpobject.hxx"
101cdf0e10cSrcweir #include "dpoutput.hxx"
102cdf0e10cSrcweir #include "transobj.hxx"
103cdf0e10cSrcweir #include "drwtrans.hxx"
104cdf0e10cSrcweir #include "seltrans.hxx"
105cdf0e10cSrcweir #include "sizedev.hxx"
106cdf0e10cSrcweir #include "AccessibilityHints.hxx"
107cdf0e10cSrcweir #include "dpsave.hxx"
108cdf0e10cSrcweir #include "viewuno.hxx"
109cdf0e10cSrcweir #include "compiler.hxx"
110cdf0e10cSrcweir #include "editable.hxx"
111cdf0e10cSrcweir #include "fillinfo.hxx"
112cdf0e10cSrcweir #include "scitems.hxx"
113cdf0e10cSrcweir #include "userdat.hxx"
114cdf0e10cSrcweir #include "drwlayer.hxx"
115cdf0e10cSrcweir #include "attrib.hxx"
116cdf0e10cSrcweir #include "validat.hxx"
117cdf0e10cSrcweir #include "tabprotection.hxx"
118cdf0e10cSrcweir #include "postit.hxx"
119cdf0e10cSrcweir #include "dpcontrol.hxx"
120cdf0e10cSrcweir #include "cellsuno.hxx"
121cdf0e10cSrcweir 
122cdf0e10cSrcweir #include "drawview.hxx"
123cdf0e10cSrcweir #include <svx/sdrpagewindow.hxx>
124cdf0e10cSrcweir #include <svx/sdr/overlay/overlaymanager.hxx>
125cdf0e10cSrcweir #include <vcl/svapp.hxx>
126cdf0e10cSrcweir #include <svx/sdr/overlay/overlayselection.hxx>
127cdf0e10cSrcweir 
128cdf0e10cSrcweir using namespace com::sun::star;
129cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
130cdf0e10cSrcweir using ::com::sun::star::uno::Any;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir const sal_uInt8 SC_NESTEDBUTTON_NONE = 0;
133cdf0e10cSrcweir const sal_uInt8 SC_NESTEDBUTTON_DOWN = 1;
134cdf0e10cSrcweir const sal_uInt8 SC_NESTEDBUTTON_UP   = 2;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir #define SC_AUTOFILTER_ALL		0
137cdf0e10cSrcweir #define	SC_AUTOFILTER_TOP10     1
138cdf0e10cSrcweir #define	SC_AUTOFILTER_CUSTOM    2
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //	Modi fuer die FilterListBox
141cdf0e10cSrcweir enum ScFilterBoxMode
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	SC_FILTERBOX_FILTER,
144cdf0e10cSrcweir 	SC_FILTERBOX_DATASELECT,
145cdf0e10cSrcweir 	SC_FILTERBOX_SCENARIO,
146cdf0e10cSrcweir 	SC_FILTERBOX_PAGEFIELD
147cdf0e10cSrcweir };
148cdf0e10cSrcweir 
149cdf0e10cSrcweir extern SfxViewShell* pScActiveViewShell;			// global.cxx
150cdf0e10cSrcweir extern sal_uInt16 nScClickMouseModifier;				// global.cxx
151cdf0e10cSrcweir extern sal_uInt16 nScFillModeMouseModifier;				// global.cxx
152cdf0e10cSrcweir 
153cdf0e10cSrcweir #define SC_FILTERLISTBOX_LINES	12
154cdf0e10cSrcweir 
155cdf0e10cSrcweir // ============================================================================
156cdf0e10cSrcweir 
157cdf0e10cSrcweir ScGridWindow::VisibleRange::VisibleRange() :
158cdf0e10cSrcweir     mnCol1(0), mnCol2(MAXCOL), mnRow1(0), mnRow2(MAXROW)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir bool ScGridWindow::VisibleRange::isInside(SCCOL nCol, SCROW nRow) const
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     return mnCol1 <= nCol && nCol <= mnCol2 && mnRow1 <= nRow && nRow <= mnRow2;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // ============================================================================
168cdf0e10cSrcweir 
169cdf0e10cSrcweir class ScFilterListBox : public ListBox
170cdf0e10cSrcweir {
171cdf0e10cSrcweir private:
172cdf0e10cSrcweir 	ScGridWindow*	pGridWin;
173cdf0e10cSrcweir 	SCCOL			nCol;
174cdf0e10cSrcweir 	SCROW			nRow;
175cdf0e10cSrcweir 	sal_Bool			bButtonDown;
176cdf0e10cSrcweir 	sal_Bool			bInit;
177cdf0e10cSrcweir 	sal_Bool			bCancelled;
178cdf0e10cSrcweir     sal_Bool            bInSelect;
179cdf0e10cSrcweir     bool            mbListHasDates;
180cdf0e10cSrcweir 	sal_uLong			nSel;
181cdf0e10cSrcweir 	ScFilterBoxMode	eMode;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir protected:
184cdf0e10cSrcweir 	virtual void	LoseFocus();
185cdf0e10cSrcweir 	void			SelectHdl();
186cdf0e10cSrcweir 
187cdf0e10cSrcweir public:
188cdf0e10cSrcweir 				ScFilterListBox( Window* pParent, ScGridWindow* pGrid,
189cdf0e10cSrcweir 								 SCCOL nNewCol, SCROW nNewRow, ScFilterBoxMode eNewMode );
190cdf0e10cSrcweir 				~ScFilterListBox();
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	virtual long	PreNotify( NotifyEvent& rNEvt );
193cdf0e10cSrcweir 	virtual void	Select();
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	SCCOL			GetCol() const			{ return nCol; }
196cdf0e10cSrcweir 	SCROW			GetRow() const			{ return nRow; }
197cdf0e10cSrcweir 	ScFilterBoxMode	GetMode() const			{ return eMode; }
198cdf0e10cSrcweir 	sal_Bool			IsDataSelect() const	{ return (eMode == SC_FILTERBOX_DATASELECT); }
199cdf0e10cSrcweir 	void			EndInit();
200cdf0e10cSrcweir     sal_Bool            IsInInit() const        { return bInit; }
201cdf0e10cSrcweir 	void			SetCancelled()			{ bCancelled = sal_True; }
202cdf0e10cSrcweir     sal_Bool            IsInSelect() const      { return bInSelect; }
203cdf0e10cSrcweir     void            SetListHasDates(bool b) { mbListHasDates = b; }
204cdf0e10cSrcweir     bool            HasDates() const        { return mbListHasDates; }
205cdf0e10cSrcweir };
206cdf0e10cSrcweir 
207cdf0e10cSrcweir //-------------------------------------------------------------------
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //	ListBox in einem FloatingWindow (pParent)
210cdf0e10cSrcweir ScFilterListBox::ScFilterListBox( Window* pParent, ScGridWindow* pGrid,
211cdf0e10cSrcweir 								  SCCOL nNewCol, SCROW nNewRow, ScFilterBoxMode eNewMode ) :
212cdf0e10cSrcweir 	ListBox( pParent, WB_AUTOHSCROLL ),
213cdf0e10cSrcweir 	pGridWin( pGrid ),
214cdf0e10cSrcweir 	nCol( nNewCol ),
215cdf0e10cSrcweir 	nRow( nNewRow ),
216cdf0e10cSrcweir 	bButtonDown( sal_False ),
217cdf0e10cSrcweir 	bInit( sal_True ),
218cdf0e10cSrcweir 	bCancelled( sal_False ),
219cdf0e10cSrcweir     bInSelect( sal_False ),
220cdf0e10cSrcweir     mbListHasDates(false),
221cdf0e10cSrcweir 	nSel( 0 ),
222cdf0e10cSrcweir 	eMode( eNewMode )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir __EXPORT ScFilterListBox::~ScFilterListBox()
227cdf0e10cSrcweir {
228cdf0e10cSrcweir 	if (IsMouseCaptured())
229cdf0e10cSrcweir 		ReleaseMouse();
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir void ScFilterListBox::EndInit()
233cdf0e10cSrcweir {
234cdf0e10cSrcweir 	sal_uInt16 nPos = GetSelectEntryPos();
235cdf0e10cSrcweir 	if ( LISTBOX_ENTRY_NOTFOUND == nPos )
236cdf0e10cSrcweir 		nSel = 0;
237cdf0e10cSrcweir 	else
238cdf0e10cSrcweir 		nSel = nPos;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	bInit = sal_False;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir void __EXPORT ScFilterListBox::LoseFocus()
244cdf0e10cSrcweir {
245cdf0e10cSrcweir #ifndef UNX
246cdf0e10cSrcweir 	Hide();
247cdf0e10cSrcweir #endif
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir // -----------------------------------------------------------------------
251cdf0e10cSrcweir 
252cdf0e10cSrcweir long ScFilterListBox::PreNotify( NotifyEvent& rNEvt )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	long nDone = 0;
255cdf0e10cSrcweir 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
256cdf0e10cSrcweir 	{
257cdf0e10cSrcweir 		KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
258cdf0e10cSrcweir 		KeyCode aCode = aKeyEvt.GetKeyCode();
259cdf0e10cSrcweir 		if ( !aCode.GetModifier() )				// ohne alle Modifiers
260cdf0e10cSrcweir 		{
261cdf0e10cSrcweir 			sal_uInt16 nKey = aCode.GetCode();
262cdf0e10cSrcweir 			if ( nKey == KEY_RETURN )
263cdf0e10cSrcweir 			{
264cdf0e10cSrcweir 				SelectHdl();					// auswaehlen
265cdf0e10cSrcweir 				nDone = 1;
266cdf0e10cSrcweir 			}
267cdf0e10cSrcweir 			else if ( nKey == KEY_ESCAPE )
268cdf0e10cSrcweir 			{
269cdf0e10cSrcweir 				pGridWin->ClickExtern();		// loescht die List-Box !!!
270cdf0e10cSrcweir 				nDone = 1;
271cdf0e10cSrcweir 			}
272cdf0e10cSrcweir 		}
273cdf0e10cSrcweir 	}
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 	return nDone ? nDone : ListBox::PreNotify( rNEvt );
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir void __EXPORT ScFilterListBox::Select()
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	ListBox::Select();
281cdf0e10cSrcweir 	SelectHdl();
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir void __EXPORT ScFilterListBox::SelectHdl()
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	if ( !IsTravelSelect() && !bInit && !bCancelled )
287cdf0e10cSrcweir 	{
288cdf0e10cSrcweir 		sal_uInt16 nPos = GetSelectEntryPos();
289cdf0e10cSrcweir 		if ( LISTBOX_ENTRY_NOTFOUND != nPos )
290cdf0e10cSrcweir 		{
291cdf0e10cSrcweir 			nSel = nPos;
292cdf0e10cSrcweir 			if (!bButtonDown)
293cdf0e10cSrcweir             {
294cdf0e10cSrcweir                 // #i81298# set bInSelect flag, so the box isn't deleted from modifications within FilterSelect
295cdf0e10cSrcweir                 bInSelect = sal_True;
296cdf0e10cSrcweir 				pGridWin->FilterSelect( nSel );
297cdf0e10cSrcweir                 bInSelect = sal_False;
298cdf0e10cSrcweir             }
299cdf0e10cSrcweir 		}
300cdf0e10cSrcweir 	}
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir // ============================================================================
304cdf0e10cSrcweir 
305cdf0e10cSrcweir // use a System floating window for the above filter listbox
306cdf0e10cSrcweir class ScFilterFloatingWindow : public FloatingWindow
307cdf0e10cSrcweir {
308cdf0e10cSrcweir public:
309cdf0e10cSrcweir 	ScFilterFloatingWindow( Window* pParent, WinBits nStyle = WB_STDFLOATWIN );
310cdf0e10cSrcweir     virtual ~ScFilterFloatingWindow();
311cdf0e10cSrcweir     // required for System FloatingWindows that will not process KeyInput by themselves
312cdf0e10cSrcweir     virtual Window* GetPreferredKeyInputWindow();
313cdf0e10cSrcweir };
314cdf0e10cSrcweir 
315cdf0e10cSrcweir ScFilterFloatingWindow::ScFilterFloatingWindow( Window* pParent, WinBits nStyle ) :
316cdf0e10cSrcweir 	FloatingWindow( pParent, nStyle|WB_SYSTEMWINDOW ) // make it a system floater
317cdf0e10cSrcweir     {}
318cdf0e10cSrcweir 
319cdf0e10cSrcweir ScFilterFloatingWindow::~ScFilterFloatingWindow()
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     EndPopupMode();
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir Window* ScFilterFloatingWindow::GetPreferredKeyInputWindow()
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     // redirect keyinput in the child window
327cdf0e10cSrcweir     return GetWindow(WINDOW_FIRSTCHILD) ? GetWindow(WINDOW_FIRSTCHILD)->GetPreferredKeyInputWindow() : NULL;    // will be the FilterBox
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir // ============================================================================
331cdf0e10cSrcweir 
332cdf0e10cSrcweir sal_Bool lcl_IsEditableMatrix( ScDocument* pDoc, const ScRange& rRange )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	//	wenn es ein editierbarer Bereich ist, und rechts unten eine Matrix-Zelle
335cdf0e10cSrcweir 	//	mit Origin links oben liegt, enthaelt der Bereich genau die Matrix.
336cdf0e10cSrcweir 	//!	Direkt die MatrixEdges Funktionen von der Column herausreichen ???
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 	if ( !pDoc->IsBlockEditable( rRange.aStart.Tab(), rRange.aStart.Col(),rRange.aStart.Row(),
339cdf0e10cSrcweir 									rRange.aEnd.Col(),rRange.aEnd.Row() ) )
340cdf0e10cSrcweir 		return sal_False;
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	ScAddress aPos;
343cdf0e10cSrcweir 	const ScBaseCell* pCell = pDoc->GetCell( rRange.aEnd );
344cdf0e10cSrcweir 	return ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA &&
345cdf0e10cSrcweir 			((ScFormulaCell*)pCell)->GetMatrixOrigin(aPos) && aPos == rRange.aStart );
346cdf0e10cSrcweir 
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir void lcl_UnLockComment( ScDrawView* pView, SdrPageView* pPV, SdrModel* pDrDoc, const Point& rPos, ScViewData* pViewData )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     if (!pView && !pPV && !pDrDoc && !pViewData)
352cdf0e10cSrcweir         return;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     ScDocument& rDoc = *pViewData->GetDocument();
355cdf0e10cSrcweir     ScAddress aCellPos( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() );
356cdf0e10cSrcweir     ScPostIt* pNote = rDoc.GetNote( aCellPos );
357cdf0e10cSrcweir     SdrObject* pObj = pNote ? pNote->GetCaption() : 0;
358cdf0e10cSrcweir     if( pObj && pObj->GetLogicRect().IsInside( rPos ) && ScDrawLayer::IsNoteCaption( pObj ) )
359cdf0e10cSrcweir     {
360cdf0e10cSrcweir         const ScProtectionAttr* pProtAttr =  static_cast< const ScProtectionAttr* > (rDoc.GetAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), ATTR_PROTECTION ) );
361cdf0e10cSrcweir         bool bProtectAttr = pProtAttr->GetProtection() || pProtAttr->GetHideCell() ;
362cdf0e10cSrcweir         bool bProtectDoc =  rDoc.IsTabProtected( aCellPos.Tab() ) || pViewData->GetSfxDocShell()->IsReadOnly() ;
363cdf0e10cSrcweir         // unlock internal layer (if not protected), will be relocked in ScDrawView::MarkListHasChanged()
364cdf0e10cSrcweir         pView->LockInternalLayer( bProtectDoc && bProtectAttr );
365cdf0e10cSrcweir     }
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPosY, SCTAB nTab, ScBaseCell*& rpCell )
369cdf0e10cSrcweir {
370cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
371cdf0e10cSrcweir 	do
372cdf0e10cSrcweir 	{
373cdf0e10cSrcweir 		pDoc->GetCell( rPosX, rPosY, nTab, rpCell );
374cdf0e10cSrcweir 		if ( !rpCell || rpCell->GetCellType() == CELLTYPE_NOTE )
375cdf0e10cSrcweir 		{
376cdf0e10cSrcweir 			if ( rPosX <= 0 )
377cdf0e10cSrcweir 				return sal_False;							// alles leer bis links
378cdf0e10cSrcweir 			else
379cdf0e10cSrcweir 				--rPosX;								// weitersuchen
380cdf0e10cSrcweir 		}
381cdf0e10cSrcweir                 else if ( rpCell->GetCellType() == CELLTYPE_EDIT)
382cdf0e10cSrcweir                     bFound = sal_True;
383cdf0e10cSrcweir                 else if (rpCell->GetCellType() == CELLTYPE_FORMULA &&
384cdf0e10cSrcweir                   static_cast<ScFormulaCell*>(rpCell)->IsHyperLinkCell())
385cdf0e10cSrcweir                     bFound = sal_True;
386cdf0e10cSrcweir 	    else
387cdf0e10cSrcweir 			return sal_False;								// andere Zelle
388cdf0e10cSrcweir 	}
389cdf0e10cSrcweir 	while ( !bFound );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	return bFound;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir // ---------------------------------------------------------------------------
395cdf0e10cSrcweir //	WB_DIALOGCONTROL noetig fuer UNO-Controls
396cdf0e10cSrcweir ScGridWindow::ScGridWindow( Window* pParent, ScViewData* pData, ScSplitPos eWhichPos )
397cdf0e10cSrcweir :			Window( pParent, WB_CLIPCHILDREN | WB_DIALOGCONTROL ),
398cdf0e10cSrcweir 			DropTargetHelper( this ),
399cdf0e10cSrcweir 			DragSourceHelper( this ),
400cdf0e10cSrcweir             mpOOCursors( NULL ),
401cdf0e10cSrcweir             mpOOSelection( NULL ),
402cdf0e10cSrcweir             mpOOAutoFill( NULL ),
403cdf0e10cSrcweir             mpOODragRect( NULL ),
404cdf0e10cSrcweir             mpOOHeader( NULL ),
405cdf0e10cSrcweir             mpOOShrink( NULL ),
406cdf0e10cSrcweir             mpAutoFillRect(static_cast<Rectangle*>(NULL)),
407cdf0e10cSrcweir 			pViewData( pData ),
408cdf0e10cSrcweir 			eWhich( eWhichPos ),
409cdf0e10cSrcweir 			pNoteMarker( NULL ),
410cdf0e10cSrcweir 			pFilterBox( NULL ),
411cdf0e10cSrcweir 			pFilterFloat( NULL ),
412cdf0e10cSrcweir             mpDPFieldPopup(NULL),
413cdf0e10cSrcweir             mpFilterButton(NULL),
414cdf0e10cSrcweir 			nCursorHideCount( 0 ),
415cdf0e10cSrcweir 			bMarking( sal_False ),
416cdf0e10cSrcweir 			nButtonDown( 0 ),
417cdf0e10cSrcweir 			bEEMouse( sal_False ),
418cdf0e10cSrcweir 			nMouseStatus( SC_GM_NONE ),
419cdf0e10cSrcweir             nNestedButtonState( SC_NESTEDBUTTON_NONE ),
420cdf0e10cSrcweir 			bDPMouse( sal_False ),
421cdf0e10cSrcweir 			bRFMouse( sal_False ),
422cdf0e10cSrcweir 			nPagebreakMouse( SC_PD_NONE ),
423cdf0e10cSrcweir             bPagebreakDrawn( sal_False ),
424cdf0e10cSrcweir 			nPageScript( 0 ),
425cdf0e10cSrcweir 			bDragRect( sal_False ),
426cdf0e10cSrcweir             meDragInsertMode( INS_NONE ),
427cdf0e10cSrcweir 			nCurrentPointer( 0 ),
428cdf0e10cSrcweir 			bIsInScroll( sal_False ),
429cdf0e10cSrcweir 			bIsInPaint( sal_False ),
430cdf0e10cSrcweir 			aComboButton( this ),
431cdf0e10cSrcweir 			aCurMousePos( 0,0 ),
432cdf0e10cSrcweir 			nPaintCount( 0 ),
433cdf0e10cSrcweir 			bNeedsRepaint( sal_False ),
434cdf0e10cSrcweir 			bAutoMarkVisible( sal_False ),
435cdf0e10cSrcweir 			bListValButton( sal_False )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir 	switch(eWhich)
438cdf0e10cSrcweir 	{
439cdf0e10cSrcweir 		case SC_SPLIT_TOPLEFT:
440cdf0e10cSrcweir 			eHWhich = SC_SPLIT_LEFT;
441cdf0e10cSrcweir 			eVWhich = SC_SPLIT_TOP;
442cdf0e10cSrcweir 			break;
443cdf0e10cSrcweir 		case SC_SPLIT_TOPRIGHT:
444cdf0e10cSrcweir 			eHWhich = SC_SPLIT_RIGHT;
445cdf0e10cSrcweir 			eVWhich = SC_SPLIT_TOP;
446cdf0e10cSrcweir 			break;
447cdf0e10cSrcweir 		case SC_SPLIT_BOTTOMLEFT:
448cdf0e10cSrcweir 			eHWhich = SC_SPLIT_LEFT;
449cdf0e10cSrcweir 			eVWhich = SC_SPLIT_BOTTOM;
450cdf0e10cSrcweir 			break;
451cdf0e10cSrcweir 		case SC_SPLIT_BOTTOMRIGHT:
452cdf0e10cSrcweir 			eHWhich = SC_SPLIT_RIGHT;
453cdf0e10cSrcweir 			eVWhich = SC_SPLIT_BOTTOM;
454cdf0e10cSrcweir 			break;
455cdf0e10cSrcweir 		default:
456cdf0e10cSrcweir 			DBG_ERROR("GridWindow: falsche Position");
457cdf0e10cSrcweir 	}
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 	SetBackground();
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 	SetMapMode(pViewData->GetLogicMode(eWhich));
462cdf0e10cSrcweir //	EnableDrop();
463cdf0e10cSrcweir 	EnableChildTransparentMode();
464cdf0e10cSrcweir 	SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	SetHelpId( HID_SC_WIN_GRIDWIN );
467cdf0e10cSrcweir 	SetUniqueId( HID_SC_WIN_GRIDWIN );
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
470cdf0e10cSrcweir     EnableRTL( sal_False );
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir __EXPORT ScGridWindow::~ScGridWindow()
474cdf0e10cSrcweir {
475cdf0e10cSrcweir 	// #114409#
476cdf0e10cSrcweir 	ImpDestroyOverlayObjects();
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 	delete pFilterBox;
479cdf0e10cSrcweir 	delete pFilterFloat;
480cdf0e10cSrcweir 	delete pNoteMarker;
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir void __EXPORT ScGridWindow::Resize( const Size& )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	//	gar nix
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir void ScGridWindow::ClickExtern()
489cdf0e10cSrcweir {
490cdf0e10cSrcweir     do
491cdf0e10cSrcweir     {
492cdf0e10cSrcweir         // #i81298# don't delete the filter box when called from its select handler
493cdf0e10cSrcweir         // (possible through row header size update)
494cdf0e10cSrcweir         // #i84277# when initializing the filter box, a Basic error can deactivate the view
495cdf0e10cSrcweir         if ( pFilterBox && ( pFilterBox->IsInSelect() || pFilterBox->IsInInit() ) )
496cdf0e10cSrcweir         {
497cdf0e10cSrcweir             break;
498cdf0e10cSrcweir         }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir         DELETEZ(pFilterBox);
501cdf0e10cSrcweir         DELETEZ(pFilterFloat);
502cdf0e10cSrcweir     }
503cdf0e10cSrcweir     while (false);
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     if (mpDPFieldPopup.get())
506cdf0e10cSrcweir     {
507cdf0e10cSrcweir         mpDPFieldPopup->close(false);
508cdf0e10cSrcweir         mpDPFieldPopup.reset();
509cdf0e10cSrcweir     }
510cdf0e10cSrcweir }
511cdf0e10cSrcweir 
512cdf0e10cSrcweir IMPL_LINK( ScGridWindow, PopupModeEndHdl, FloatingWindow*, EMPTYARG )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir 	if (pFilterBox)
515cdf0e10cSrcweir 		pFilterBox->SetCancelled();		// nicht mehr auswaehlen
516cdf0e10cSrcweir 	GrabFocus();
517cdf0e10cSrcweir 	return 0;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir IMPL_LINK( ScGridWindow, PopupSpellingHdl, SpellCallbackInfo*, pInfo )
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     if( pInfo->nCommand == SPELLCMD_STARTSPELLDLG )
523cdf0e10cSrcweir         pViewData->GetDispatcher().Execute( SID_SPELL_DIALOG, SFX_CALLMODE_ASYNCHRON );
524cdf0e10cSrcweir     return 0;
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
527cdf0e10cSrcweir void ScGridWindow::ExecPageFieldSelect( SCCOL nCol, SCROW nRow, sal_Bool bHasSelection, const String& rStr )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir 	//!	gridwin2 ?
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
532cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
533cdf0e10cSrcweir 	ScDPObject*	pDPObj = pDoc->GetDPAtCursor(nCol, nRow, nTab);
534cdf0e10cSrcweir 	if ( pDPObj && nCol > 0 )
535cdf0e10cSrcweir 	{
536cdf0e10cSrcweir 		// look for the dimension header left of the drop-down arrow
537cdf0e10cSrcweir 		sal_uInt16 nOrient = sheet::DataPilotFieldOrientation_HIDDEN;
538cdf0e10cSrcweir 		long nField = pDPObj->GetHeaderDim( ScAddress( nCol-1, nRow, nTab ), nOrient );
539cdf0e10cSrcweir 		if ( nField >= 0 && nOrient == sheet::DataPilotFieldOrientation_PAGE )
540cdf0e10cSrcweir 		{
541cdf0e10cSrcweir 			ScDPSaveData aSaveData( *pDPObj->GetSaveData() );
542cdf0e10cSrcweir 
543cdf0e10cSrcweir 			sal_Bool bIsDataLayout;
544cdf0e10cSrcweir 			String aDimName = pDPObj->GetDimName( nField, bIsDataLayout );
545cdf0e10cSrcweir 			if ( !bIsDataLayout )
546cdf0e10cSrcweir 			{
547cdf0e10cSrcweir 				ScDPSaveDimension* pDim = aSaveData.GetDimensionByName(aDimName);
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 				if ( bHasSelection )
550cdf0e10cSrcweir 					pDim->SetCurrentPage( &rStr );
551cdf0e10cSrcweir 				else
552cdf0e10cSrcweir 					pDim->SetCurrentPage( NULL );
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 				ScDPObject aNewObj( *pDPObj );
555cdf0e10cSrcweir 				aNewObj.SetSaveData( aSaveData );
556cdf0e10cSrcweir 				ScDBDocFunc aFunc( *pViewData->GetDocShell() );
557cdf0e10cSrcweir 				aFunc.DataPilotUpdate( pDPObj, &aNewObj, sal_True, sal_False );
558cdf0e10cSrcweir 				pViewData->GetView()->CursorPosChanged();		// shells may be switched
559cdf0e10cSrcweir 			}
560cdf0e10cSrcweir 		}
561cdf0e10cSrcweir 	}
562cdf0e10cSrcweir }
563cdf0e10cSrcweir 
564cdf0e10cSrcweir void ScGridWindow::LaunchPageFieldMenu( SCCOL nCol, SCROW nRow )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir 	//!	merge position/size handling with DoAutoFilterMenue
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 	delete pFilterBox;
569cdf0e10cSrcweir 	delete pFilterFloat;
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 	sal_uInt16 i;
572cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
573cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
574cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	long nSizeX  = 0;
577cdf0e10cSrcweir 	long nSizeY  = 0;
578cdf0e10cSrcweir 	long nHeight = 0;
579cdf0e10cSrcweir 	pViewData->GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
580cdf0e10cSrcweir 	Point aPos = pViewData->GetScrPos( nCol, nRow, eWhich );
581cdf0e10cSrcweir 	if ( bLayoutRTL )
582cdf0e10cSrcweir 		aPos.X() -= nSizeX;
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 	Rectangle aCellRect( OutputToScreenPixel(aPos), Size(nSizeX,nSizeY) );
585cdf0e10cSrcweir 
586cdf0e10cSrcweir 	aPos.X() -= 1;
587cdf0e10cSrcweir 	aPos.Y() += nSizeY - 1;
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 	pFilterFloat = new ScFilterFloatingWindow( this, WinBits(WB_BORDER) );		// not resizable etc.
590cdf0e10cSrcweir 	pFilterFloat->SetPopupModeEndHdl( LINK( this, ScGridWindow, PopupModeEndHdl ) );
591cdf0e10cSrcweir 	pFilterBox = new ScFilterListBox( pFilterFloat, this, nCol, nRow, SC_FILTERBOX_PAGEFIELD );
592cdf0e10cSrcweir 	if ( bLayoutRTL )
593cdf0e10cSrcweir 		pFilterBox->EnableMirroring();
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 	nSizeX += 1;
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 	{
598cdf0e10cSrcweir 		Font 	aOldFont = GetFont(); SetFont( pFilterBox->GetFont() );
599cdf0e10cSrcweir 		MapMode aOldMode = GetMapMode(); SetMapMode( MAP_PIXEL );
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 		nHeight  = GetTextHeight();
602cdf0e10cSrcweir 		nHeight *= SC_FILTERLISTBOX_LINES;
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 		SetMapMode( aOldMode );
605cdf0e10cSrcweir 		SetFont( aOldFont );
606cdf0e10cSrcweir 	}
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 	//	SetSize comes later
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 	TypedScStrCollection aStrings( 128, 128 );
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 	//	get list box entries and selection
613cdf0e10cSrcweir 	sal_Bool bHasCurrentPage = sal_False;
614cdf0e10cSrcweir 	String aCurrentPage;
615cdf0e10cSrcweir 	ScDPObject*	pDPObj = pDoc->GetDPAtCursor(nCol, nRow, nTab);
616cdf0e10cSrcweir 	if ( pDPObj && nCol > 0 )
617cdf0e10cSrcweir 	{
618cdf0e10cSrcweir 		// look for the dimension header left of the drop-down arrow
619cdf0e10cSrcweir 		sal_uInt16 nOrient = sheet::DataPilotFieldOrientation_HIDDEN;
620cdf0e10cSrcweir 		long nField = pDPObj->GetHeaderDim( ScAddress( nCol-1, nRow, nTab ), nOrient );
621cdf0e10cSrcweir 		if ( nField >= 0 && nOrient == sheet::DataPilotFieldOrientation_PAGE )
622cdf0e10cSrcweir 		{
623cdf0e10cSrcweir 			pDPObj->FillPageList( aStrings, nField );
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 			// get current page from SaveData
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 			ScDPSaveData* pSaveData = pDPObj->GetSaveData();
628cdf0e10cSrcweir 			sal_Bool bIsDataLayout;
629cdf0e10cSrcweir 			String aDimName = pDPObj->GetDimName( nField, bIsDataLayout );
630cdf0e10cSrcweir 			if ( pSaveData && !bIsDataLayout )
631cdf0e10cSrcweir 			{
632cdf0e10cSrcweir 				ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName(aDimName);
633cdf0e10cSrcweir 				if ( pDim && pDim->HasCurrentPage() )
634cdf0e10cSrcweir 				{
635cdf0e10cSrcweir 					aCurrentPage = pDim->GetCurrentPage();
636cdf0e10cSrcweir 					bHasCurrentPage = sal_True;
637cdf0e10cSrcweir 				}
638cdf0e10cSrcweir 			}
639cdf0e10cSrcweir 		}
640cdf0e10cSrcweir 	}
641cdf0e10cSrcweir 
642cdf0e10cSrcweir 	//	include all entry widths for the size of the drop-down
643cdf0e10cSrcweir 	long nMaxText = 0;
644cdf0e10cSrcweir 	sal_uInt16 nCount = aStrings.GetCount();
645cdf0e10cSrcweir 	for (i=0; i<nCount; i++)
646cdf0e10cSrcweir 	{
647cdf0e10cSrcweir 		TypedStrData* pData = aStrings[i];
648cdf0e10cSrcweir 		long nTextWidth = pFilterBox->GetTextWidth( pData->GetString() );
649cdf0e10cSrcweir 		if ( nTextWidth > nMaxText )
650cdf0e10cSrcweir 			nMaxText = nTextWidth;
651cdf0e10cSrcweir 	}
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 	//	add scrollbar width if needed (string entries are counted here)
654cdf0e10cSrcweir 	//	(scrollbar is shown if the box is exactly full?)
655cdf0e10cSrcweir 	if ( nCount >= SC_FILTERLISTBOX_LINES )
656cdf0e10cSrcweir 		nMaxText += GetSettings().GetStyleSettings().GetScrollBarSize();
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 	nMaxText += 4;				// for borders
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 	if ( nMaxText > nSizeX )
661cdf0e10cSrcweir 		nSizeX = nMaxText;		// just modify width - starting position is unchanged
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 	//	adjust position and size to window
664cdf0e10cSrcweir 
665cdf0e10cSrcweir 	Size aParentSize = GetParent()->GetOutputSizePixel();
666cdf0e10cSrcweir 	Size aSize( nSizeX, nHeight );
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 	if ( aSize.Height() > aParentSize.Height() )
669cdf0e10cSrcweir 		aSize.Height() = aParentSize.Height();
670cdf0e10cSrcweir 	if ( aPos.Y() + aSize.Height() > aParentSize.Height() )
671cdf0e10cSrcweir 		aPos.Y() = aParentSize.Height() - aSize.Height();
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	pFilterBox->SetSizePixel( aSize );
674cdf0e10cSrcweir 	pFilterBox->Show();					// Show must be called before SetUpdateMode
675cdf0e10cSrcweir 	pFilterBox->SetUpdateMode(sal_False);
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 	pFilterFloat->SetOutputSizePixel( aSize );
678cdf0e10cSrcweir 	pFilterFloat->StartPopupMode( aCellRect, FLOATWIN_POPUPMODE_DOWN|FLOATWIN_POPUPMODE_GRABFOCUS);
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 	//	fill the list box
681cdf0e10cSrcweir 	sal_Bool bWait = ( nCount > 100 );
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 	if (bWait)
684cdf0e10cSrcweir 		EnterWait();
685cdf0e10cSrcweir 
686cdf0e10cSrcweir 	for (i=0; i<nCount; i++)
687cdf0e10cSrcweir 		pFilterBox->InsertEntry( aStrings[i]->GetString() );
688cdf0e10cSrcweir 
689cdf0e10cSrcweir     pFilterBox->SetSeparatorPos( 0 );
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 	if (bWait)
692cdf0e10cSrcweir 		LeaveWait();
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 	pFilterBox->SetUpdateMode(sal_True);
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     sal_uInt16 nSelPos = LISTBOX_ENTRY_NOTFOUND;
697cdf0e10cSrcweir 	if (bHasCurrentPage)
698cdf0e10cSrcweir 		nSelPos = pFilterBox->GetEntryPos( aCurrentPage );
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 	if ( nSelPos == LISTBOX_ENTRY_NOTFOUND )
701cdf0e10cSrcweir 		nSelPos = 0;                            // first entry
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 	pFilterBox->GrabFocus();
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	//	call Select after GrabFocus, so the focus rectangle ends up in the right position
706cdf0e10cSrcweir 	if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
707cdf0e10cSrcweir 		pFilterBox->SelectEntryPos( nSelPos );
708cdf0e10cSrcweir 
709cdf0e10cSrcweir 	pFilterBox->EndInit();
710cdf0e10cSrcweir 
711cdf0e10cSrcweir 	nMouseStatus = SC_GM_FILTER;
712cdf0e10cSrcweir 	CaptureMouse();
713cdf0e10cSrcweir }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir void ScGridWindow::LaunchDPFieldMenu( SCCOL nCol, SCROW nRow )
716cdf0e10cSrcweir {
717cdf0e10cSrcweir     SCTAB nTab = pViewData->GetTabNo();
718cdf0e10cSrcweir     ScDPObject* pDPObj = pViewData->GetDocument()->GetDPAtCursor(nCol, nRow, nTab);
719cdf0e10cSrcweir     if (!pDPObj)
720cdf0e10cSrcweir         return;
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     // Get the geometry of the cell.
723cdf0e10cSrcweir     Point aScrPos = pViewData->GetScrPos(nCol, nRow, eWhich);
724cdf0e10cSrcweir     long nSizeX, nSizeY;
725cdf0e10cSrcweir     pViewData->GetMergeSizePixel(nCol, nRow, nSizeX, nSizeY);
726cdf0e10cSrcweir     Size aScrSize(nSizeX-1, nSizeY-1);
727cdf0e10cSrcweir 
728cdf0e10cSrcweir     DPLaunchFieldPopupMenu(OutputToScreenPixel(aScrPos), aScrSize, ScAddress(nCol, nRow, nTab), pDPObj);
729cdf0e10cSrcweir }
730cdf0e10cSrcweir 
731cdf0e10cSrcweir void ScGridWindow::DoScenarioMenue( const ScRange& rScenRange )
732cdf0e10cSrcweir {
733cdf0e10cSrcweir 	delete pFilterBox;
734cdf0e10cSrcweir 	delete pFilterFloat;
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 	SCCOL nCol = rScenRange.aEnd.Col();		// Zelle unterhalb des Buttons
737cdf0e10cSrcweir 	SCROW nRow = rScenRange.aStart.Row();
738cdf0e10cSrcweir 	if (nRow == 0)
739cdf0e10cSrcweir 	{
740cdf0e10cSrcweir 		nRow = rScenRange.aEnd.Row() + 1;		// Bereich ganz oben -> Button unterhalb
741cdf0e10cSrcweir 		if (nRow>MAXROW) nRow = MAXROW;
742cdf0e10cSrcweir 		//!	Texthoehe addieren (wenn sie an der View gespeichert ist...)
743cdf0e10cSrcweir 	}
744cdf0e10cSrcweir 
745cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
746cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
747cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 	long nSizeX  = 0;
750cdf0e10cSrcweir 	long nSizeY  = 0;
751cdf0e10cSrcweir 	long nHeight = 0;
752cdf0e10cSrcweir 	pViewData->GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
753cdf0e10cSrcweir 	Point aPos = pViewData->GetScrPos( nCol, nRow, eWhich );
754cdf0e10cSrcweir 	if ( bLayoutRTL )
755cdf0e10cSrcweir 		aPos.X() -= nSizeX;
756cdf0e10cSrcweir 	Rectangle aCellRect( OutputToScreenPixel(aPos), Size(nSizeX,nSizeY) );
757cdf0e10cSrcweir 	aCellRect.Top()    -= nSizeY;
758cdf0e10cSrcweir 	aCellRect.Bottom() -= nSizeY - 1;
759cdf0e10cSrcweir 	//	Die ListBox direkt unter der schwarzen Linie auf dem Zellgitter
760cdf0e10cSrcweir 	//	(wenn die Linie verdeckt wird, sieht es komisch aus...)
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 	pFilterFloat = new ScFilterFloatingWindow( this, WinBits(WB_BORDER) );		// nicht resizable etc.
763cdf0e10cSrcweir 	pFilterFloat->SetPopupModeEndHdl( LINK( this, ScGridWindow, PopupModeEndHdl ) );
764cdf0e10cSrcweir 	pFilterBox = new ScFilterListBox( pFilterFloat, this, nCol, nRow, SC_FILTERBOX_SCENARIO );
765cdf0e10cSrcweir 	if ( bLayoutRTL )
766cdf0e10cSrcweir 		pFilterBox->EnableMirroring();
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 	nSizeX += 1;
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 	{
771cdf0e10cSrcweir 		Font 	aOldFont = GetFont(); SetFont( pFilterBox->GetFont() );
772cdf0e10cSrcweir 		MapMode aOldMode = GetMapMode(); SetMapMode( MAP_PIXEL );
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 		nHeight  = GetTextHeight();
775cdf0e10cSrcweir 		nHeight *= SC_FILTERLISTBOX_LINES;
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 		SetMapMode( aOldMode );
778cdf0e10cSrcweir 		SetFont( aOldFont );
779cdf0e10cSrcweir 	}
780cdf0e10cSrcweir 
781cdf0e10cSrcweir 	//	SetSize spaeter
782cdf0e10cSrcweir /*
783cdf0e10cSrcweir 	pFilterBox->SetSelectionMode( SINGLE_SELECTION );
784cdf0e10cSrcweir 	pFilterBox->SetTabs( nFilterBoxTabs, MapUnit( MAP_APPFONT ));
785cdf0e10cSrcweir 	pFilterBox->SetTabJustify( 1, bLayoutRTL ? AdjustRight : AdjustLeft );
786cdf0e10cSrcweir */
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 	//	ParentSize Abfrage fehlt
789cdf0e10cSrcweir 	Size aSize( nSizeX, nHeight );
790cdf0e10cSrcweir 	pFilterBox->SetSizePixel( aSize );
791cdf0e10cSrcweir 	pFilterBox->Show();					// Show muss vor SetUpdateMode kommen !!!
792cdf0e10cSrcweir 	pFilterBox->SetUpdateMode(sal_False);
793cdf0e10cSrcweir 
794cdf0e10cSrcweir 	//	SetOutputSizePixel/StartPopupMode erst unten, wenn die Groesse feststeht
795cdf0e10cSrcweir 
796cdf0e10cSrcweir 	//	Listbox fuellen
797cdf0e10cSrcweir 
798cdf0e10cSrcweir 	long nMaxText = 0;
799cdf0e10cSrcweir 	String aCurrent;
800cdf0e10cSrcweir 	String aTabName;
801cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
802cdf0e10cSrcweir 	SCTAB nEntryCount = 0;
803cdf0e10cSrcweir 	for (SCTAB i=nTab+1; i<nTabCount && pDoc->IsScenario(i); i++)
804cdf0e10cSrcweir 	{
805cdf0e10cSrcweir 		if (pDoc->HasScenarioRange( i, rScenRange ))
806cdf0e10cSrcweir 			if (pDoc->GetName( i, aTabName ))
807cdf0e10cSrcweir 			{
808cdf0e10cSrcweir 				pFilterBox->InsertEntry( aTabName );
809cdf0e10cSrcweir 				if (pDoc->IsActiveScenario(i))
810cdf0e10cSrcweir 					aCurrent = aTabName;
811cdf0e10cSrcweir 				long nTextWidth = pFilterBox->GetTextWidth( aTabName );
812cdf0e10cSrcweir 				if ( nTextWidth > nMaxText )
813cdf0e10cSrcweir 					nMaxText = nTextWidth;
814cdf0e10cSrcweir 				++nEntryCount;
815cdf0e10cSrcweir 			}
816cdf0e10cSrcweir 	}
817cdf0e10cSrcweir 	if (nEntryCount > SC_FILTERLISTBOX_LINES)
818cdf0e10cSrcweir 		nMaxText += GetSettings().GetStyleSettings().GetScrollBarSize();
819cdf0e10cSrcweir 	nMaxText += 4;			// fuer Rand
820cdf0e10cSrcweir 	if ( nMaxText > 300 )
821cdf0e10cSrcweir 		nMaxText = 300;		// auch nicht uebertreiben (Pixel)
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 	if (nMaxText > nSizeX)	// Groesse auf benoetigte Groesse anpassen
824cdf0e10cSrcweir 	{
825cdf0e10cSrcweir 		long nDiff = nMaxText - nSizeX;
826cdf0e10cSrcweir 		aSize = Size( nMaxText, nHeight );
827cdf0e10cSrcweir 		pFilterBox->SetSizePixel( aSize );
828cdf0e10cSrcweir 		pFilterFloat->SetOutputSizePixel( aSize );
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 		if ( !bLayoutRTL )
831cdf0e10cSrcweir 		{
832cdf0e10cSrcweir 			//	also move popup position
833cdf0e10cSrcweir 			long nNewX = aCellRect.Left() - nDiff;
834cdf0e10cSrcweir 			if ( nNewX < 0 )
835cdf0e10cSrcweir 				nNewX = 0;
836cdf0e10cSrcweir 			aCellRect.Left() = nNewX;
837cdf0e10cSrcweir 		}
838cdf0e10cSrcweir 	}
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 	pFilterFloat->SetOutputSizePixel( aSize );
841cdf0e10cSrcweir 	pFilterFloat->StartPopupMode( aCellRect, FLOATWIN_POPUPMODE_DOWN|FLOATWIN_POPUPMODE_GRABFOCUS );
842cdf0e10cSrcweir 
843cdf0e10cSrcweir 	pFilterBox->SetUpdateMode(sal_True);
844cdf0e10cSrcweir 	pFilterBox->GrabFocus();
845cdf0e10cSrcweir 
846cdf0e10cSrcweir 	//	Select erst nach GrabFocus, damit das Focus-Rechteck richtig landet
847cdf0e10cSrcweir //!	SvLBoxEntry* pSelect = NULL;
848cdf0e10cSrcweir 	sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
849cdf0e10cSrcweir 	if (aCurrent.Len())
850cdf0e10cSrcweir 	{
851cdf0e10cSrcweir 		nPos = pFilterBox->GetEntryPos( aCurrent );
852cdf0e10cSrcweir //!		pSelect = pFilterBox->GetEntry( nPos );
853cdf0e10cSrcweir 	}
854cdf0e10cSrcweir 	if (/*!pSelect*/ LISTBOX_ENTRY_NOTFOUND == nPos && pFilterBox->GetEntryCount() > 0 )
855cdf0e10cSrcweir 		nPos = 0;
856cdf0e10cSrcweir //!		pSelect = pFilterBox->GetEntry(0);			// einer sollte immer selektiert sein
857cdf0e10cSrcweir 	if (/*pSelect*/ LISTBOX_ENTRY_NOTFOUND != nPos )
858cdf0e10cSrcweir 		pFilterBox->SelectEntryPos(nPos);
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 	pFilterBox->EndInit();
861cdf0e10cSrcweir 
862cdf0e10cSrcweir 	// Szenario-Auswahl kommt aus MouseButtonDown:
863cdf0e10cSrcweir 	//	der naechste MouseMove auf die Filterbox ist wie ein ButtonDown
864cdf0e10cSrcweir 
865cdf0e10cSrcweir 	nMouseStatus = SC_GM_FILTER;
866cdf0e10cSrcweir 	CaptureMouse();
867cdf0e10cSrcweir }
868cdf0e10cSrcweir 
869*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
870*0deba7fbSSteve Yin sal_Bool ScGridWindow::HasScenarioRange( sal_uInt16 nCol, sal_Int32 nRow, ScRange& rScenRange )
871*0deba7fbSSteve Yin {
872*0deba7fbSSteve Yin 	ScDocument* pDoc = pViewData->GetDocument();
873*0deba7fbSSteve Yin 	sal_uInt16 nTab = pViewData->GetTabNo();
874*0deba7fbSSteve Yin 	sal_uInt16 nTabCount = pDoc->GetTableCount();
875*0deba7fbSSteve Yin 	if ( nTab+1<nTabCount && pDoc->IsScenario(nTab+1) && !pDoc->IsScenario(nTab) )
876*0deba7fbSSteve Yin 	{
877*0deba7fbSSteve Yin 		sal_uInt16 i;
878*0deba7fbSSteve Yin 		ScMarkData aMarks;
879*0deba7fbSSteve Yin 		for (i=nTab+1; i<nTabCount && pDoc->IsScenario(i); i++)
880*0deba7fbSSteve Yin 			pDoc->MarkScenario( i, nTab, aMarks, sal_False, SC_SCENARIO_SHOWFRAME );
881*0deba7fbSSteve Yin 		ScRangeList aRanges;
882*0deba7fbSSteve Yin 		aMarks.FillRangeListWithMarks( &aRanges, sal_False );
883*0deba7fbSSteve Yin 		sal_uInt16 nRangeCount = (sal_uInt16)aRanges.Count();
884*0deba7fbSSteve Yin 		for (i=0; i<nRangeCount; i++)
885*0deba7fbSSteve Yin 		{
886*0deba7fbSSteve Yin 			ScRange aRange = *aRanges.GetObject(i);
887*0deba7fbSSteve Yin 			pDoc->ExtendTotalMerge( aRange );
888*0deba7fbSSteve Yin 			sal_Bool bTextBelow = ( aRange.aStart.Row() == 0 );
889*0deba7fbSSteve Yin 			sal_Bool bIsInScen = sal_False;
890*0deba7fbSSteve Yin 			if ( bTextBelow )
891*0deba7fbSSteve Yin 			{
892*0deba7fbSSteve Yin 				bIsInScen = (aRange.aStart.Col() == nCol && aRange.aEnd.Row() == nRow-1);
893*0deba7fbSSteve Yin 			}
894*0deba7fbSSteve Yin 			else
895*0deba7fbSSteve Yin 			{
896*0deba7fbSSteve Yin 				bIsInScen = (aRange.aStart.Col() == nCol && aRange.aStart.Row() == nRow+1);
897*0deba7fbSSteve Yin 			}
898*0deba7fbSSteve Yin 			if (bIsInScen)
899*0deba7fbSSteve Yin 			{
900*0deba7fbSSteve Yin 				rScenRange = aRange;
901*0deba7fbSSteve Yin 				return sal_True;
902*0deba7fbSSteve Yin 			}
903*0deba7fbSSteve Yin 		}
904*0deba7fbSSteve Yin 	}
905*0deba7fbSSteve Yin 	return sal_False;
906*0deba7fbSSteve Yin }
907*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
908cdf0e10cSrcweir void ScGridWindow::DoAutoFilterMenue( SCCOL nCol, SCROW nRow, sal_Bool bDataSelect )
909cdf0e10cSrcweir {
910cdf0e10cSrcweir 	delete pFilterBox;
911cdf0e10cSrcweir 	delete pFilterFloat;
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 	sal_uInt16 i;
914cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
915cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
916cdf0e10cSrcweir 	sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
917cdf0e10cSrcweir 
918cdf0e10cSrcweir 	long nSizeX  = 0;
919cdf0e10cSrcweir 	long nSizeY  = 0;
920cdf0e10cSrcweir 	long nHeight = 0;
921cdf0e10cSrcweir 	pViewData->GetMergeSizePixel( nCol, nRow, nSizeX, nSizeY );
92251b45b88SJian Fang Zhang 	// The button height should not use the merged cell height, should still use single row height
92351b45b88SJian Fang Zhang 	nSizeY = pViewData->ToPixel(pDoc->GetRowHeight(nRow, nTab), pViewData->GetPPTY());
924cdf0e10cSrcweir 	Point aPos = pViewData->GetScrPos( nCol, nRow, eWhich );
925cdf0e10cSrcweir 	if ( bLayoutRTL )
926cdf0e10cSrcweir 		aPos.X() -= nSizeX;
927cdf0e10cSrcweir 
928cdf0e10cSrcweir 	Rectangle aCellRect( OutputToScreenPixel(aPos), Size(nSizeX,nSizeY) );
929cdf0e10cSrcweir 
930cdf0e10cSrcweir 	aPos.X() -= 1;
931cdf0e10cSrcweir 	aPos.Y() += nSizeY - 1;
932cdf0e10cSrcweir 
933cdf0e10cSrcweir 	pFilterFloat = new ScFilterFloatingWindow( this, WinBits(WB_BORDER) );		// nicht resizable etc.
934cdf0e10cSrcweir 	pFilterFloat->SetPopupModeEndHdl( LINK( this, ScGridWindow, PopupModeEndHdl ) );
935cdf0e10cSrcweir 	pFilterBox = new ScFilterListBox(
936cdf0e10cSrcweir 		pFilterFloat, this, nCol, nRow, bDataSelect ? SC_FILTERBOX_DATASELECT : SC_FILTERBOX_FILTER );
937cdf0e10cSrcweir 	if ( bLayoutRTL )
938cdf0e10cSrcweir 		pFilterBox->EnableMirroring();
939cdf0e10cSrcweir 
940cdf0e10cSrcweir 	nSizeX += 1;
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 	{
943cdf0e10cSrcweir 		Font 	aOldFont = GetFont(); SetFont( pFilterBox->GetFont() );
944cdf0e10cSrcweir 		MapMode aOldMode = GetMapMode(); SetMapMode( MAP_PIXEL );
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 		nHeight  = GetTextHeight();
947cdf0e10cSrcweir 		nHeight *= SC_FILTERLISTBOX_LINES;
948cdf0e10cSrcweir 
949cdf0e10cSrcweir 		SetMapMode( aOldMode );
950cdf0e10cSrcweir 		SetFont( aOldFont );
951cdf0e10cSrcweir 	}
952cdf0e10cSrcweir 
953cdf0e10cSrcweir 	//	SetSize spaeter
954cdf0e10cSrcweir /*
955cdf0e10cSrcweir 	pFilterBox->SetSelectionMode( SINGLE_SELECTION );
956cdf0e10cSrcweir 	pFilterBox->SetTabs( nFilterBoxTabs, MapUnit( MAP_APPFONT ));
957cdf0e10cSrcweir 	pFilterBox->SetTabJustify( 1, bLayoutRTL ? AdjustRight : AdjustLeft );
958cdf0e10cSrcweir */
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 	sal_Bool bEmpty = sal_False;
961cdf0e10cSrcweir 	TypedScStrCollection aStrings( 128, 128 );
962cdf0e10cSrcweir 	if ( bDataSelect )									// Auswahl-Liste
963cdf0e10cSrcweir 	{
964cdf0e10cSrcweir 		//	Liste fuellen
965cdf0e10cSrcweir 		aStrings.SetCaseSensitive( sal_True );
966cdf0e10cSrcweir 		pDoc->GetDataEntries( nCol, nRow, nTab, aStrings );
967cdf0e10cSrcweir 		if ( aStrings.GetCount() == 0 )
968cdf0e10cSrcweir 			bEmpty = sal_True;
969cdf0e10cSrcweir 	}
970cdf0e10cSrcweir 	else												// AutoFilter
971cdf0e10cSrcweir 	{
972cdf0e10cSrcweir 		//!	wird der Titel ueberhaupt ausgewertet ???
973cdf0e10cSrcweir 		String aString;
974cdf0e10cSrcweir 		pDoc->GetString( nCol, nRow, nTab, aString );
975cdf0e10cSrcweir 		pFilterBox->SetText( aString );
976cdf0e10cSrcweir 
977cdf0e10cSrcweir 		long nMaxText = 0;
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 		//	default entries
980cdf0e10cSrcweir         static const sal_uInt16 nDefIDs[] = { SCSTR_ALLFILTER, SCSTR_TOP10FILTER, SCSTR_STDFILTER };
981cdf0e10cSrcweir 		const sal_uInt16 nDefCount = sizeof(nDefIDs) / sizeof(sal_uInt16);
982cdf0e10cSrcweir 		for (i=0; i<nDefCount; i++)
983cdf0e10cSrcweir 		{
984cdf0e10cSrcweir 			String aEntry( (ScResId) nDefIDs[i] );
985cdf0e10cSrcweir 			pFilterBox->InsertEntry( aEntry );
986cdf0e10cSrcweir 			long nTextWidth = pFilterBox->GetTextWidth( aEntry );
987cdf0e10cSrcweir 			if ( nTextWidth > nMaxText )
988cdf0e10cSrcweir 				nMaxText = nTextWidth;
989cdf0e10cSrcweir 		}
990cdf0e10cSrcweir         pFilterBox->SetSeparatorPos( nDefCount - 1 );
991cdf0e10cSrcweir 
992cdf0e10cSrcweir 		//	get list entries
993cdf0e10cSrcweir         bool bHasDates = false;
994cdf0e10cSrcweir         pDoc->GetFilterEntries( nCol, nRow, nTab, true, aStrings, bHasDates);
995cdf0e10cSrcweir         pFilterBox->SetListHasDates(bHasDates);
996cdf0e10cSrcweir 
997cdf0e10cSrcweir 		//	check widths of numerical entries (string entries are not included)
998cdf0e10cSrcweir 		//	so all numbers are completely visible
999cdf0e10cSrcweir 		sal_uInt16 nCount = aStrings.GetCount();
1000cdf0e10cSrcweir 		for (i=0; i<nCount; i++)
1001cdf0e10cSrcweir 		{
1002cdf0e10cSrcweir 			TypedStrData* pData = aStrings[i];
1003cdf0e10cSrcweir 			if ( !pData->IsStrData() )				// only numerical entries
1004cdf0e10cSrcweir 			{
1005cdf0e10cSrcweir 				long nTextWidth = pFilterBox->GetTextWidth( pData->GetString() );
1006cdf0e10cSrcweir 				if ( nTextWidth > nMaxText )
1007cdf0e10cSrcweir 					nMaxText = nTextWidth;
1008cdf0e10cSrcweir 			}
1009cdf0e10cSrcweir 		}
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 		//	add scrollbar width if needed (string entries are counted here)
1012cdf0e10cSrcweir 		//	(scrollbar is shown if the box is exactly full?)
1013cdf0e10cSrcweir 		if ( nCount + nDefCount >= SC_FILTERLISTBOX_LINES )
1014cdf0e10cSrcweir 			nMaxText += GetSettings().GetStyleSettings().GetScrollBarSize();
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir 		nMaxText += 4;				// for borders
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 		if ( nMaxText > nSizeX )
1019cdf0e10cSrcweir 			nSizeX = nMaxText;		// just modify width - starting position is unchanged
1020cdf0e10cSrcweir 	}
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir 	if (!bEmpty)
1023cdf0e10cSrcweir 	{
1024cdf0e10cSrcweir 		//	Position und Groesse an Fenster anpassen
1025cdf0e10cSrcweir 		//!	vorher Abfrage, ob die Eintraege hineinpassen (Breite)
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 		Size aParentSize = GetParent()->GetOutputSizePixel();
1028cdf0e10cSrcweir 		Size aSize( nSizeX, nHeight );
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 		if ( aSize.Height() > aParentSize.Height() )
1031cdf0e10cSrcweir 			aSize.Height() = aParentSize.Height();
1032cdf0e10cSrcweir 		if ( aPos.Y() + aSize.Height() > aParentSize.Height() )
1033cdf0e10cSrcweir 			aPos.Y() = aParentSize.Height() - aSize.Height();
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 		pFilterBox->SetSizePixel( aSize );
1036cdf0e10cSrcweir 		pFilterBox->Show();					// Show muss vor SetUpdateMode kommen !!!
1037cdf0e10cSrcweir 		pFilterBox->SetUpdateMode(sal_False);
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir 		pFilterFloat->SetOutputSizePixel( aSize );
1040cdf0e10cSrcweir 		pFilterFloat->StartPopupMode( aCellRect, FLOATWIN_POPUPMODE_DOWN|FLOATWIN_POPUPMODE_GRABFOCUS);
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir 		//	Listbox fuellen
1043cdf0e10cSrcweir 		sal_uInt16 nCount = aStrings.GetCount();
1044cdf0e10cSrcweir 		sal_Bool bWait = ( nCount > 100 );
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir 		if (bWait)
1047cdf0e10cSrcweir 			EnterWait();
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir 		for (i=0; i<nCount; i++)
1050cdf0e10cSrcweir 			pFilterBox->InsertEntry( aStrings[i]->GetString() );
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 		if (bWait)
1053cdf0e10cSrcweir 			LeaveWait();
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir 		pFilterBox->SetUpdateMode(sal_True);
1056cdf0e10cSrcweir 	}
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir //!	SvLBoxEntry* pSelect = NULL;
1059cdf0e10cSrcweir 	sal_uInt16 nSelPos = LISTBOX_ENTRY_NOTFOUND;
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 	if (!bDataSelect)						// AutoFilter: aktiven Eintrag selektieren
1062cdf0e10cSrcweir 	{
1063cdf0e10cSrcweir 		ScDBData* pDBData = pDoc->GetDBAtCursor( nCol, nRow, nTab );
1064cdf0e10cSrcweir 		if (pDBData)
1065cdf0e10cSrcweir 		{
1066cdf0e10cSrcweir 			ScQueryParam aParam;
1067cdf0e10cSrcweir 			pDBData->GetQueryParam( aParam );		// kann nur MAXQUERY Eintraege ergeben
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir 			sal_Bool bValid = sal_True;
1070cdf0e10cSrcweir 			for (SCSIZE j=0; j<MAXQUERY && bValid; j++)			// bisherige Filter-Einstellungen
1071cdf0e10cSrcweir 				if (aParam.GetEntry(j).bDoQuery)
1072cdf0e10cSrcweir 				{
1073cdf0e10cSrcweir 					//!			Abfrage mit DrawButtons zusammenfassen!
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir 					ScQueryEntry& rEntry = aParam.GetEntry(j);
1076cdf0e10cSrcweir 					if (j>0)
1077cdf0e10cSrcweir 						if (rEntry.eConnect != SC_AND)
1078cdf0e10cSrcweir 							bValid = sal_False;
1079cdf0e10cSrcweir 					if (rEntry.nField == nCol)
1080cdf0e10cSrcweir 					{
1081cdf0e10cSrcweir 						if (rEntry.eOp == SC_EQUAL)
1082cdf0e10cSrcweir 						{
1083cdf0e10cSrcweir 							String* pStr = rEntry.pStr;
1084cdf0e10cSrcweir 							if (pStr)
1085cdf0e10cSrcweir 							{
1086cdf0e10cSrcweir 								nSelPos = pFilterBox->GetEntryPos( *pStr );
1087cdf0e10cSrcweir //!								pSelect = pFilterBox->GetEntry( nPos );
1088cdf0e10cSrcweir 							}
1089cdf0e10cSrcweir 						}
1090cdf0e10cSrcweir 						else if (rEntry.eOp == SC_TOPVAL && rEntry.pStr &&
1091cdf0e10cSrcweir 									rEntry.pStr->EqualsAscii("10"))
1092cdf0e10cSrcweir 							nSelPos = SC_AUTOFILTER_TOP10;
1093cdf0e10cSrcweir 						else
1094cdf0e10cSrcweir 							nSelPos = SC_AUTOFILTER_CUSTOM;
1095cdf0e10cSrcweir 					}
1096cdf0e10cSrcweir 				}
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 			if (!bValid)
1099cdf0e10cSrcweir 				nSelPos = SC_AUTOFILTER_CUSTOM;
1100cdf0e10cSrcweir 		}
1101cdf0e10cSrcweir 	}
1102cdf0e10cSrcweir 	else
1103cdf0e10cSrcweir 	{
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir 		sal_uLong nIndex = ((SfxUInt32Item*)pDoc->GetAttr(
1106cdf0e10cSrcweir 								nCol, nRow, nTab, ATTR_VALIDDATA ))->GetValue();
1107cdf0e10cSrcweir 		if ( nIndex )
1108cdf0e10cSrcweir 		{
1109cdf0e10cSrcweir 			const ScValidationData*	pData = pDoc->GetValidationEntry( nIndex );
1110cdf0e10cSrcweir 			if (pData)
1111cdf0e10cSrcweir 			{
1112cdf0e10cSrcweir 				TypedStrData* pNew = NULL;
1113cdf0e10cSrcweir 				String aDocStr;
1114cdf0e10cSrcweir 				pDoc->GetString( nCol, nRow, nTab, aDocStr );
1115cdf0e10cSrcweir 				if ( pDoc->HasValueData( nCol, nRow, nTab ) )
1116cdf0e10cSrcweir 				{
1117cdf0e10cSrcweir 					double fVal = pDoc->GetValue(ScAddress(nCol, nRow, nTab));
1118cdf0e10cSrcweir 					pNew = new TypedStrData( aDocStr, fVal, SC_STRTYPE_VALUE );
1119cdf0e10cSrcweir 				}
1120cdf0e10cSrcweir 				else
1121cdf0e10cSrcweir 					pNew = new TypedStrData( aDocStr, 0.0, SC_STRTYPE_STANDARD );
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 				bool bSortList = ( pData->GetListType() == ValidListType::SORTEDASCENDING);
1124cdf0e10cSrcweir 				if ( bSortList )
1125cdf0e10cSrcweir 				{
1126cdf0e10cSrcweir 					sal_uInt16 nStrIndex;
1127cdf0e10cSrcweir 					if (aStrings.Search(pNew,nStrIndex))
1128cdf0e10cSrcweir 						nSelPos = nStrIndex;
1129cdf0e10cSrcweir 				}
1130cdf0e10cSrcweir 				else
1131cdf0e10cSrcweir 				{
1132cdf0e10cSrcweir 					sal_uInt16 nCount = aStrings.GetCount();
1133cdf0e10cSrcweir 					for (i = 0; ((i < nCount) && ( LISTBOX_ENTRY_NOTFOUND == nSelPos)); i++)
1134cdf0e10cSrcweir 					{
1135cdf0e10cSrcweir 						if ( aStrings.Compare(aStrings[i], pNew)==0 )
1136cdf0e10cSrcweir 							nSelPos = i;
1137cdf0e10cSrcweir 					}
1138cdf0e10cSrcweir 				}
1139cdf0e10cSrcweir 				delete pNew;
1140cdf0e10cSrcweir 			}
1141cdf0e10cSrcweir 		}
1142cdf0e10cSrcweir 	}
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir 		//	neu (309): irgendwas muss immer selektiert sein:
1145cdf0e10cSrcweir 	if ( LISTBOX_ENTRY_NOTFOUND == nSelPos && pFilterBox->GetEntryCount() > 0 && !bDataSelect)
1146cdf0e10cSrcweir 		nSelPos = 0;
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 	//	keine leere Auswahl-Liste anzeigen:
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 	if ( bEmpty )
1151cdf0e10cSrcweir 	{
1152cdf0e10cSrcweir 		DELETEZ(pFilterBox);				// war nix
1153cdf0e10cSrcweir 		DELETEZ(pFilterFloat);
1154cdf0e10cSrcweir 		Sound::Beep();						// bemerkbar machen
1155cdf0e10cSrcweir 	}
1156cdf0e10cSrcweir 	else
1157cdf0e10cSrcweir 	{
1158cdf0e10cSrcweir //		pFilterBox->Show();					// schon vorne
1159cdf0e10cSrcweir 		pFilterBox->GrabFocus();
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir 			//	Select erst nach GrabFocus, damit das Focus-Rechteck richtig landet
1162cdf0e10cSrcweir 		if ( LISTBOX_ENTRY_NOTFOUND != nSelPos )
1163cdf0e10cSrcweir 			pFilterBox->SelectEntryPos( nSelPos );
1164cdf0e10cSrcweir 		else
1165cdf0e10cSrcweir 		{
1166cdf0e10cSrcweir 			if (bDataSelect)
1167cdf0e10cSrcweir 				pFilterBox->SetNoSelection();
1168cdf0e10cSrcweir 		}
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir 		pFilterBox->EndInit();
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir 		if (!bDataSelect)
1173cdf0e10cSrcweir 		{
1174cdf0e10cSrcweir 			// AutoFilter (aus MouseButtonDown):
1175cdf0e10cSrcweir 			//	der naechste MouseMove auf die Filterbox ist wie ein ButtonDown
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir 			nMouseStatus = SC_GM_FILTER;
1178cdf0e10cSrcweir 			CaptureMouse();
1179cdf0e10cSrcweir 		}
1180cdf0e10cSrcweir 	}
1181cdf0e10cSrcweir }
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir void ScGridWindow::FilterSelect( sal_uLong nSel )
1184cdf0e10cSrcweir {
1185cdf0e10cSrcweir 	String aString;
1186cdf0e10cSrcweir /*
1187cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pFilterBox->GetEntry( nSel );
1188cdf0e10cSrcweir 	if (pEntry)
1189cdf0e10cSrcweir 	{
1190cdf0e10cSrcweir 		SvLBoxString* pStringEntry = (SvLBoxString*) pEntry->GetFirstItem( SV_ITEM_ID_LBOXSTRING );
1191cdf0e10cSrcweir 		if ( pStringEntry )
1192cdf0e10cSrcweir 			aString = pStringEntry->GetText();
1193cdf0e10cSrcweir 	}
1194cdf0e10cSrcweir */
1195cdf0e10cSrcweir 	aString = pFilterBox->GetEntry( static_cast< sal_uInt16 >( nSel ) );
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir 	SCCOL nCol = pFilterBox->GetCol();
1198cdf0e10cSrcweir 	SCROW nRow = pFilterBox->GetRow();
1199cdf0e10cSrcweir 	switch ( pFilterBox->GetMode() )
1200cdf0e10cSrcweir 	{
1201cdf0e10cSrcweir 		case SC_FILTERBOX_DATASELECT:
1202cdf0e10cSrcweir 			ExecDataSelect( nCol, nRow, aString );
1203cdf0e10cSrcweir 			break;
1204cdf0e10cSrcweir 		case SC_FILTERBOX_FILTER:
1205cdf0e10cSrcweir             ExecFilter( nSel, nCol, nRow, aString, pFilterBox->HasDates() );
1206cdf0e10cSrcweir 			break;
1207cdf0e10cSrcweir 		case SC_FILTERBOX_SCENARIO:
1208cdf0e10cSrcweir 			pViewData->GetView()->UseScenario( aString );
1209cdf0e10cSrcweir 			break;
1210cdf0e10cSrcweir 		case SC_FILTERBOX_PAGEFIELD:
1211cdf0e10cSrcweir 			// first entry is "all"
1212cdf0e10cSrcweir 			ExecPageFieldSelect( nCol, nRow, (nSel != 0), aString );
1213cdf0e10cSrcweir 			break;
1214cdf0e10cSrcweir 	}
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir 	if (pFilterFloat)
1217cdf0e10cSrcweir 		pFilterFloat->EndPopupMode();
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir 	GrabFocus();		// unter OS/2 stimmt der Focus sonst nicht
1220cdf0e10cSrcweir }
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir void ScGridWindow::ExecDataSelect( SCCOL nCol, SCROW nRow, const String& rStr )
1223cdf0e10cSrcweir {
1224cdf0e10cSrcweir     if ( rStr.Len() )
1225cdf0e10cSrcweir     {
1226cdf0e10cSrcweir         SCTAB nTab = pViewData->GetTabNo();
1227cdf0e10cSrcweir         ScViewFunc* pView = pViewData->GetView();
1228cdf0e10cSrcweir         pView->EnterData( nCol, nRow, nTab, rStr );
1229cdf0e10cSrcweir 
1230cdf0e10cSrcweir         // #i52307# CellContentChanged is not in EnterData so it isn't called twice
1231cdf0e10cSrcweir         // if the cursor is moved afterwards.
1232cdf0e10cSrcweir         pView->CellContentChanged();
1233cdf0e10cSrcweir     }
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir void ScGridWindow::ExecFilter( sal_uLong nSel,
1237cdf0e10cSrcweir 							   SCCOL nCol, SCROW nRow,
1238cdf0e10cSrcweir                                const String& aValue, bool bCheckForDates )
1239cdf0e10cSrcweir {
1240cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
1241cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir 	ScDBData* pDBData = pDoc->GetDBAtCursor( nCol, nRow, nTab );
1244cdf0e10cSrcweir 	if (pDBData)
1245cdf0e10cSrcweir 	{
1246cdf0e10cSrcweir 		ScQueryParam aParam;
1247cdf0e10cSrcweir 		pDBData->GetQueryParam( aParam );		// kann nur MAXQUERY Eintraege ergeben
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir 		if (SC_AUTOFILTER_CUSTOM == nSel)
1250cdf0e10cSrcweir 		{
1251cdf0e10cSrcweir 			SCTAB nAreaTab;
1252cdf0e10cSrcweir 			SCCOL nStartCol;
1253cdf0e10cSrcweir 			SCROW nStartRow;
1254cdf0e10cSrcweir 			SCCOL nEndCol;
1255cdf0e10cSrcweir 			SCROW nEndRow;
1256cdf0e10cSrcweir 			pDBData->GetArea( nAreaTab, nStartCol,nStartRow,nEndCol,nEndRow );
1257cdf0e10cSrcweir 			pViewData->GetView()->MarkRange( ScRange( nStartCol,nStartRow,nAreaTab,nEndCol,nEndRow,nAreaTab));
1258cdf0e10cSrcweir 			pViewData->GetView()->SetCursor(nCol,nRow);		//! auch ueber Slot ??
1259cdf0e10cSrcweir 			pViewData->GetDispatcher().Execute( SID_FILTER, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
1260cdf0e10cSrcweir 		}
1261cdf0e10cSrcweir 		else
1262cdf0e10cSrcweir 		{
1263cdf0e10cSrcweir 			sal_Bool bDeleteOld = sal_False;
1264cdf0e10cSrcweir 			SCSIZE nQueryPos = 0;
1265cdf0e10cSrcweir 			sal_Bool bFound = sal_False;
1266cdf0e10cSrcweir 			if (!aParam.bInplace)
1267cdf0e10cSrcweir 				bDeleteOld = sal_True;
1268cdf0e10cSrcweir 			if (aParam.bRegExp)
1269cdf0e10cSrcweir 				bDeleteOld = sal_True;
1270cdf0e10cSrcweir 			for (SCSIZE i=0; i<MAXQUERY && !bDeleteOld; i++)	// bisherige Filter-Einstellungen
1271cdf0e10cSrcweir 				if (aParam.GetEntry(i).bDoQuery)
1272cdf0e10cSrcweir 				{
1273cdf0e10cSrcweir 					//!			Abfrage mit DrawButtons zusammenfassen!
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir 					ScQueryEntry& rEntry = aParam.GetEntry(i);
1276cdf0e10cSrcweir 					if (i>0)
1277cdf0e10cSrcweir 						if (rEntry.eConnect != SC_AND)
1278cdf0e10cSrcweir 							bDeleteOld = sal_True;
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir 					if (rEntry.nField == nCol)
1281cdf0e10cSrcweir 					{
1282cdf0e10cSrcweir 						if (bFound)							// diese Spalte zweimal?
1283cdf0e10cSrcweir 							bDeleteOld = sal_True;
1284cdf0e10cSrcweir 						nQueryPos = i;
1285cdf0e10cSrcweir 						bFound = sal_True;
1286cdf0e10cSrcweir 					}
1287cdf0e10cSrcweir 					if (!bFound)
1288cdf0e10cSrcweir 						nQueryPos = i + 1;
1289cdf0e10cSrcweir 				}
1290cdf0e10cSrcweir 
1291cdf0e10cSrcweir 			if (bDeleteOld)
1292cdf0e10cSrcweir 			{
1293cdf0e10cSrcweir 				SCSIZE nEC = aParam.GetEntryCount();
1294cdf0e10cSrcweir 				for (SCSIZE i=0; i<nEC; i++)
1295cdf0e10cSrcweir                     aParam.GetEntry(i).Clear();
1296cdf0e10cSrcweir 				nQueryPos = 0;
1297cdf0e10cSrcweir 				aParam.bInplace = sal_True;
1298cdf0e10cSrcweir 				aParam.bRegExp = sal_False;
1299cdf0e10cSrcweir 			}
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir 			if ( nQueryPos < MAXQUERY || SC_AUTOFILTER_ALL == nSel )	// loeschen geht immer
1302cdf0e10cSrcweir 			{
1303cdf0e10cSrcweir 				if (nSel)
1304cdf0e10cSrcweir 				{
1305cdf0e10cSrcweir 					ScQueryEntry& rNewEntry = aParam.GetEntry(nQueryPos);
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir 					rNewEntry.bDoQuery		 = sal_True;
1308cdf0e10cSrcweir 					rNewEntry.bQueryByString = sal_True;
1309cdf0e10cSrcweir 					rNewEntry.nField		 = nCol;
1310cdf0e10cSrcweir                     rNewEntry.bQueryByDate   = bCheckForDates;
1311cdf0e10cSrcweir 					if ( nSel == SC_AUTOFILTER_TOP10 )
1312cdf0e10cSrcweir 					{
1313cdf0e10cSrcweir 						rNewEntry.eOp	= SC_TOPVAL;
1314cdf0e10cSrcweir 						*rNewEntry.pStr	= String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("10"));
1315cdf0e10cSrcweir 					}
1316cdf0e10cSrcweir 					else
1317cdf0e10cSrcweir 					{
1318cdf0e10cSrcweir 						rNewEntry.eOp	= SC_EQUAL;
1319cdf0e10cSrcweir 						*rNewEntry.pStr	= aValue;
1320cdf0e10cSrcweir 					}
1321cdf0e10cSrcweir 					if (nQueryPos > 0)
1322cdf0e10cSrcweir 						rNewEntry.eConnect   = SC_AND;
1323cdf0e10cSrcweir 				}
1324cdf0e10cSrcweir 				else
1325cdf0e10cSrcweir 				{
1326cdf0e10cSrcweir 					if (bFound)
1327cdf0e10cSrcweir 						aParam.DeleteQuery(nQueryPos);
1328cdf0e10cSrcweir 				}
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir 				//	#100597# end edit mode - like in ScCellShell::ExecuteDB
1331cdf0e10cSrcweir 				if ( pViewData->HasEditView( pViewData->GetActivePart() ) )
1332cdf0e10cSrcweir 				{
1333cdf0e10cSrcweir 					SC_MOD()->InputEnterHandler();
1334cdf0e10cSrcweir 					pViewData->GetViewShell()->UpdateInputHandler();
1335cdf0e10cSrcweir 				}
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir 				pViewData->GetView()->Query( aParam, NULL, sal_True );
1338cdf0e10cSrcweir 				pDBData->SetQueryParam( aParam );							// speichern
1339cdf0e10cSrcweir 			}
1340cdf0e10cSrcweir 			else					//	"Zuviele Bedingungen"
1341cdf0e10cSrcweir 				pViewData->GetView()->ErrorMessage( STR_FILTER_TOOMANY );
1342cdf0e10cSrcweir 		}
1343cdf0e10cSrcweir 	}
1344cdf0e10cSrcweir 	else
1345cdf0e10cSrcweir 	{
1346cdf0e10cSrcweir 		DBG_ERROR("Wo ist der Datenbankbereich?");
1347cdf0e10cSrcweir 	}
1348cdf0e10cSrcweir }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir void ScGridWindow::SetPointer( const Pointer& rPointer )
1351cdf0e10cSrcweir {
1352cdf0e10cSrcweir 	nCurrentPointer = 0;
1353cdf0e10cSrcweir 	Window::SetPointer( rPointer );
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir void ScGridWindow::MoveMouseStatus( ScGridWindow& rDestWin )
1357cdf0e10cSrcweir {
1358cdf0e10cSrcweir 	if (nButtonDown)
1359cdf0e10cSrcweir 	{
1360cdf0e10cSrcweir 		rDestWin.nButtonDown = nButtonDown;
1361cdf0e10cSrcweir 		rDestWin.nMouseStatus = nMouseStatus;
1362cdf0e10cSrcweir 	}
1363cdf0e10cSrcweir 
1364cdf0e10cSrcweir 	if (bRFMouse)
1365cdf0e10cSrcweir 	{
1366cdf0e10cSrcweir 		rDestWin.bRFMouse = bRFMouse;
1367cdf0e10cSrcweir 		rDestWin.bRFSize  = bRFSize;
1368cdf0e10cSrcweir 		rDestWin.nRFIndex = nRFIndex;
1369cdf0e10cSrcweir 		rDestWin.nRFAddX  = nRFAddX;
1370cdf0e10cSrcweir 		rDestWin.nRFAddY  = nRFAddY;
1371cdf0e10cSrcweir 		bRFMouse = sal_False;
1372cdf0e10cSrcweir 	}
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir 	if (nPagebreakMouse)
1375cdf0e10cSrcweir 	{
1376cdf0e10cSrcweir 		rDestWin.nPagebreakMouse  = nPagebreakMouse;
1377cdf0e10cSrcweir 		rDestWin.nPagebreakBreak  = nPagebreakBreak;
1378cdf0e10cSrcweir 		rDestWin.nPagebreakPrev   = nPagebreakPrev;
1379cdf0e10cSrcweir 		rDestWin.aPagebreakSource = aPagebreakSource;
1380cdf0e10cSrcweir 		rDestWin.aPagebreakDrag   = aPagebreakDrag;
1381cdf0e10cSrcweir 		nPagebreakMouse = SC_PD_NONE;
1382cdf0e10cSrcweir 	}
1383cdf0e10cSrcweir }
1384cdf0e10cSrcweir 
1385cdf0e10cSrcweir sal_Bool ScGridWindow::TestMouse( const MouseEvent& rMEvt, sal_Bool bAction )
1386cdf0e10cSrcweir {
1387cdf0e10cSrcweir 	//	MouseEvent buttons must only be checked if bAction==TRUE
1388cdf0e10cSrcweir 	//	to allow changing the mouse pointer in MouseMove,
1389cdf0e10cSrcweir 	//	but not start AutoFill with right button (#74229#).
1390cdf0e10cSrcweir 	//	with bAction==sal_True, SetFillMode / SetDragMode is called
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir 	if ( bAction && !rMEvt.IsLeft() )
1393cdf0e10cSrcweir 		return sal_False;
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir 	sal_Bool bNewPointer = sal_False;
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir 	SfxInPlaceClient* pClient = pViewData->GetViewShell()->GetIPClient();
1398cdf0e10cSrcweir     sal_Bool bOleActive = ( pClient && pClient->IsObjectInPlaceActive() );
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir 	if ( pViewData->IsActive() && !bOleActive )
1401cdf0e10cSrcweir 	{
1402cdf0e10cSrcweir 		ScDocument* pDoc = pViewData->GetDocument();
1403cdf0e10cSrcweir 		SCTAB nTab = pViewData->GetTabNo();
1404cdf0e10cSrcweir 		sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir 		//	Auto-Fill
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir 		ScRange aMarkRange;
1409cdf0e10cSrcweir 		if (pViewData->GetSimpleArea( aMarkRange ) == SC_MARK_SIMPLE)
1410cdf0e10cSrcweir 		{
1411cdf0e10cSrcweir             if (aMarkRange.aStart.Tab() == pViewData->GetTabNo() && mpAutoFillRect)
1412cdf0e10cSrcweir 			{
1413cdf0e10cSrcweir 				Point aMousePos = rMEvt.GetPosPixel();
1414cdf0e10cSrcweir                 if (mpAutoFillRect->IsInside(aMousePos))
1415cdf0e10cSrcweir 				{
1416cdf0e10cSrcweir                     SetPointer( Pointer( POINTER_CROSS ) );     //! dickeres Kreuz ?
1417cdf0e10cSrcweir 					if (bAction)
1418cdf0e10cSrcweir 					{
1419cdf0e10cSrcweir                         SCCOL nX = aMarkRange.aEnd.Col();
1420cdf0e10cSrcweir                         SCROW nY = aMarkRange.aEnd.Row();
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 						if ( lcl_IsEditableMatrix( pViewData->GetDocument(), aMarkRange ) )
1423cdf0e10cSrcweir 							pViewData->SetDragMode(
1424cdf0e10cSrcweir 								aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), nX, nY, SC_FILL_MATRIX );
1425cdf0e10cSrcweir 						else
1426cdf0e10cSrcweir 							pViewData->SetFillMode(
1427cdf0e10cSrcweir 								aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), nX, nY );
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 						//	#108266# The simple selection must also be recognized when dragging,
1430cdf0e10cSrcweir 						//	where the Marking flag is set and MarkToSimple won't work anymore.
1431cdf0e10cSrcweir 						pViewData->GetMarkData().MarkToSimple();
1432cdf0e10cSrcweir 					}
1433cdf0e10cSrcweir 					bNewPointer = sal_True;
1434cdf0e10cSrcweir 				}
1435cdf0e10cSrcweir 			}
1436cdf0e10cSrcweir 		}
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir 		//	Embedded-Rechteck
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 		if (pDoc->IsEmbedded())
1441cdf0e10cSrcweir 		{
1442cdf0e10cSrcweir             ScRange aRange;
1443cdf0e10cSrcweir 			pDoc->GetEmbedded( aRange );
1444cdf0e10cSrcweir 			if ( pViewData->GetTabNo() == aRange.aStart.Tab() )
1445cdf0e10cSrcweir 			{
1446cdf0e10cSrcweir 				Point aStartPos = pViewData->GetScrPos( aRange.aStart.Col(), aRange.aStart.Row(), eWhich );
1447cdf0e10cSrcweir 				Point aEndPos   = pViewData->GetScrPos( aRange.aEnd.Col()+1, aRange.aEnd.Row()+1, eWhich );
1448cdf0e10cSrcweir 				Point aMousePos = rMEvt.GetPosPixel();
1449cdf0e10cSrcweir 				if ( bLayoutRTL )
1450cdf0e10cSrcweir 				{
1451cdf0e10cSrcweir 					aStartPos.X() += 2;
1452cdf0e10cSrcweir 					aEndPos.X()   += 2;
1453cdf0e10cSrcweir 				}
1454cdf0e10cSrcweir 				sal_Bool bTop = ( aMousePos.X() >= aStartPos.X()-3 && aMousePos.X() <= aStartPos.X()+1 &&
1455cdf0e10cSrcweir 							  aMousePos.Y() >= aStartPos.Y()-3 && aMousePos.Y() <= aStartPos.Y()+1 );
1456cdf0e10cSrcweir 				sal_Bool bBottom = ( aMousePos.X() >= aEndPos.X()-3 && aMousePos.X() <= aEndPos.X()+1 &&
1457cdf0e10cSrcweir 								 aMousePos.Y() >= aEndPos.Y()-3 && aMousePos.Y() <= aEndPos.Y()+1 );
1458cdf0e10cSrcweir 				if ( bTop || bBottom )
1459cdf0e10cSrcweir 				{
1460cdf0e10cSrcweir 					SetPointer( Pointer( POINTER_CROSS ) );
1461cdf0e10cSrcweir 					if (bAction)
1462cdf0e10cSrcweir 					{
1463cdf0e10cSrcweir 						sal_uInt8 nMode = bTop ? SC_FILL_EMBED_LT : SC_FILL_EMBED_RB;
1464cdf0e10cSrcweir 						pViewData->SetDragMode(
1465cdf0e10cSrcweir 									aRange.aStart.Col(), aRange.aStart.Row(),
1466cdf0e10cSrcweir 									aRange.aEnd.Col(), aRange.aEnd.Row(), nMode );
1467cdf0e10cSrcweir 					}
1468cdf0e10cSrcweir 					bNewPointer = sal_True;
1469cdf0e10cSrcweir 				}
1470cdf0e10cSrcweir 			}
1471cdf0e10cSrcweir 		}
1472cdf0e10cSrcweir 	}
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir 	if (!bNewPointer && bAction)
1475cdf0e10cSrcweir 	{
1476cdf0e10cSrcweir //		SetPointer( POINTER_ARROW );			// in Fu...
1477cdf0e10cSrcweir 		pViewData->ResetFillMode();
1478cdf0e10cSrcweir 	}
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir 	return bNewPointer;
1481cdf0e10cSrcweir }
1482cdf0e10cSrcweir 
1483cdf0e10cSrcweir void __EXPORT ScGridWindow::MouseButtonDown( const MouseEvent& rMEvt )
1484cdf0e10cSrcweir {
1485cdf0e10cSrcweir     nNestedButtonState = SC_NESTEDBUTTON_DOWN;
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir     HandleMouseButtonDown( rMEvt );
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir     if ( nNestedButtonState == SC_NESTEDBUTTON_UP )
1490cdf0e10cSrcweir     {
1491cdf0e10cSrcweir         // #i41690# If an object is deactivated from MouseButtonDown, it might reschedule,
1492cdf0e10cSrcweir         // so MouseButtonUp comes before the MouseButtonDown call is finished. In this case,
1493cdf0e10cSrcweir         // simulate another MouseButtonUp call, so the selection state is consistent.
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir         nButtonDown = rMEvt.GetButtons();
1496cdf0e10cSrcweir         FakeButtonUp();
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir         if ( IsTracking() )
1499cdf0e10cSrcweir             EndTracking();      // normally done in VCL as part of MouseButtonUp handling
1500cdf0e10cSrcweir     }
1501cdf0e10cSrcweir     nNestedButtonState = SC_NESTEDBUTTON_NONE;
1502cdf0e10cSrcweir }
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt )
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir     // We have to check if a context menu is shown and we have an UI
1507cdf0e10cSrcweir     // active inplace client. In that case we have to ignore the event.
1508cdf0e10cSrcweir     // Otherwise we would crash (context menu has been
1509cdf0e10cSrcweir     // opened by inplace client and we would deactivate the inplace client,
1510cdf0e10cSrcweir     // the contex menu is closed by VCL asynchronously which in the end
1511cdf0e10cSrcweir     // would work on deleted objects or the context menu has no parent anymore)
1512cdf0e10cSrcweir     // See #126086# and #128122#
1513cdf0e10cSrcweir 	SfxViewShell* pViewSh = pViewData->GetViewShell();
1514cdf0e10cSrcweir 	SfxInPlaceClient* pClient = pViewSh->GetIPClient();
1515cdf0e10cSrcweir     if ( pClient &&
1516cdf0e10cSrcweir          pClient->IsObjectInPlaceActive() &&
1517cdf0e10cSrcweir          PopupMenu::IsInExecute() )
1518cdf0e10cSrcweir         return;
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir     aCurMousePos = rMEvt.GetPosPixel();
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir 	//	Filter-Popup beendet sich mit eigenem Mausklick, nicht erst beim Klick
1523cdf0e10cSrcweir 	//	in das GridWindow, darum ist die folgende Abfrage nicht mehr noetig:
1524cdf0e10cSrcweir #if 0
1525cdf0e10cSrcweir 	// merken, dass FilterBox geloescht wird, damit sichergestellt
1526cdf0e10cSrcweir 	// ist, dass in diesem Handler nicht an gleicher Stelle wieder
1527cdf0e10cSrcweir 	// eine neue geoeffnet wird.
1528cdf0e10cSrcweir 	sal_Bool	bWasFilterBox = ( pFilterBox != NULL &&
1529cdf0e10cSrcweir 								((Window*)pFilterBox)->IsVisible() &&
1530cdf0e10cSrcweir 								!pFilterBox->IsDataSelect() );
1531cdf0e10cSrcweir 	SCCOL	nOldColFBox	  = bWasFilterBox ? pFilterBox->GetCol() : 0;
1532cdf0e10cSrcweir 	SCROW  nOldRowFBox	  = bWasFilterBox ? pFilterBox->GetRow() : 0;
1533cdf0e10cSrcweir #endif
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir 	ClickExtern();	// loescht FilterBox, wenn vorhanden
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir 	HideNoteMarker();	// Notiz-Anzeige
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir 	bEEMouse = sal_False;
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
1542cdf0e10cSrcweir 	if (pScMod->IsModalMode(pViewData->GetSfxDocShell()))
1543cdf0e10cSrcweir 	{
1544cdf0e10cSrcweir 		Sound::Beep();
1545cdf0e10cSrcweir 		return;
1546cdf0e10cSrcweir 	}
1547cdf0e10cSrcweir 
1548cdf0e10cSrcweir 	pScActiveViewShell = pViewData->GetViewShell();			// falls auf Link geklickt wird
1549cdf0e10cSrcweir 	nScClickMouseModifier = rMEvt.GetModifier();			// um Control-Klick immer zu erkennen
1550cdf0e10cSrcweir 
1551cdf0e10cSrcweir 	sal_Bool bDetective = pViewData->GetViewShell()->IsAuditShell();
1552cdf0e10cSrcweir 	sal_Bool bRefMode =	pViewData->IsRefMode();					// Referenz angefangen
1553cdf0e10cSrcweir 	sal_Bool bFormulaMode = pScMod->IsFormulaMode();			// naechster Klick -> Referenz
1554cdf0e10cSrcweir 	sal_Bool bEditMode = pViewData->HasEditView(eWhich);		// auch bei Mode==SC_INPUT_TYPE
1555cdf0e10cSrcweir     sal_Bool bDouble = (rMEvt.GetClicks() == 2);
1556cdf0e10cSrcweir 
1557cdf0e10cSrcweir 	//	DeactivateIP passiert nur noch bei MarkListHasChanged
1558cdf0e10cSrcweir 
1559cdf0e10cSrcweir 	//	im GrabFocus Aufruf kann eine Fehlermeldung hochkommen
1560cdf0e10cSrcweir 	//	(z.B. beim Umbenennen von Tabellen per Tab-Reiter)
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir     if ( !nButtonDown || !bDouble )             // single (first) click is always valid
1563cdf0e10cSrcweir         nButtonDown = rMEvt.GetButtons();       // set nButtonDown first, so StopMarking works
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir //	pViewData->GetViewShell()->GetViewFrame()->GetWindow().GrabFocus();
1566cdf0e10cSrcweir 	if ( ( bEditMode && pViewData->GetActivePart() == eWhich ) || !bFormulaMode )
1567cdf0e10cSrcweir 		GrabFocus();
1568cdf0e10cSrcweir 
1569cdf0e10cSrcweir     // #i31846# need to cancel a double click if the first click has set the "ignore" state,
1570cdf0e10cSrcweir     // but a single (first) click is always valid
1571cdf0e10cSrcweir     if ( nMouseStatus == SC_GM_IGNORE && bDouble )
1572cdf0e10cSrcweir 	{
1573cdf0e10cSrcweir 		nButtonDown = 0;
1574cdf0e10cSrcweir 		nMouseStatus = SC_GM_NONE;
1575cdf0e10cSrcweir 		return;
1576cdf0e10cSrcweir 	}
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir 	if ( bDetective )				// Detektiv-Fuell-Modus
1579cdf0e10cSrcweir 	{
1580cdf0e10cSrcweir 		if ( rMEvt.IsLeft() && !rMEvt.GetModifier() )
1581cdf0e10cSrcweir 		{
1582cdf0e10cSrcweir 			Point	aPos = rMEvt.GetPosPixel();
1583cdf0e10cSrcweir 			SCsCOL	nPosX;
1584cdf0e10cSrcweir 			SCsROW	nPosY;
1585cdf0e10cSrcweir 			pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir 			SfxInt16Item aPosXItem( SID_RANGE_COL, nPosX );
1588cdf0e10cSrcweir 			SfxInt32Item aPosYItem( SID_RANGE_ROW, nPosY );
1589cdf0e10cSrcweir 			pViewData->GetDispatcher().Execute( SID_FILL_SELECT, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
1590cdf0e10cSrcweir 										&aPosXItem, &aPosYItem, (void*)0L );
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir 		}
1593cdf0e10cSrcweir 		nButtonDown = 0;
1594cdf0e10cSrcweir 		nMouseStatus = SC_GM_NONE;
1595cdf0e10cSrcweir 		return;
1596cdf0e10cSrcweir 	}
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir 	if (!bDouble)
1599cdf0e10cSrcweir 		nMouseStatus = SC_GM_NONE;
1600cdf0e10cSrcweir 
1601cdf0e10cSrcweir 	if (!bFormulaMode)
1602cdf0e10cSrcweir 	{
1603cdf0e10cSrcweir 		if ( pViewData->GetActivePart() != eWhich )
1604cdf0e10cSrcweir 			pViewData->GetView()->ActivatePart( eWhich );
1605cdf0e10cSrcweir 	}
1606cdf0e10cSrcweir 	else
1607cdf0e10cSrcweir 	{
1608cdf0e10cSrcweir 		ScViewSelectionEngine* pSelEng = pViewData->GetView()->GetSelEngine();
1609cdf0e10cSrcweir 		pSelEng->SetWindow(this);
1610cdf0e10cSrcweir 		pSelEng->SetWhich(eWhich);
1611cdf0e10cSrcweir 		pSelEng->SetVisibleArea( Rectangle(Point(), GetOutputSizePixel()) );
1612cdf0e10cSrcweir 	}
1613cdf0e10cSrcweir 
1614cdf0e10cSrcweir 	if (bEditMode && (pViewData->GetRefTabNo() == pViewData->GetTabNo()))
1615cdf0e10cSrcweir 	{
1616cdf0e10cSrcweir 		Point	aPos = rMEvt.GetPosPixel();
1617cdf0e10cSrcweir 		SCsCOL	nPosX;
1618cdf0e10cSrcweir 		SCsROW	nPosY;
1619cdf0e10cSrcweir 		pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
1620cdf0e10cSrcweir 
1621cdf0e10cSrcweir 		EditView*	pEditView;
1622cdf0e10cSrcweir 		SCCOL		nEditCol;
1623cdf0e10cSrcweir 		SCROW		nEditRow;
1624cdf0e10cSrcweir 		pViewData->GetEditView( eWhich, pEditView, nEditCol, nEditRow );
1625cdf0e10cSrcweir 		SCCOL nEndCol = pViewData->GetEditEndCol();
1626cdf0e10cSrcweir 		SCROW nEndRow = pViewData->GetEditEndRow();
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir 		if ( nPosX >= (SCsCOL) nEditCol && nPosX <= (SCsCOL) nEndCol &&
1629cdf0e10cSrcweir 			 nPosY >= (SCsROW) nEditRow && nPosY <= (SCsROW) nEndRow )
1630cdf0e10cSrcweir 		{
1631cdf0e10cSrcweir 			//	#53966# beim Klick in die Tabellen-EditView immer den Focus umsetzen
1632cdf0e10cSrcweir 			if (bFormulaMode)	// sonst ist es oben schon passiert
1633cdf0e10cSrcweir 				GrabFocus();
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir 			pScMod->SetInputMode( SC_INPUT_TABLE );
1636cdf0e10cSrcweir 			bEEMouse = sal_True;
1637cdf0e10cSrcweir 			bEditMode = pEditView->MouseButtonDown( rMEvt );
1638cdf0e10cSrcweir 			return;
1639cdf0e10cSrcweir 		}
1640cdf0e10cSrcweir 	}
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 	if (pScMod->GetIsWaterCan())
1643cdf0e10cSrcweir 	{
1644cdf0e10cSrcweir 		//!		was is mit'm Mac ???
1645cdf0e10cSrcweir 		if ( rMEvt.GetModifier() + rMEvt.GetButtons() == MOUSE_RIGHT )
1646cdf0e10cSrcweir 		{
1647cdf0e10cSrcweir 			nMouseStatus = SC_GM_WATERUNDO;
1648cdf0e10cSrcweir 			return;
1649cdf0e10cSrcweir 		}
1650cdf0e10cSrcweir 	}
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir 	// Reihenfolge passend zum angezeigten Cursor:
1653cdf0e10cSrcweir 	//	RangeFinder, AutoFill, PageBreak, Drawing
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir 	if ( HitRangeFinder( rMEvt.GetPosPixel(), bRFSize, &nRFIndex, &nRFAddX, &nRFAddY ) )
1656cdf0e10cSrcweir 	{
1657cdf0e10cSrcweir 		bRFMouse = sal_True;		// die anderen Variablen sind oben initialisiert
1658cdf0e10cSrcweir 
1659cdf0e10cSrcweir 		if ( pViewData->GetActivePart() != eWhich )
1660cdf0e10cSrcweir 			pViewData->GetView()->ActivatePart( eWhich );	//! schon oben immer ???
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir 		// CaptureMouse();
1663cdf0e10cSrcweir 		StartTracking();
1664cdf0e10cSrcweir 		return;
1665cdf0e10cSrcweir 	}
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir 	sal_Bool bCrossPointer = TestMouse( rMEvt, sal_True );
1668cdf0e10cSrcweir 	if ( bCrossPointer )
1669cdf0e10cSrcweir 	{
1670cdf0e10cSrcweir 		if ( bDouble )
1671cdf0e10cSrcweir 			pViewData->GetView()->FillCrossDblClick();
1672cdf0e10cSrcweir 		else
1673cdf0e10cSrcweir 		pScMod->InputEnterHandler();								// Autofill etc.
1674cdf0e10cSrcweir 	}
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir 	if ( !bCrossPointer )
1677cdf0e10cSrcweir 	{
1678cdf0e10cSrcweir 		nPagebreakMouse = HitPageBreak( rMEvt.GetPosPixel(), &aPagebreakSource,
1679cdf0e10cSrcweir 											&nPagebreakBreak, &nPagebreakPrev );
1680cdf0e10cSrcweir 		if (nPagebreakMouse)
1681cdf0e10cSrcweir 		{
1682cdf0e10cSrcweir 			bPagebreakDrawn = sal_False;
1683cdf0e10cSrcweir 			// CaptureMouse();
1684cdf0e10cSrcweir 			StartTracking();
1685cdf0e10cSrcweir 			PagebreakMove( rMEvt, sal_False );
1686cdf0e10cSrcweir 			return;
1687cdf0e10cSrcweir 		}
1688cdf0e10cSrcweir 	}
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir 	if (!bFormulaMode && !bEditMode && rMEvt.IsLeft())
1691cdf0e10cSrcweir 	{
1692cdf0e10cSrcweir 		if ( !bCrossPointer && DrawMouseButtonDown(rMEvt) )
1693cdf0e10cSrcweir 		{
1694cdf0e10cSrcweir 			//if (DrawHasMarkedObj())
1695cdf0e10cSrcweir 			//	pViewData->GetViewShell()->SetDrawShellOrSub();		// Draw-Objekt selektiert
1696cdf0e10cSrcweir 			return;
1697cdf0e10cSrcweir 		}
1698cdf0e10cSrcweir 
1699cdf0e10cSrcweir 		pViewData->GetViewShell()->SetDrawShell( sal_False );				// kein Draw-Objekt selektiert
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir 		//	TestMouse schon oben passiert
1702cdf0e10cSrcweir 	}
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir 	Point aPos = rMEvt.GetPosPixel();
1705cdf0e10cSrcweir 	SCsCOL nPosX;
1706cdf0e10cSrcweir 	SCsROW nPosY;
1707cdf0e10cSrcweir 	pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
1708cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
1709cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir             //
1713cdf0e10cSrcweir             //      AutoFilter buttons
1714cdf0e10cSrcweir             //
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir     if ( !bDouble && !bFormulaMode && rMEvt.IsLeft() )
1717cdf0e10cSrcweir 	{
171851b45b88SJian Fang Zhang 		SCsCOL nRealPosX;
171951b45b88SJian Fang Zhang 		SCsROW nRealPosY;
172051b45b88SJian Fang Zhang 		pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nRealPosX, nRealPosY, false );//the real row/col
172151b45b88SJian Fang Zhang 		ScMergeFlagAttr* pRealPosAttr = (ScMergeFlagAttr*)
172251b45b88SJian Fang Zhang 									pDoc->GetAttr( nRealPosX, nRealPosY, nTab, ATTR_MERGE_FLAG );
1723cdf0e10cSrcweir 		ScMergeFlagAttr* pAttr = (ScMergeFlagAttr*)
1724cdf0e10cSrcweir 									pDoc->GetAttr( nPosX, nPosY, nTab, ATTR_MERGE_FLAG );
172551b45b88SJian Fang Zhang 		if( pRealPosAttr->HasAutoFilter() )
172651b45b88SJian Fang Zhang 		{
172751b45b88SJian Fang Zhang 			SC_MOD()->InputEnterHandler();
172851b45b88SJian Fang Zhang 			if (DoAutoFilterButton( nRealPosX, nRealPosY, rMEvt))
172951b45b88SJian Fang Zhang                 return;
173051b45b88SJian Fang Zhang 		}
1731cdf0e10cSrcweir 		if( pAttr->HasAutoFilter() )
1732cdf0e10cSrcweir 		{
1733cdf0e10cSrcweir 			SC_MOD()->InputEnterHandler();	//Add for i85305
1734cdf0e10cSrcweir 			if (DoAutoFilterButton( nPosX, nPosY, rMEvt))
1735cdf0e10cSrcweir                 return;
1736cdf0e10cSrcweir 		}
1737cdf0e10cSrcweir 		if (pAttr->HasButton())
1738cdf0e10cSrcweir 		{
1739cdf0e10cSrcweir 			DoPushButton( nPosX, nPosY, rMEvt );	// setzt evtl. bPivotMouse / bDPMouse
1740cdf0e10cSrcweir 			return;
1741cdf0e10cSrcweir 		}
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir         //  List Validity drop-down button
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir         if ( bListValButton )
1746cdf0e10cSrcweir         {
1747cdf0e10cSrcweir             Rectangle aButtonRect = GetListValButtonRect( aListValPos );
1748cdf0e10cSrcweir             if ( aButtonRect.IsInside( aPos ) )
1749cdf0e10cSrcweir             {
1750cdf0e10cSrcweir                 DoAutoFilterMenue( aListValPos.Col(), aListValPos.Row(), sal_True );
1751cdf0e10cSrcweir 
1752cdf0e10cSrcweir                 nMouseStatus = SC_GM_FILTER;    // not set in DoAutoFilterMenue for bDataSelect
1753cdf0e10cSrcweir                 CaptureMouse();
1754cdf0e10cSrcweir                 return;
1755cdf0e10cSrcweir             }
1756cdf0e10cSrcweir         }
1757cdf0e10cSrcweir 	}
1758cdf0e10cSrcweir 
1759cdf0e10cSrcweir             //
1760cdf0e10cSrcweir             //      scenario selection
1761cdf0e10cSrcweir             //
1762cdf0e10cSrcweir 
1763cdf0e10cSrcweir 	ScRange aScenRange;
1764cdf0e10cSrcweir 	if ( rMEvt.IsLeft() && HasScenarioButton( aPos, aScenRange ) )
1765cdf0e10cSrcweir 	{
1766cdf0e10cSrcweir 		DoScenarioMenue( aScenRange );
1767cdf0e10cSrcweir 		return;
1768cdf0e10cSrcweir 	}
1769cdf0e10cSrcweir 
1770cdf0e10cSrcweir 			//
1771cdf0e10cSrcweir 			//		Doppelklick angefangen ?
1772cdf0e10cSrcweir 			//
1773cdf0e10cSrcweir 
1774cdf0e10cSrcweir 	// StopMarking kann aus DrawMouseButtonDown gerufen werden
1775cdf0e10cSrcweir 
1776cdf0e10cSrcweir 	if ( nMouseStatus != SC_GM_IGNORE && !bRefMode )
1777cdf0e10cSrcweir 	{
1778cdf0e10cSrcweir 		if ( bDouble && !bCrossPointer )
1779cdf0e10cSrcweir 		{
1780cdf0e10cSrcweir 			if (nMouseStatus == SC_GM_TABDOWN)
1781cdf0e10cSrcweir 				nMouseStatus = SC_GM_DBLDOWN;
1782cdf0e10cSrcweir 		}
1783cdf0e10cSrcweir 		else
1784cdf0e10cSrcweir 			nMouseStatus = SC_GM_TABDOWN;
1785cdf0e10cSrcweir 	}
1786cdf0e10cSrcweir 
1787cdf0e10cSrcweir 			//
1788cdf0e10cSrcweir 			//		Links in Edit-Zellen
1789cdf0e10cSrcweir 			//
1790cdf0e10cSrcweir 
1791cdf0e10cSrcweir 	sal_Bool bAlt = rMEvt.IsMod2();
1792cdf0e10cSrcweir 	if ( !bAlt && rMEvt.IsLeft() &&
1793cdf0e10cSrcweir 			GetEditUrl(rMEvt.GetPosPixel()) )			// Klick auf Link: Cursor nicht bewegen
1794cdf0e10cSrcweir 	{
1795cdf0e10cSrcweir 		SetPointer( Pointer( POINTER_REFHAND ) );
1796cdf0e10cSrcweir 		nMouseStatus = SC_GM_URLDOWN;					// auch nur dann beim ButtonUp ausfuehren
1797cdf0e10cSrcweir 		return;
1798cdf0e10cSrcweir 	}
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir 			//
1801cdf0e10cSrcweir 			//		Gridwin - SelectionEngine
1802cdf0e10cSrcweir 			//
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir 	if ( rMEvt.IsLeft() )
1805cdf0e10cSrcweir 	{
1806cdf0e10cSrcweir 		ScViewSelectionEngine* pSelEng = pViewData->GetView()->GetSelEngine();
1807cdf0e10cSrcweir 		pSelEng->SetWindow(this);
1808cdf0e10cSrcweir 		pSelEng->SetWhich(eWhich);
1809cdf0e10cSrcweir 		pSelEng->SetVisibleArea( Rectangle(Point(), GetOutputSizePixel()) );
1810cdf0e10cSrcweir 
1811cdf0e10cSrcweir 		//	SelMouseButtonDown an der View setzt noch das bMoveIsShift Flag
1812cdf0e10cSrcweir 		if ( pViewData->GetView()->SelMouseButtonDown( rMEvt ) )
1813cdf0e10cSrcweir 		{
1814cdf0e10cSrcweir 			if (IsMouseCaptured())
1815cdf0e10cSrcweir 			{
1816cdf0e10cSrcweir 				//	Tracking statt CaptureMouse, damit sauber abgebrochen werden kann
1817cdf0e10cSrcweir 				//!	Irgendwann sollte die SelectionEngine selber StartTracking rufen!?!
1818cdf0e10cSrcweir 				ReleaseMouse();
1819cdf0e10cSrcweir 				StartTracking();
1820cdf0e10cSrcweir 			}
1821cdf0e10cSrcweir 			pViewData->GetMarkData().SetMarking(sal_True);
1822cdf0e10cSrcweir 			return;
1823cdf0e10cSrcweir 		}
1824cdf0e10cSrcweir 	}
1825cdf0e10cSrcweir }
1826cdf0e10cSrcweir 
1827cdf0e10cSrcweir void __EXPORT ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt )
1828cdf0e10cSrcweir {
1829cdf0e10cSrcweir 	aCurMousePos = rMEvt.GetPosPixel();
1830cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
1831cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
1832cdf0e10cSrcweir 
1833cdf0e10cSrcweir     // #i41690# detect a MouseButtonUp call from within MouseButtonDown
1834cdf0e10cSrcweir     // (possible through Reschedule from storing an OLE object that is deselected)
1835cdf0e10cSrcweir 
1836cdf0e10cSrcweir     if ( nNestedButtonState == SC_NESTEDBUTTON_DOWN )
1837cdf0e10cSrcweir         nNestedButtonState = SC_NESTEDBUTTON_UP;
1838cdf0e10cSrcweir 
1839cdf0e10cSrcweir 	if (nButtonDown != rMEvt.GetButtons())
1840cdf0e10cSrcweir 		nMouseStatus = SC_GM_IGNORE;			// reset und return
1841cdf0e10cSrcweir 
1842cdf0e10cSrcweir 	nButtonDown = 0;
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir 	if (nMouseStatus == SC_GM_IGNORE)
1845cdf0e10cSrcweir 	{
1846cdf0e10cSrcweir 		nMouseStatus = SC_GM_NONE;
1847cdf0e10cSrcweir 										// Selection-Engine: Markieren abbrechen
1848cdf0e10cSrcweir 		pViewData->GetView()->GetSelEngine()->Reset();
1849cdf0e10cSrcweir 		rMark.SetMarking(sal_False);
1850cdf0e10cSrcweir 		if (pViewData->IsAnyFillMode())
1851cdf0e10cSrcweir 		{
1852cdf0e10cSrcweir 			pViewData->GetView()->StopRefMode();
1853cdf0e10cSrcweir 			pViewData->ResetFillMode();
1854cdf0e10cSrcweir 		}
1855cdf0e10cSrcweir 		StopMarking();
1856cdf0e10cSrcweir 		DrawEndAction();				// Markieren/Verschieben auf Drawing-Layer abbrechen
1857cdf0e10cSrcweir 		ReleaseMouse();
1858cdf0e10cSrcweir 		return;
1859cdf0e10cSrcweir 	}
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir 	if (nMouseStatus == SC_GM_FILTER)
1862cdf0e10cSrcweir 	{
1863cdf0e10cSrcweir 		if ( pFilterBox && pFilterBox->GetMode() == SC_FILTERBOX_FILTER )
1864cdf0e10cSrcweir 		{
1865cdf0e10cSrcweir             if (mpFilterButton.get())
1866cdf0e10cSrcweir             {
1867cdf0e10cSrcweir                 bool bFilterActive = IsAutoFilterActive(
1868cdf0e10cSrcweir                     pFilterBox->GetCol(), pFilterBox->GetRow(), pViewData->GetTabNo() );
1869cdf0e10cSrcweir 
1870cdf0e10cSrcweir                 mpFilterButton->setHasHiddenMember(bFilterActive);
1871cdf0e10cSrcweir                 mpFilterButton->setPopupPressed(false);
1872cdf0e10cSrcweir                 HideCursor();
1873cdf0e10cSrcweir                 mpFilterButton->draw();
1874cdf0e10cSrcweir                 ShowCursor();
1875cdf0e10cSrcweir             }
1876cdf0e10cSrcweir 		}
1877cdf0e10cSrcweir 		nMouseStatus = SC_GM_NONE;
1878cdf0e10cSrcweir 		ReleaseMouse();
1879cdf0e10cSrcweir 		return;							// da muss nix mehr passieren
1880cdf0e10cSrcweir 	}
1881cdf0e10cSrcweir 
1882cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
1883cdf0e10cSrcweir 	if (pScMod->IsModalMode(pViewData->GetSfxDocShell()))
1884cdf0e10cSrcweir 		return;
1885cdf0e10cSrcweir 
1886cdf0e10cSrcweir 	SfxBindings& rBindings = pViewData->GetBindings();
1887cdf0e10cSrcweir     if (bEEMouse && pViewData->HasEditView( eWhich ))
1888cdf0e10cSrcweir 	{
1889cdf0e10cSrcweir 		EditView*	pEditView;
1890cdf0e10cSrcweir 		SCCOL		nEditCol;
1891cdf0e10cSrcweir 		SCROW		nEditRow;
1892cdf0e10cSrcweir 		pViewData->GetEditView( eWhich, pEditView, nEditCol, nEditRow );
1893cdf0e10cSrcweir 		pEditView->MouseButtonUp( rMEvt );
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir 		if ( rMEvt.IsMiddle() &&
1896cdf0e10cSrcweir 	         	GetSettings().GetMouseSettings().GetMiddleButtonAction() == MOUSE_MIDDLE_PASTESELECTION )
1897cdf0e10cSrcweir 	    {
1898cdf0e10cSrcweir 	    	//	EditView may have pasted from selection
1899cdf0e10cSrcweir 	    	pScMod->InputChanged( pEditView );
1900cdf0e10cSrcweir 	    }
1901cdf0e10cSrcweir 		else
1902cdf0e10cSrcweir 			pScMod->InputSelection( pEditView );			// parentheses etc.
1903cdf0e10cSrcweir 
1904cdf0e10cSrcweir 		pViewData->GetView()->InvalidateAttribs();
1905cdf0e10cSrcweir 		rBindings.Invalidate( SID_HYPERLINK_GETLINK );
1906cdf0e10cSrcweir 		bEEMouse = sal_False;
1907cdf0e10cSrcweir 		return;
1908cdf0e10cSrcweir 	}
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir 	if (bDPMouse)
1911cdf0e10cSrcweir 	{
1912cdf0e10cSrcweir 		DPMouseButtonUp( rMEvt );		// resets bDPMouse
1913cdf0e10cSrcweir 		return;
1914cdf0e10cSrcweir 	}
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 	if (bRFMouse)
1917cdf0e10cSrcweir 	{
1918cdf0e10cSrcweir 		RFMouseMove( rMEvt, sal_True );		// Range wieder richtigherum
1919cdf0e10cSrcweir 		bRFMouse = sal_False;
1920cdf0e10cSrcweir 		SetPointer( Pointer( POINTER_ARROW ) );
1921cdf0e10cSrcweir 		ReleaseMouse();
1922cdf0e10cSrcweir 		return;
1923cdf0e10cSrcweir 	}
1924cdf0e10cSrcweir 
1925cdf0e10cSrcweir 	if (nPagebreakMouse)
1926cdf0e10cSrcweir 	{
1927cdf0e10cSrcweir 		PagebreakMove( rMEvt, sal_True );
1928cdf0e10cSrcweir 		nPagebreakMouse = SC_PD_NONE;
1929cdf0e10cSrcweir 		SetPointer( Pointer( POINTER_ARROW ) );
1930cdf0e10cSrcweir 		ReleaseMouse();
1931cdf0e10cSrcweir 		return;
1932cdf0e10cSrcweir 	}
1933cdf0e10cSrcweir 
1934cdf0e10cSrcweir 	if (nMouseStatus == SC_GM_WATERUNDO)	// Undo im Giesskannenmodus
1935cdf0e10cSrcweir 	{
1936cdf0e10cSrcweir 		::svl::IUndoManager* pMgr = pViewData->GetDocShell()->GetUndoManager();
1937cdf0e10cSrcweir 		if ( pMgr->GetUndoActionCount() && pMgr->GetUndoActionId() == STR_UNDO_APPLYCELLSTYLE )
1938cdf0e10cSrcweir 			pMgr->Undo();
1939cdf0e10cSrcweir 		else
1940cdf0e10cSrcweir 			Sound::Beep();
1941cdf0e10cSrcweir 		return;
1942cdf0e10cSrcweir 	}
1943cdf0e10cSrcweir 
1944cdf0e10cSrcweir 	if (DrawMouseButtonUp(rMEvt))       // includes format paint brush handling for drawing objects
1945ee093554SAndre Fischer     {
1946ee093554SAndre Fischer         ScTabViewShell* pViewShell = pViewData->GetViewShell();
1947ee093554SAndre Fischer         SfxBindings& rBindings=pViewShell->GetViewFrame()->GetBindings();
1948ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_WIDTH);
1949ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_HEIGHT);
1950ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_X);
1951ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_Y);
1952ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_ANGLE);
1953ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_X);
1954ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_Y);
1955ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOWIDTH);
1956ee093554SAndre Fischer         rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOHEIGHT);
1957cdf0e10cSrcweir         return;
1958ee093554SAndre Fischer     }
1959cdf0e10cSrcweir 
1960cdf0e10cSrcweir 	rMark.SetMarking(sal_False);
1961cdf0e10cSrcweir 
1962cdf0e10cSrcweir 	SetPointer( Pointer( POINTER_ARROW ) );
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir 	if (pViewData->IsFillMode() ||
1965cdf0e10cSrcweir 		( pViewData->GetFillMode() == SC_FILL_MATRIX && rMEvt.IsMod1() ))
1966cdf0e10cSrcweir 	{
1967cdf0e10cSrcweir 		nScFillModeMouseModifier = rMEvt.GetModifier();
1968cdf0e10cSrcweir 		SCCOL nStartCol;
1969cdf0e10cSrcweir 		SCROW nStartRow;
1970cdf0e10cSrcweir 		SCCOL nEndCol;
1971cdf0e10cSrcweir 		SCROW nEndRow;
1972cdf0e10cSrcweir 		pViewData->GetFillData( nStartCol, nStartRow, nEndCol, nEndRow );
1973cdf0e10cSrcweir //		DBG_ASSERT( nStartCol==pViewData->GetRefStartX() && nStartRow==pViewData->GetRefStartY(),
1974cdf0e10cSrcweir //								"Block falsch fuer AutoFill" );
1975cdf0e10cSrcweir 		ScRange aDelRange;
1976cdf0e10cSrcweir 		sal_Bool bIsDel = pViewData->GetDelMark( aDelRange );
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir 		ScViewFunc* pView = pViewData->GetView();
1979cdf0e10cSrcweir 		pView->StopRefMode();
1980cdf0e10cSrcweir 		pViewData->ResetFillMode();
1981cdf0e10cSrcweir 		pView->GetFunctionSet()->SetAnchorFlag( sal_False );	// #i5819# don't use AutoFill anchor flag for selection
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir 		if ( bIsDel )
1984cdf0e10cSrcweir 		{
1985cdf0e10cSrcweir 			pView->MarkRange( aDelRange, sal_False );
1986cdf0e10cSrcweir 			pView->DeleteContents( IDF_CONTENTS );
1987cdf0e10cSrcweir 			SCTAB nTab = pViewData->GetTabNo();
1988cdf0e10cSrcweir 			ScRange aBlockRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab );
1989cdf0e10cSrcweir 			if ( aBlockRange != aDelRange )
1990cdf0e10cSrcweir 			{
1991cdf0e10cSrcweir 				if ( aDelRange.aStart.Row() == nStartRow )
1992cdf0e10cSrcweir 					aBlockRange.aEnd.SetCol( aDelRange.aStart.Col() - 1 );
1993cdf0e10cSrcweir 				else
1994cdf0e10cSrcweir 					aBlockRange.aEnd.SetRow( aDelRange.aStart.Row() - 1 );
1995cdf0e10cSrcweir 				pView->MarkRange( aBlockRange, sal_False );
1996cdf0e10cSrcweir 			}
1997cdf0e10cSrcweir 		}
1998cdf0e10cSrcweir 		else
1999cdf0e10cSrcweir 			pViewData->GetDispatcher().Execute( FID_FILL_AUTO, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
2000cdf0e10cSrcweir 	}
2001cdf0e10cSrcweir 	else if (pViewData->GetFillMode() == SC_FILL_MATRIX)
2002cdf0e10cSrcweir 	{
2003cdf0e10cSrcweir 		SCTAB nTab = pViewData->GetTabNo();
2004cdf0e10cSrcweir 		SCCOL nStartCol;
2005cdf0e10cSrcweir 		SCROW nStartRow;
2006cdf0e10cSrcweir 		SCCOL nEndCol;
2007cdf0e10cSrcweir 		SCROW nEndRow;
2008cdf0e10cSrcweir 		pViewData->GetFillData( nStartCol, nStartRow, nEndCol, nEndRow );
2009cdf0e10cSrcweir 		ScRange aBlockRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab );
2010cdf0e10cSrcweir 		SCCOL nFillCol = pViewData->GetRefEndX();
2011cdf0e10cSrcweir 		SCROW nFillRow = pViewData->GetRefEndY();
2012cdf0e10cSrcweir 		ScAddress aEndPos( nFillCol, nFillRow, nTab );
2013cdf0e10cSrcweir 
2014cdf0e10cSrcweir 		ScTabView* pView = pViewData->GetView();
2015cdf0e10cSrcweir 		pView->StopRefMode();
2016cdf0e10cSrcweir 		pViewData->ResetFillMode();
2017cdf0e10cSrcweir 		pView->GetFunctionSet()->SetAnchorFlag( sal_False );
2018cdf0e10cSrcweir 
2019cdf0e10cSrcweir 		if ( aEndPos != aBlockRange.aEnd )
2020cdf0e10cSrcweir 		{
2021cdf0e10cSrcweir 			pViewData->GetDocShell()->GetDocFunc().ResizeMatrix( aBlockRange, aEndPos, sal_False );
2022cdf0e10cSrcweir 			pViewData->GetView()->MarkRange( ScRange( aBlockRange.aStart, aEndPos ) );
2023cdf0e10cSrcweir 		}
2024cdf0e10cSrcweir 	}
2025cdf0e10cSrcweir 	else if (pViewData->IsAnyFillMode())
2026cdf0e10cSrcweir 	{
2027cdf0e10cSrcweir 												// Embedded-Area has been changed
2028cdf0e10cSrcweir 		ScTabView* pView = pViewData->GetView();
2029cdf0e10cSrcweir 		pView->StopRefMode();
2030cdf0e10cSrcweir 		pViewData->ResetFillMode();
2031cdf0e10cSrcweir 		pView->GetFunctionSet()->SetAnchorFlag( sal_False );
2032cdf0e10cSrcweir 		pViewData->GetDocShell()->UpdateOle(pViewData);
2033cdf0e10cSrcweir 	}
2034cdf0e10cSrcweir 
2035cdf0e10cSrcweir 	sal_Bool bRefMode =	pViewData->IsRefMode();
2036cdf0e10cSrcweir 	if (bRefMode)
2037cdf0e10cSrcweir 		pScMod->EndReference();
2038cdf0e10cSrcweir 
2039cdf0e10cSrcweir 		//
2040cdf0e10cSrcweir 		//	Giesskannen-Modus (Gestalter)
2041cdf0e10cSrcweir 		//
2042cdf0e10cSrcweir 
2043cdf0e10cSrcweir 	if (pScMod->GetIsWaterCan())
2044cdf0e10cSrcweir 	{
2045cdf0e10cSrcweir 		//	Abfrage auf Undo schon oben
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir 		ScStyleSheetPool* pStylePool = (ScStyleSheetPool*)
2048cdf0e10cSrcweir 									   (pViewData->GetDocument()->
2049cdf0e10cSrcweir 											GetStyleSheetPool());
2050cdf0e10cSrcweir 		if ( pStylePool )
2051cdf0e10cSrcweir 		{
2052cdf0e10cSrcweir 			SfxStyleSheet* pStyleSheet = (SfxStyleSheet*)
2053cdf0e10cSrcweir 										 pStylePool->GetActualStyleSheet();
2054cdf0e10cSrcweir 
2055cdf0e10cSrcweir 			if ( pStyleSheet )
2056cdf0e10cSrcweir 			{
2057cdf0e10cSrcweir 				SfxStyleFamily eFamily = pStyleSheet->GetFamily();
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir 				switch ( eFamily )
2060cdf0e10cSrcweir 				{
2061cdf0e10cSrcweir 					case SFX_STYLE_FAMILY_PARA:
2062cdf0e10cSrcweir 						pViewData->GetView()->SetStyleSheetToMarked( pStyleSheet );
2063cdf0e10cSrcweir 						pViewData->GetView()->DoneBlockMode();
2064cdf0e10cSrcweir 						break;
2065cdf0e10cSrcweir 
2066cdf0e10cSrcweir 					case SFX_STYLE_FAMILY_PAGE:
2067cdf0e10cSrcweir 						pViewData->GetDocument()->SetPageStyle( pViewData->GetTabNo(),
2068cdf0e10cSrcweir 																pStyleSheet->GetName() );
2069cdf0e10cSrcweir 
2070cdf0e10cSrcweir 						ScPrintFunc( pViewData->GetDocShell(),
2071cdf0e10cSrcweir 									 pViewData->GetViewShell()->GetPrinter(sal_True),
2072cdf0e10cSrcweir 									 pViewData->GetTabNo() ).UpdatePages();
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir 						rBindings.Invalidate( SID_STATUS_PAGESTYLE );
2075cdf0e10cSrcweir 						break;
2076cdf0e10cSrcweir 
2077cdf0e10cSrcweir 					default:
2078cdf0e10cSrcweir 						break;
2079cdf0e10cSrcweir 				}
2080cdf0e10cSrcweir 			}
2081cdf0e10cSrcweir 		}
2082cdf0e10cSrcweir 	}
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir     ScDBFunc* pView = pViewData->GetView();
2085cdf0e10cSrcweir     ScDocument* pBrushDoc = pView->GetBrushDocument();
2086cdf0e10cSrcweir     if ( pBrushDoc )
2087cdf0e10cSrcweir     {
2088cdf0e10cSrcweir         pView->PasteFromClip( IDF_ATTRIB, pBrushDoc );
2089cdf0e10cSrcweir         if ( !pView->IsPaintBrushLocked() )
2090cdf0e10cSrcweir             pView->ResetBrushDocument();            // invalidates pBrushDoc pointer
2091cdf0e10cSrcweir     }
2092cdf0e10cSrcweir 
2093cdf0e10cSrcweir 			//
2094cdf0e10cSrcweir 			//		double click (only left button)
2095cdf0e10cSrcweir 			//
2096cdf0e10cSrcweir 
2097cdf0e10cSrcweir 	sal_Bool bDouble = ( rMEvt.GetClicks() == 2 && rMEvt.IsLeft() );
2098cdf0e10cSrcweir 	if ( bDouble && !bRefMode && nMouseStatus == SC_GM_DBLDOWN && !pScMod->IsRefDialogOpen() )
2099cdf0e10cSrcweir 	{
2100cdf0e10cSrcweir 		//	data pilot table
2101cdf0e10cSrcweir 		Point aPos = rMEvt.GetPosPixel();
2102cdf0e10cSrcweir         SCsCOL nPosX;
2103cdf0e10cSrcweir         SCsROW nPosY;
2104cdf0e10cSrcweir         SCTAB nTab = pViewData->GetTabNo();
2105cdf0e10cSrcweir         pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
2106cdf0e10cSrcweir 		ScDPObject*	pDPObj	= pDoc->GetDPAtCursor( nPosX, nPosY, nTab );
2107cdf0e10cSrcweir 		if ( pDPObj && pDPObj->GetSaveData()->GetDrillDown() )
2108cdf0e10cSrcweir 		{
2109cdf0e10cSrcweir 			ScAddress aCellPos( nPosX, nPosY, pViewData->GetTabNo() );
2110cdf0e10cSrcweir 
2111cdf0e10cSrcweir             // Check for header drill-down first.
2112cdf0e10cSrcweir             sheet::DataPilotTableHeaderData aData;
2113cdf0e10cSrcweir             pDPObj->GetHeaderPositionData(aCellPos, aData);
2114cdf0e10cSrcweir 
2115cdf0e10cSrcweir             if ( ( aData.Flags & sheet::MemberResultFlags::HASMEMBER ) &&
2116cdf0e10cSrcweir                  ! ( aData.Flags & sheet::MemberResultFlags::SUBTOTAL ) )
2117cdf0e10cSrcweir 			{
2118cdf0e10cSrcweir                 sal_uInt16 nDummy;
2119cdf0e10cSrcweir                 if ( pView->HasSelectionForDrillDown( nDummy ) )
2120cdf0e10cSrcweir                 {
2121cdf0e10cSrcweir                     // execute slot to show dialog
2122cdf0e10cSrcweir                     pViewData->GetDispatcher().Execute( SID_OUTLINE_SHOW, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD );
2123cdf0e10cSrcweir                 }
2124cdf0e10cSrcweir                 else
2125cdf0e10cSrcweir                 {
2126cdf0e10cSrcweir                     // toggle single entry
2127cdf0e10cSrcweir                     ScDPObject aNewObj( *pDPObj );
2128cdf0e10cSrcweir                     pDPObj->ToggleDetails( aData, &aNewObj );
2129cdf0e10cSrcweir                     ScDBDocFunc aFunc( *pViewData->GetDocShell() );
2130cdf0e10cSrcweir                     aFunc.DataPilotUpdate( pDPObj, &aNewObj, sal_True, sal_False );
2131cdf0e10cSrcweir                     pViewData->GetView()->CursorPosChanged();       // shells may be switched
2132cdf0e10cSrcweir                 }
2133cdf0e10cSrcweir 			}
2134cdf0e10cSrcweir 			else
2135cdf0e10cSrcweir             {
2136cdf0e10cSrcweir                 // Check if the data area is double-clicked.
2137cdf0e10cSrcweir 
2138cdf0e10cSrcweir                 Sequence<sheet::DataPilotFieldFilter> aFilters;
2139cdf0e10cSrcweir                 if ( pDPObj->GetDataFieldPositionData(aCellPos, aFilters) )
2140cdf0e10cSrcweir                     pViewData->GetView()->ShowDataPilotSourceData( *pDPObj, aFilters );
2141cdf0e10cSrcweir                 else
2142cdf0e10cSrcweir                     Sound::Beep();  // nothing to expand/collapse/show
2143cdf0e10cSrcweir             }
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir 			return;
2146cdf0e10cSrcweir 		}
2147cdf0e10cSrcweir 
2148cdf0e10cSrcweir         // Check for cell protection attribute.
2149cdf0e10cSrcweir         ScTableProtection* pProtect = pDoc->GetTabProtection( nTab );
2150cdf0e10cSrcweir         bool bEditAllowed = true;
2151cdf0e10cSrcweir         if ( pProtect && pProtect->isProtected() )
2152cdf0e10cSrcweir         {
2153cdf0e10cSrcweir             bool bCellProtected = pDoc->HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HASATTR_PROTECTED);
2154cdf0e10cSrcweir             bool bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
2155cdf0e10cSrcweir             bool bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
2156cdf0e10cSrcweir 
2157cdf0e10cSrcweir             if ( bSkipProtected && bSkipUnprotected )
2158cdf0e10cSrcweir                 bEditAllowed = false;
2159cdf0e10cSrcweir             else if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
2160cdf0e10cSrcweir                 bEditAllowed = false;
2161cdf0e10cSrcweir         }
2162cdf0e10cSrcweir 
2163cdf0e10cSrcweir         if ( bEditAllowed )
2164cdf0e10cSrcweir         {
2165cdf0e10cSrcweir             //  edit cell contents
2166cdf0e10cSrcweir             pViewData->GetViewShell()->UpdateInputHandler();
2167cdf0e10cSrcweir             pScMod->SetInputMode( SC_INPUT_TABLE );
2168cdf0e10cSrcweir             if (pViewData->HasEditView(eWhich))
2169cdf0e10cSrcweir             {
2170cdf0e10cSrcweir                 //  Text-Cursor gleich an die geklickte Stelle setzen
2171cdf0e10cSrcweir                 EditView* pEditView = pViewData->GetEditView( eWhich );
2172cdf0e10cSrcweir                 MouseEvent aEditEvt( rMEvt.GetPosPixel(), 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
2173cdf0e10cSrcweir                 pEditView->MouseButtonDown( aEditEvt );
2174cdf0e10cSrcweir                 pEditView->MouseButtonUp( aEditEvt );
2175cdf0e10cSrcweir             }
2176cdf0e10cSrcweir         }
2177cdf0e10cSrcweir         return;
2178cdf0e10cSrcweir     }
2179cdf0e10cSrcweir 
2180cdf0e10cSrcweir 			//
2181cdf0e10cSrcweir 			//		Links in edit cells
2182cdf0e10cSrcweir 			//
2183cdf0e10cSrcweir 
2184cdf0e10cSrcweir 	sal_Bool bAlt = rMEvt.IsMod2();
2185cdf0e10cSrcweir 	if ( !bAlt && !bRefMode && !bDouble && nMouseStatus == SC_GM_URLDOWN )
2186cdf0e10cSrcweir 	{
2187cdf0e10cSrcweir 		//	beim ButtonUp nur ausfuehren, wenn ButtonDown auch ueber einer URL war
2188cdf0e10cSrcweir 
2189cdf0e10cSrcweir 		String aName, aUrl, aTarget;
2190cdf0e10cSrcweir 		if ( GetEditUrl( rMEvt.GetPosPixel(), &aName, &aUrl, &aTarget ) )
2191cdf0e10cSrcweir 		{
2192cdf0e10cSrcweir 			nMouseStatus = SC_GM_NONE;				// keinen Doppelklick anfangen
2193cdf0e10cSrcweir 			ScGlobal::OpenURL( aUrl, aTarget );
2194cdf0e10cSrcweir 
2195cdf0e10cSrcweir 			// fire worksheet_followhyperlink event
2196cdf0e10cSrcweir             uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor();
2197cdf0e10cSrcweir 			if( xVbaEvents.is() ) try
2198cdf0e10cSrcweir 			{
2199cdf0e10cSrcweir     			Point aPos = rMEvt.GetPosPixel();
2200cdf0e10cSrcweir     	        SCsCOL nPosX;
2201cdf0e10cSrcweir         	    SCsROW nPosY;
2202cdf0e10cSrcweir             	SCTAB nTab = pViewData->GetTabNo();
2203cdf0e10cSrcweir             	pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
2204cdf0e10cSrcweir     			ScBaseCell* pCell = NULL;
2205cdf0e10cSrcweir     			if( lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell ) )
2206cdf0e10cSrcweir     			{
2207cdf0e10cSrcweir     				ScAddress aCellPos( nPosX, nPosY, nTab );
2208cdf0e10cSrcweir     				uno::Reference< table::XCell > xCell( new ScCellObj( pViewData->GetDocShell(), aCellPos ) );
2209cdf0e10cSrcweir     				uno::Sequence< uno::Any > aArgs(1);
2210cdf0e10cSrcweir     				aArgs[0] <<= xCell;
2211cdf0e10cSrcweir     			    xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_FOLLOWHYPERLINK, aArgs );
2212cdf0e10cSrcweir     			}
2213cdf0e10cSrcweir 			}
2214cdf0e10cSrcweir             catch( uno::Exception& )
2215cdf0e10cSrcweir             {
2216cdf0e10cSrcweir             }
2217cdf0e10cSrcweir 
2218cdf0e10cSrcweir 			return;
2219cdf0e10cSrcweir 		}
2220cdf0e10cSrcweir 	}
2221cdf0e10cSrcweir 
2222cdf0e10cSrcweir 			//
2223cdf0e10cSrcweir 			//		Gridwin - SelectionEngine
2224cdf0e10cSrcweir 			//
2225cdf0e10cSrcweir 
2226cdf0e10cSrcweir 	//	SelMouseButtonDown is called only for left button, but SelMouseButtonUp would return
2227cdf0e10cSrcweir 	//	sal_True for any call, so IsLeft must be checked here, too.
2228cdf0e10cSrcweir 
2229cdf0e10cSrcweir 	if ( rMEvt.IsLeft() && pViewData->GetView()->GetSelEngine()->SelMouseButtonUp( rMEvt ) )
2230cdf0e10cSrcweir 	{
2231cdf0e10cSrcweir //		rMark.MarkToSimple();
2232cdf0e10cSrcweir 		pViewData->GetView()->UpdateAutoFillMark();
2233cdf0e10cSrcweir 
2234cdf0e10cSrcweir 		SfxDispatcher* pDisp = pViewData->GetViewShell()->GetDispatcher();
2235cdf0e10cSrcweir         sal_Bool bFormulaMode = pScMod->IsFormulaMode();
2236cdf0e10cSrcweir 		DBG_ASSERT( pDisp || bFormulaMode, "Cursor auf nicht aktiver View bewegen ?" );
2237cdf0e10cSrcweir 
2238cdf0e10cSrcweir 		//	#i14927# execute SID_CURRENTCELL (for macro recording) only if there is no
2239cdf0e10cSrcweir 		//	multiple selection, so the argument string completely describes the selection,
2240cdf0e10cSrcweir 		//	and executing the slot won't change the existing selection (executing the slot
2241cdf0e10cSrcweir 		//	here and from a recorded macro is treated equally)
2242cdf0e10cSrcweir 
2243cdf0e10cSrcweir 		if ( pDisp && !bFormulaMode && !rMark.IsMultiMarked() )
2244cdf0e10cSrcweir 		{
2245cdf0e10cSrcweir 			String aAddr;								// CurrentCell
2246cdf0e10cSrcweir 			if( rMark.IsMarked() )
2247cdf0e10cSrcweir 			{
2248cdf0e10cSrcweir //				sal_Bool bKeep = rMark.IsMultiMarked();		//! wohin damit ???
2249cdf0e10cSrcweir 
2250cdf0e10cSrcweir 				ScRange aScRange;
2251cdf0e10cSrcweir 				rMark.GetMarkArea( aScRange );
2252cdf0e10cSrcweir 				aScRange.Format( aAddr, SCR_ABS );
2253cdf0e10cSrcweir 				if ( aScRange.aStart == aScRange.aEnd )
2254cdf0e10cSrcweir 				{
2255cdf0e10cSrcweir 					//	make sure there is a range selection string even for a single cell
2256cdf0e10cSrcweir 					String aSingle = aAddr;
2257cdf0e10cSrcweir 					aAddr.Append( (sal_Char) ':' );
2258cdf0e10cSrcweir 					aAddr.Append( aSingle );
2259cdf0e10cSrcweir 				}
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir 				//!	SID_MARKAREA gibts nicht mehr ???
2262cdf0e10cSrcweir 				//!	was passiert beim Markieren mit dem Cursor ???
2263cdf0e10cSrcweir 			}
2264cdf0e10cSrcweir 			else										// nur Cursor bewegen
2265cdf0e10cSrcweir 			{
2266cdf0e10cSrcweir 				ScAddress aScAddress( pViewData->GetCurX(), pViewData->GetCurY(), 0 );
2267cdf0e10cSrcweir 				aScAddress.Format( aAddr, SCA_ABS );
2268cdf0e10cSrcweir 			}
2269cdf0e10cSrcweir 
2270cdf0e10cSrcweir 			SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
2271cdf0e10cSrcweir 			pDisp->Execute( SID_CURRENTCELL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
2272cdf0e10cSrcweir 										&aPosItem, (void*)0L );
2273cdf0e10cSrcweir 
2274cdf0e10cSrcweir 			pViewData->GetView()->InvalidateAttribs();
2275cdf0e10cSrcweir 		}
2276*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
2277*0deba7fbSSteve Yin 		pViewData->GetViewShell()->SelectionChanged();
2278*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
2279cdf0e10cSrcweir 		return;
2280cdf0e10cSrcweir 	}
2281cdf0e10cSrcweir }
2282cdf0e10cSrcweir 
2283cdf0e10cSrcweir void ScGridWindow::FakeButtonUp()
2284cdf0e10cSrcweir {
2285cdf0e10cSrcweir 	if ( nButtonDown )
2286cdf0e10cSrcweir 	{
2287cdf0e10cSrcweir 		MouseEvent aEvent( aCurMousePos );		// nButtons = 0 -> ignore
2288cdf0e10cSrcweir 		MouseButtonUp( aEvent );
2289cdf0e10cSrcweir 	}
2290cdf0e10cSrcweir }
2291cdf0e10cSrcweir 
2292cdf0e10cSrcweir void __EXPORT ScGridWindow::MouseMove( const MouseEvent& rMEvt )
2293cdf0e10cSrcweir {
2294cdf0e10cSrcweir 	aCurMousePos = rMEvt.GetPosPixel();
2295cdf0e10cSrcweir 
2296cdf0e10cSrcweir 	if ( rMEvt.IsLeaveWindow() && pNoteMarker && !pNoteMarker->IsByKeyboard() )
2297cdf0e10cSrcweir 		HideNoteMarker();
2298cdf0e10cSrcweir 
2299cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
2300cdf0e10cSrcweir 	if (pScMod->IsModalMode(pViewData->GetSfxDocShell()))
2301cdf0e10cSrcweir 		return;
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir 		//	Ob aus dem Edit-Modus Drag&Drop gestartet wurde, bekommt man leider
2304cdf0e10cSrcweir 		//	nicht anders mit:
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir 	if (bEEMouse && nButtonDown && !rMEvt.GetButtons())
2307cdf0e10cSrcweir 	{
2308cdf0e10cSrcweir 		bEEMouse = sal_False;
2309cdf0e10cSrcweir 		nButtonDown = 0;
2310cdf0e10cSrcweir 		nMouseStatus = SC_GM_NONE;
2311cdf0e10cSrcweir 		return;
2312cdf0e10cSrcweir 	}
2313cdf0e10cSrcweir 
2314cdf0e10cSrcweir 	if (nMouseStatus == SC_GM_IGNORE)
2315cdf0e10cSrcweir 		return;
2316cdf0e10cSrcweir 
2317cdf0e10cSrcweir 	if (nMouseStatus == SC_GM_WATERUNDO)	// Undo im Giesskannenmodus -> nur auf Up warten
2318cdf0e10cSrcweir 		return;
2319cdf0e10cSrcweir 
2320cdf0e10cSrcweir 	if ( pViewData->GetViewShell()->IsAuditShell() )		// Detektiv-Fuell-Modus
2321cdf0e10cSrcweir 	{
2322cdf0e10cSrcweir 		SetPointer( Pointer( POINTER_FILL ) );
2323cdf0e10cSrcweir 		return;
2324cdf0e10cSrcweir 	}
2325cdf0e10cSrcweir 
2326cdf0e10cSrcweir 	if (nMouseStatus == SC_GM_FILTER && pFilterBox)
2327cdf0e10cSrcweir 	{
2328cdf0e10cSrcweir 		Point aRelPos = pFilterBox->ScreenToOutputPixel( OutputToScreenPixel( rMEvt.GetPosPixel() ) );
2329cdf0e10cSrcweir 		if ( Rectangle(Point(),pFilterBox->GetOutputSizePixel()).IsInside(aRelPos) )
2330cdf0e10cSrcweir 		{
2331cdf0e10cSrcweir 			nButtonDown = 0;
2332cdf0e10cSrcweir 			nMouseStatus = SC_GM_NONE;
2333cdf0e10cSrcweir 			if ( pFilterBox->GetMode() == SC_FILTERBOX_FILTER )
2334cdf0e10cSrcweir 			{
2335cdf0e10cSrcweir                 if (mpFilterButton.get())
2336cdf0e10cSrcweir                 {
2337cdf0e10cSrcweir                     mpFilterButton->setHasHiddenMember(false);
2338cdf0e10cSrcweir                     mpFilterButton->setPopupPressed(false);
2339cdf0e10cSrcweir                     HideCursor();
2340cdf0e10cSrcweir                     mpFilterButton->draw();
2341cdf0e10cSrcweir                     ShowCursor();
2342cdf0e10cSrcweir                 }
2343cdf0e10cSrcweir 			}
2344cdf0e10cSrcweir 			ReleaseMouse();
2345cdf0e10cSrcweir 			pFilterBox->MouseButtonDown( MouseEvent( aRelPos, 1, MOUSE_SIMPLECLICK, MOUSE_LEFT ) );
2346cdf0e10cSrcweir 			return;
2347cdf0e10cSrcweir 		}
2348cdf0e10cSrcweir 	}
2349cdf0e10cSrcweir 
2350cdf0e10cSrcweir 	sal_Bool bFormulaMode = pScMod->IsFormulaMode();			// naechster Klick -> Referenz
2351cdf0e10cSrcweir 
2352cdf0e10cSrcweir     if (bEEMouse && pViewData->HasEditView( eWhich ))
2353cdf0e10cSrcweir 	{
2354cdf0e10cSrcweir 		EditView*	pEditView;
2355cdf0e10cSrcweir 		SCCOL		nEditCol;
2356cdf0e10cSrcweir 		SCROW		nEditRow;
2357cdf0e10cSrcweir         pViewData->GetEditView( eWhich, pEditView, nEditCol, nEditRow );
2358cdf0e10cSrcweir         pEditView->MouseMove( rMEvt );
2359cdf0e10cSrcweir         return;
2360cdf0e10cSrcweir 	}
2361cdf0e10cSrcweir 
2362cdf0e10cSrcweir 	if (bDPMouse)
2363cdf0e10cSrcweir 	{
2364cdf0e10cSrcweir 		DPMouseMove( rMEvt );
2365cdf0e10cSrcweir 		return;
2366cdf0e10cSrcweir 	}
2367cdf0e10cSrcweir 
2368cdf0e10cSrcweir 	if (bRFMouse)
2369cdf0e10cSrcweir 	{
2370cdf0e10cSrcweir 		RFMouseMove( rMEvt, sal_False );
2371cdf0e10cSrcweir 		return;
2372cdf0e10cSrcweir 	}
2373cdf0e10cSrcweir 
2374cdf0e10cSrcweir 	if (nPagebreakMouse)
2375cdf0e10cSrcweir 	{
2376cdf0e10cSrcweir 		PagebreakMove( rMEvt, sal_False );
2377cdf0e10cSrcweir 		return;
2378cdf0e10cSrcweir 	}
2379cdf0e10cSrcweir 
2380cdf0e10cSrcweir 	//	anderen Mauszeiger anzeigen?
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir 	sal_Bool bEditMode = pViewData->HasEditView(eWhich);
2383cdf0e10cSrcweir 
2384cdf0e10cSrcweir 					//! Testen ob RefMode-Dragging !!!
2385cdf0e10cSrcweir 	if ( bEditMode && (pViewData->GetRefTabNo() == pViewData->GetTabNo()) )
2386cdf0e10cSrcweir 	{
2387cdf0e10cSrcweir 		Point	aPos = rMEvt.GetPosPixel();
2388cdf0e10cSrcweir 		SCsCOL	nPosX;
2389cdf0e10cSrcweir 		SCsROW	nPosY;
2390cdf0e10cSrcweir 		pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
2391cdf0e10cSrcweir 
2392cdf0e10cSrcweir 		EditView*	pEditView;
2393cdf0e10cSrcweir 		SCCOL		nEditCol;
2394cdf0e10cSrcweir 		SCROW		nEditRow;
2395cdf0e10cSrcweir 		pViewData->GetEditView( eWhich, pEditView, nEditCol, nEditRow );
2396cdf0e10cSrcweir 		SCCOL nEndCol = pViewData->GetEditEndCol();
2397cdf0e10cSrcweir 		SCROW nEndRow = pViewData->GetEditEndRow();
2398cdf0e10cSrcweir 
2399cdf0e10cSrcweir 		if ( nPosX >= (SCsCOL) nEditCol && nPosX <= (SCsCOL) nEndCol &&
2400cdf0e10cSrcweir 			 nPosY >= (SCsROW) nEditRow && nPosY <= (SCsROW) nEndRow )
2401cdf0e10cSrcweir 		{
2402cdf0e10cSrcweir 			//	Field can only be URL field
2403cdf0e10cSrcweir 			sal_Bool bAlt = rMEvt.IsMod2();
2404cdf0e10cSrcweir 			if ( !bAlt && !nButtonDown && pEditView && pEditView->GetFieldUnderMousePointer() )
2405cdf0e10cSrcweir 				SetPointer( Pointer( POINTER_REFHAND ) );
2406cdf0e10cSrcweir 			else if ( pEditView && pEditView->GetEditEngine()->IsVertical() )
2407cdf0e10cSrcweir 				SetPointer( Pointer( POINTER_TEXT_VERTICAL ) );
2408cdf0e10cSrcweir 			else
2409cdf0e10cSrcweir 				SetPointer( Pointer( POINTER_TEXT ) );
2410cdf0e10cSrcweir 			return;
2411cdf0e10cSrcweir 		}
2412cdf0e10cSrcweir 	}
2413cdf0e10cSrcweir 
2414cdf0e10cSrcweir 	sal_Bool bWater = SC_MOD()->GetIsWaterCan() || pViewData->GetView()->HasPaintBrush();
2415cdf0e10cSrcweir 	if (bWater)
2416cdf0e10cSrcweir 		SetPointer( Pointer(POINTER_FILL) );
2417cdf0e10cSrcweir 
2418cdf0e10cSrcweir 	if (!bWater)
2419cdf0e10cSrcweir 	{
2420cdf0e10cSrcweir 		sal_Bool bCross = sal_False;
2421cdf0e10cSrcweir 
2422cdf0e10cSrcweir 		//	Range-Finder
2423cdf0e10cSrcweir 
2424cdf0e10cSrcweir 		sal_Bool bCorner;
2425cdf0e10cSrcweir 		if ( HitRangeFinder( rMEvt.GetPosPixel(), bCorner ) )
2426cdf0e10cSrcweir 		{
2427cdf0e10cSrcweir 			if (bCorner)
2428cdf0e10cSrcweir 				SetPointer( Pointer( POINTER_CROSS ) );
2429cdf0e10cSrcweir 			else
2430cdf0e10cSrcweir 				SetPointer( Pointer( POINTER_HAND ) );
2431cdf0e10cSrcweir 			bCross = sal_True;
2432cdf0e10cSrcweir 		}
2433cdf0e10cSrcweir 
2434cdf0e10cSrcweir 		//	Page-Break-Modus
2435cdf0e10cSrcweir 
2436cdf0e10cSrcweir 		sal_uInt16 nBreakType;
2437cdf0e10cSrcweir 		if ( !nButtonDown && pViewData->IsPagebreakMode() &&
2438cdf0e10cSrcweir                 ( nBreakType = HitPageBreak( rMEvt.GetPosPixel() ) ) != 0 )
2439cdf0e10cSrcweir 		{
2440cdf0e10cSrcweir 			PointerStyle eNew = POINTER_ARROW;
2441cdf0e10cSrcweir 			switch ( nBreakType )
2442cdf0e10cSrcweir 			{
2443cdf0e10cSrcweir 				case SC_PD_RANGE_L:
2444cdf0e10cSrcweir 				case SC_PD_RANGE_R:
2445cdf0e10cSrcweir 				case SC_PD_BREAK_H:
2446cdf0e10cSrcweir 					eNew = POINTER_ESIZE;
2447cdf0e10cSrcweir 					break;
2448cdf0e10cSrcweir 				case SC_PD_RANGE_T:
2449cdf0e10cSrcweir 				case SC_PD_RANGE_B:
2450cdf0e10cSrcweir 				case SC_PD_BREAK_V:
2451cdf0e10cSrcweir 					eNew = POINTER_SSIZE;
2452cdf0e10cSrcweir 					break;
2453cdf0e10cSrcweir 				case SC_PD_RANGE_TL:
2454cdf0e10cSrcweir 				case SC_PD_RANGE_BR:
2455cdf0e10cSrcweir 					eNew = POINTER_SESIZE;
2456cdf0e10cSrcweir 					break;
2457cdf0e10cSrcweir 				case SC_PD_RANGE_TR:
2458cdf0e10cSrcweir 				case SC_PD_RANGE_BL:
2459cdf0e10cSrcweir 					eNew = POINTER_NESIZE;
2460cdf0e10cSrcweir 					break;
2461cdf0e10cSrcweir 			}
2462cdf0e10cSrcweir 			SetPointer( Pointer( eNew ) );
2463cdf0e10cSrcweir 			bCross = sal_True;
2464cdf0e10cSrcweir 		}
2465cdf0e10cSrcweir 
2466cdf0e10cSrcweir 		//	Fill-Cursor anzeigen ?
2467cdf0e10cSrcweir 
2468cdf0e10cSrcweir 		if ( !bFormulaMode && !nButtonDown )
2469cdf0e10cSrcweir 			if (TestMouse( rMEvt, sal_False ))
2470cdf0e10cSrcweir 				bCross = sal_True;
2471cdf0e10cSrcweir 
2472cdf0e10cSrcweir 		if ( nButtonDown && pViewData->IsAnyFillMode() )
2473cdf0e10cSrcweir 		{
2474cdf0e10cSrcweir 			SetPointer( Pointer( POINTER_CROSS ) );
2475cdf0e10cSrcweir 			bCross = sal_True;
2476cdf0e10cSrcweir 			nScFillModeMouseModifier = rMEvt.GetModifier();	// ausgewertet bei AutoFill und Matrix
2477cdf0e10cSrcweir 		}
2478cdf0e10cSrcweir 
2479cdf0e10cSrcweir 		if (!bCross)
2480cdf0e10cSrcweir 		{
2481cdf0e10cSrcweir 			sal_Bool bAlt = rMEvt.IsMod2();
2482cdf0e10cSrcweir 
2483cdf0e10cSrcweir 			if (bEditMode)									// Edit-Mode muss zuerst kommen!
2484cdf0e10cSrcweir 				SetPointer( Pointer( POINTER_ARROW ) );
2485cdf0e10cSrcweir 			else if ( !bAlt && !nButtonDown &&
2486cdf0e10cSrcweir 						GetEditUrl(rMEvt.GetPosPixel()) )
2487cdf0e10cSrcweir 				SetPointer( Pointer( POINTER_REFHAND ) );
2488cdf0e10cSrcweir 			else if ( DrawMouseMove(rMEvt) )				// setzt Pointer um
2489cdf0e10cSrcweir 				return;
2490cdf0e10cSrcweir 		}
2491cdf0e10cSrcweir 	}
2492cdf0e10cSrcweir 
2493cdf0e10cSrcweir 	if ( pViewData->GetView()->GetSelEngine()->SelMouseMove( rMEvt ) )
2494cdf0e10cSrcweir 		return;
2495cdf0e10cSrcweir }
2496cdf0e10cSrcweir 
2497cdf0e10cSrcweir void lcl_InitMouseEvent( ::com::sun::star::awt::MouseEvent& rEvent, const MouseEvent& rEvt )
2498cdf0e10cSrcweir {
2499cdf0e10cSrcweir 	rEvent.Modifiers = 0;
2500cdf0e10cSrcweir 	if ( rEvt.IsShift() )
2501cdf0e10cSrcweir 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT;
2502cdf0e10cSrcweir 	if ( rEvt.IsMod1() )
2503cdf0e10cSrcweir 	rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1;
2504cdf0e10cSrcweir 	if ( rEvt.IsMod2() )
2505cdf0e10cSrcweir 		rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2;
2506cdf0e10cSrcweir         if ( rEvt.IsMod3() )
2507cdf0e10cSrcweir                 rEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD3;
2508cdf0e10cSrcweir 
2509cdf0e10cSrcweir 	rEvent.Buttons = 0;
2510cdf0e10cSrcweir 	if ( rEvt.IsLeft() )
2511cdf0e10cSrcweir 		rEvent.Buttons |= ::com::sun::star::awt::MouseButton::LEFT;
2512cdf0e10cSrcweir 	if ( rEvt.IsRight() )
2513cdf0e10cSrcweir 		rEvent.Buttons |= ::com::sun::star::awt::MouseButton::RIGHT;
2514cdf0e10cSrcweir 	if ( rEvt.IsMiddle() )
2515cdf0e10cSrcweir 		rEvent.Buttons |= ::com::sun::star::awt::MouseButton::MIDDLE;
2516cdf0e10cSrcweir 
2517cdf0e10cSrcweir 	rEvent.X = rEvt.GetPosPixel().X();
2518cdf0e10cSrcweir 	rEvent.Y = rEvt.GetPosPixel().Y();
2519cdf0e10cSrcweir 	rEvent.ClickCount = rEvt.GetClicks();
2520cdf0e10cSrcweir 	rEvent.PopupTrigger = sal_False;
2521cdf0e10cSrcweir }
2522cdf0e10cSrcweir 
2523cdf0e10cSrcweir long ScGridWindow::PreNotify( NotifyEvent& rNEvt )
2524cdf0e10cSrcweir {
2525cdf0e10cSrcweir     bool bDone = false;
2526cdf0e10cSrcweir 	sal_uInt16 nType = rNEvt.GetType();
2527cdf0e10cSrcweir 	if ( nType == EVENT_MOUSEBUTTONUP || nType == EVENT_MOUSEBUTTONDOWN )
2528cdf0e10cSrcweir     {
2529cdf0e10cSrcweir 		Window* pWindow = rNEvt.GetWindow();
2530cdf0e10cSrcweir         if (pWindow == this && pViewData)
2531cdf0e10cSrcweir         {
2532cdf0e10cSrcweir 	        SfxViewFrame* pViewFrame = pViewData->GetViewShell()->GetViewFrame();
2533cdf0e10cSrcweir 	        if (pViewFrame)
2534cdf0e10cSrcweir 	        {
2535cdf0e10cSrcweir 		        com::sun::star::uno::Reference<com::sun::star::frame::XController> xController = pViewFrame->GetFrame().GetController();
2536cdf0e10cSrcweir 		        if (xController.is())
2537cdf0e10cSrcweir 		        {
2538cdf0e10cSrcweir 			        ScTabViewObj* pImp = ScTabViewObj::getImplementation( xController );
2539cdf0e10cSrcweir 			        if (pImp && pImp->IsMouseListening())
2540cdf0e10cSrcweir                     {
2541cdf0e10cSrcweir 		                ::com::sun::star::awt::MouseEvent aEvent;
2542cdf0e10cSrcweir 		                lcl_InitMouseEvent( aEvent, *rNEvt.GetMouseEvent() );
2543cdf0e10cSrcweir                         if ( rNEvt.GetWindow() )
2544cdf0e10cSrcweir 	                        aEvent.Source = rNEvt.GetWindow()->GetComponentInterface();
2545cdf0e10cSrcweir                         if ( nType == EVENT_MOUSEBUTTONDOWN)
2546cdf0e10cSrcweir                             bDone = pImp->MousePressed( aEvent );
2547cdf0e10cSrcweir                         else
2548cdf0e10cSrcweir                             bDone = pImp->MouseReleased( aEvent );
2549cdf0e10cSrcweir                     }
2550cdf0e10cSrcweir 		        }
2551cdf0e10cSrcweir 	        }
2552cdf0e10cSrcweir         }
2553cdf0e10cSrcweir 	}
2554cdf0e10cSrcweir     if (bDone)      // event consumed by a listener
2555cdf0e10cSrcweir     {
2556cdf0e10cSrcweir         if ( nType == EVENT_MOUSEBUTTONDOWN )
2557cdf0e10cSrcweir         {
2558cdf0e10cSrcweir             const MouseEvent* pMouseEvent = rNEvt.GetMouseEvent();
2559cdf0e10cSrcweir             if ( pMouseEvent->IsRight() && pMouseEvent->GetClicks() == 1 )
2560cdf0e10cSrcweir             {
2561cdf0e10cSrcweir                 // If a listener returned true for a right-click call, also prevent opening the context menu
2562cdf0e10cSrcweir                 // (this works only if the context menu is opened on mouse-down)
2563cdf0e10cSrcweir                 nMouseStatus = SC_GM_IGNORE;
2564cdf0e10cSrcweir             }
2565cdf0e10cSrcweir         }
2566cdf0e10cSrcweir 
2567cdf0e10cSrcweir         return 1;
2568cdf0e10cSrcweir     }
2569cdf0e10cSrcweir     else
2570cdf0e10cSrcweir         return Window::PreNotify( rNEvt );
2571cdf0e10cSrcweir }
2572cdf0e10cSrcweir 
2573cdf0e10cSrcweir void ScGridWindow::Tracking( const TrackingEvent& rTEvt )
2574cdf0e10cSrcweir {
2575cdf0e10cSrcweir 	//	Weil die SelectionEngine kein Tracking kennt, die Events nur auf
2576cdf0e10cSrcweir 	//	die verschiedenen MouseHandler verteilen...
2577cdf0e10cSrcweir 
2578cdf0e10cSrcweir 	const MouseEvent& rMEvt = rTEvt.GetMouseEvent();
2579cdf0e10cSrcweir 
2580cdf0e10cSrcweir 	if ( rTEvt.IsTrackingCanceled() )		// alles abbrechen...
2581cdf0e10cSrcweir 	{
2582cdf0e10cSrcweir 		if (!pViewData->GetView()->IsInActivatePart())
2583cdf0e10cSrcweir 		{
2584cdf0e10cSrcweir 			if (bDPMouse)
2585cdf0e10cSrcweir 				bDPMouse = sal_False;				// gezeichnet wird per bDragRect
2586cdf0e10cSrcweir 			if (bDragRect)
2587cdf0e10cSrcweir 			{
2588cdf0e10cSrcweir 				// pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
2589cdf0e10cSrcweir 				bDragRect = sal_False;
2590cdf0e10cSrcweir                 UpdateDragRectOverlay();
2591cdf0e10cSrcweir 			}
2592cdf0e10cSrcweir 			if (bRFMouse)
2593cdf0e10cSrcweir 			{
2594cdf0e10cSrcweir 				RFMouseMove( rMEvt, sal_True );		// richtig abbrechen geht dabei nicht...
2595cdf0e10cSrcweir 				bRFMouse = sal_False;
2596cdf0e10cSrcweir 			}
2597cdf0e10cSrcweir 			if (nPagebreakMouse)
2598cdf0e10cSrcweir 			{
2599cdf0e10cSrcweir 				// if (bPagebreakDrawn)
2600cdf0e10cSrcweir 				//	DrawDragRect( aPagebreakDrag.aStart.Col(), aPagebreakDrag.aStart.Row(),
2601cdf0e10cSrcweir 				//					aPagebreakDrag.aEnd.Col(), aPagebreakDrag.aEnd.Row(), sal_False );
2602cdf0e10cSrcweir 				bPagebreakDrawn = sal_False;
2603cdf0e10cSrcweir                 UpdateDragRectOverlay();
2604cdf0e10cSrcweir 				nPagebreakMouse = SC_PD_NONE;
2605cdf0e10cSrcweir 			}
2606cdf0e10cSrcweir 
2607cdf0e10cSrcweir 			SetPointer( Pointer( POINTER_ARROW ) );
2608cdf0e10cSrcweir 			StopMarking();
2609cdf0e10cSrcweir 			MouseButtonUp( rMEvt );		// mit Status SC_GM_IGNORE aus StopMarking
2610cdf0e10cSrcweir 
2611cdf0e10cSrcweir 			sal_Bool bRefMode =	pViewData->IsRefMode();
2612cdf0e10cSrcweir 			if (bRefMode)
2613cdf0e10cSrcweir 				SC_MOD()->EndReference();		// #63148# Dialog nicht verkleinert lassen
2614cdf0e10cSrcweir 		}
2615cdf0e10cSrcweir 	}
2616cdf0e10cSrcweir 	else if ( rTEvt.IsTrackingEnded() )
2617cdf0e10cSrcweir 	{
2618cdf0e10cSrcweir 		//	MouseButtonUp immer mit passenden Buttons (z.B. wegen Testtool, #63148#)
2619cdf0e10cSrcweir 		//	Schliesslich behauptet der Tracking-Event ja, dass normal beendet und nicht
2620cdf0e10cSrcweir 		//	abgebrochen wurde.
2621cdf0e10cSrcweir 
2622cdf0e10cSrcweir 		MouseEvent aUpEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(),
2623cdf0e10cSrcweir 							rMEvt.GetMode(), nButtonDown, rMEvt.GetModifier() );
2624cdf0e10cSrcweir 		MouseButtonUp( aUpEvt );
2625cdf0e10cSrcweir 	}
2626cdf0e10cSrcweir 	else
2627cdf0e10cSrcweir 		MouseMove( rMEvt );
2628cdf0e10cSrcweir }
2629cdf0e10cSrcweir 
2630cdf0e10cSrcweir void ScGridWindow::StartDrag( sal_Int8 /* nAction */, const Point& rPosPixel )
2631cdf0e10cSrcweir {
2632cdf0e10cSrcweir 	if ( pFilterBox || nPagebreakMouse )
2633cdf0e10cSrcweir 		return;
2634cdf0e10cSrcweir 
2635cdf0e10cSrcweir 	HideNoteMarker();
2636cdf0e10cSrcweir 
2637cdf0e10cSrcweir 	CommandEvent aDragEvent( rPosPixel, COMMAND_STARTDRAG, sal_True );
2638cdf0e10cSrcweir 
2639cdf0e10cSrcweir     if (bEEMouse && pViewData->HasEditView( eWhich ))
2640cdf0e10cSrcweir 	{
2641cdf0e10cSrcweir 		EditView*	pEditView;
2642cdf0e10cSrcweir 		SCCOL		nEditCol;
2643cdf0e10cSrcweir 		SCROW		nEditRow;
2644cdf0e10cSrcweir 		pViewData->GetEditView( eWhich, pEditView, nEditCol, nEditRow );
2645cdf0e10cSrcweir 
2646cdf0e10cSrcweir 		// #63263# don't remove the edit view while switching views
2647cdf0e10cSrcweir 		ScModule* pScMod = SC_MOD();
2648cdf0e10cSrcweir 		pScMod->SetInEditCommand( sal_True );
2649cdf0e10cSrcweir 
2650cdf0e10cSrcweir 		pEditView->Command( aDragEvent );
2651cdf0e10cSrcweir 
2652cdf0e10cSrcweir 		ScInputHandler* pHdl = pScMod->GetInputHdl();
2653cdf0e10cSrcweir 		if (pHdl)
2654cdf0e10cSrcweir 			pHdl->DataChanged();
2655cdf0e10cSrcweir 
2656cdf0e10cSrcweir 		pScMod->SetInEditCommand( sal_False );
2657cdf0e10cSrcweir 		if (!pViewData->IsActive())				// dropped to different view?
2658cdf0e10cSrcweir 		{
2659cdf0e10cSrcweir 			ScInputHandler* pViewHdl = pScMod->GetInputHdl( pViewData->GetViewShell() );
2660cdf0e10cSrcweir 			if ( pViewHdl && pViewData->HasEditView( eWhich ) )
2661cdf0e10cSrcweir 			{
2662cdf0e10cSrcweir 				pViewHdl->CancelHandler();
2663cdf0e10cSrcweir 				ShowCursor();	// missing from KillEditView
2664cdf0e10cSrcweir 			}
2665cdf0e10cSrcweir 		}
2666cdf0e10cSrcweir 	}
2667cdf0e10cSrcweir 	else
2668cdf0e10cSrcweir 		if ( !DrawCommand(aDragEvent) )
2669cdf0e10cSrcweir 			pViewData->GetView()->GetSelEngine()->Command( aDragEvent );
2670cdf0e10cSrcweir }
2671cdf0e10cSrcweir 
2672cdf0e10cSrcweir void lcl_SetTextCursorPos( ScViewData* pViewData, ScSplitPos eWhich, Window* pWin )
2673cdf0e10cSrcweir {
2674cdf0e10cSrcweir 	SCCOL nCol = pViewData->GetCurX();
2675cdf0e10cSrcweir 	SCROW nRow = pViewData->GetCurY();
2676cdf0e10cSrcweir 	Rectangle aEditArea = pViewData->GetEditArea( eWhich, nCol, nRow, pWin, NULL, sal_True );
2677cdf0e10cSrcweir 	aEditArea.Right() = aEditArea.Left();
2678cdf0e10cSrcweir 	aEditArea = pWin->PixelToLogic( aEditArea );
2679cdf0e10cSrcweir 	pWin->SetCursorRect( &aEditArea );
2680cdf0e10cSrcweir }
2681cdf0e10cSrcweir 
2682cdf0e10cSrcweir void __EXPORT ScGridWindow::Command( const CommandEvent& rCEvt )
2683cdf0e10cSrcweir {
2684cdf0e10cSrcweir     // The command event is send to the window after a possible context
2685cdf0e10cSrcweir     // menu from an inplace client is closed. Now we have the chance to
2686cdf0e10cSrcweir     // deactivate the inplace client without any problem regarding parent
2687cdf0e10cSrcweir     // windows and code on the stack.
2688cdf0e10cSrcweir     // For more information, see #126086# and #128122#
2689cdf0e10cSrcweir     sal_uInt16 nCmd = rCEvt.GetCommand();
2690cdf0e10cSrcweir     ScTabViewShell* pTabViewSh = pViewData->GetViewShell();
2691cdf0e10cSrcweir 	SfxInPlaceClient* pClient = pTabViewSh->GetIPClient();
2692cdf0e10cSrcweir     if ( pClient &&
2693cdf0e10cSrcweir          pClient->IsObjectInPlaceActive() &&
2694cdf0e10cSrcweir          nCmd == COMMAND_CONTEXTMENU )
2695cdf0e10cSrcweir     {
2696cdf0e10cSrcweir         pTabViewSh->DeactivateOle();
2697cdf0e10cSrcweir         return;
2698cdf0e10cSrcweir     }
2699cdf0e10cSrcweir 
2700cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
2701cdf0e10cSrcweir 	DBG_ASSERT( nCmd != COMMAND_STARTDRAG, "ScGridWindow::Command called with COMMAND_STARTDRAG" );
2702cdf0e10cSrcweir 
2703cdf0e10cSrcweir 	if ( nCmd == COMMAND_STARTEXTTEXTINPUT ||
2704cdf0e10cSrcweir 		 nCmd == COMMAND_ENDEXTTEXTINPUT ||
2705cdf0e10cSrcweir 		 nCmd == COMMAND_EXTTEXTINPUT ||
2706cdf0e10cSrcweir 		 nCmd == COMMAND_CURSORPOS )
2707cdf0e10cSrcweir 	{
2708cdf0e10cSrcweir 		sal_Bool bEditView = pViewData->HasEditView( eWhich );
2709cdf0e10cSrcweir 		if (!bEditView)
2710cdf0e10cSrcweir 		{
2711cdf0e10cSrcweir 			//	only if no cell editview is active, look at drawview
2712cdf0e10cSrcweir 			SdrView* pSdrView = pViewData->GetView()->GetSdrView();
2713cdf0e10cSrcweir 			if ( pSdrView )
2714cdf0e10cSrcweir 			{
2715cdf0e10cSrcweir 				OutlinerView* pOlView = pSdrView->GetTextEditOutlinerView();
2716cdf0e10cSrcweir 				if ( pOlView && pOlView->GetWindow() == this )
2717cdf0e10cSrcweir 				{
2718cdf0e10cSrcweir 					pOlView->Command( rCEvt );
2719cdf0e10cSrcweir 					return;								// done
2720cdf0e10cSrcweir 				}
2721cdf0e10cSrcweir 			}
2722cdf0e10cSrcweir 		}
2723cdf0e10cSrcweir 
2724cdf0e10cSrcweir 		if ( nCmd == COMMAND_CURSORPOS && !bEditView )
2725cdf0e10cSrcweir 		{
2726cdf0e10cSrcweir 			//	#88458# CURSORPOS may be called without following text input,
2727cdf0e10cSrcweir 			//	to set the input method window position
2728cdf0e10cSrcweir 			//	-> input mode must not be started,
2729cdf0e10cSrcweir 			//	manually calculate text insert position if not in input mode
2730cdf0e10cSrcweir 
2731cdf0e10cSrcweir 			lcl_SetTextCursorPos( pViewData, eWhich, this );
2732cdf0e10cSrcweir 			return;
2733cdf0e10cSrcweir 		}
2734cdf0e10cSrcweir 
2735cdf0e10cSrcweir 		ScInputHandler* pHdl = pScMod->GetInputHdl( pViewData->GetViewShell() );
2736cdf0e10cSrcweir 		if ( pHdl )
2737cdf0e10cSrcweir 		{
2738cdf0e10cSrcweir 			pHdl->InputCommand( rCEvt, sal_True );
2739cdf0e10cSrcweir 			return;										// done
2740cdf0e10cSrcweir 		}
2741cdf0e10cSrcweir 
2742cdf0e10cSrcweir 		Window::Command( rCEvt );
2743cdf0e10cSrcweir 		return;
2744cdf0e10cSrcweir 	}
2745cdf0e10cSrcweir 
2746cdf0e10cSrcweir 	if ( nCmd == COMMAND_VOICE )
2747cdf0e10cSrcweir 	{
2748cdf0e10cSrcweir 		//	Der Handler wird nur gerufen, wenn ein Text-Cursor aktiv ist,
2749cdf0e10cSrcweir 		//	also muss es eine EditView oder ein editiertes Zeichenobjekt geben
2750cdf0e10cSrcweir 
2751cdf0e10cSrcweir 		ScInputHandler* pHdl = pScMod->GetInputHdl( pViewData->GetViewShell() );
2752cdf0e10cSrcweir 		if ( pHdl && pViewData->HasEditView( eWhich ) )
2753cdf0e10cSrcweir 		{
2754cdf0e10cSrcweir 			EditView* pEditView = pViewData->GetEditView( eWhich );	// ist dann nicht 0
2755cdf0e10cSrcweir 			pHdl->DataChanging();
2756cdf0e10cSrcweir 			pEditView->Command( rCEvt );
2757cdf0e10cSrcweir 			pHdl->DataChanged();
2758cdf0e10cSrcweir 			return;										// erledigt
2759cdf0e10cSrcweir 		}
2760cdf0e10cSrcweir 		SdrView* pSdrView = pViewData->GetView()->GetSdrView();
2761cdf0e10cSrcweir 		if ( pSdrView )
2762cdf0e10cSrcweir 		{
2763cdf0e10cSrcweir 			OutlinerView* pOlView = pSdrView->GetTextEditOutlinerView();
2764cdf0e10cSrcweir 			if ( pOlView && pOlView->GetWindow() == this )
2765cdf0e10cSrcweir 			{
2766cdf0e10cSrcweir 				pOlView->Command( rCEvt );
2767cdf0e10cSrcweir 				return;									// erledigt
2768cdf0e10cSrcweir 			}
2769cdf0e10cSrcweir 		}
2770cdf0e10cSrcweir 		Window::Command(rCEvt);		//	sonst soll sich die Basisklasse drum kuemmern...
2771cdf0e10cSrcweir 		return;
2772cdf0e10cSrcweir 	}
2773cdf0e10cSrcweir 
2774cdf0e10cSrcweir 	if ( nCmd == COMMAND_PASTESELECTION )
2775cdf0e10cSrcweir 	{
2776cdf0e10cSrcweir 		if ( bEEMouse )
2777cdf0e10cSrcweir 		{
2778cdf0e10cSrcweir 			//	EditEngine handles selection in MouseButtonUp - no action
2779cdf0e10cSrcweir 			//	needed in command handler
2780cdf0e10cSrcweir 		}
2781cdf0e10cSrcweir 		else
2782cdf0e10cSrcweir 		{
2783cdf0e10cSrcweir 			PasteSelection( rCEvt.GetMousePosPixel() );
2784cdf0e10cSrcweir 		}
2785cdf0e10cSrcweir 		return;
2786cdf0e10cSrcweir 	}
2787cdf0e10cSrcweir 
2788cdf0e10cSrcweir     if ( nCmd == COMMAND_INPUTLANGUAGECHANGE )
2789cdf0e10cSrcweir     {
2790cdf0e10cSrcweir         // #i55929# Font and font size state depends on input language if nothing is selected,
2791cdf0e10cSrcweir         // so the slots have to be invalidated when the input language is changed.
2792cdf0e10cSrcweir 
2793cdf0e10cSrcweir         SfxBindings& rBindings = pViewData->GetBindings();
2794cdf0e10cSrcweir         rBindings.Invalidate( SID_ATTR_CHAR_FONT );
2795cdf0e10cSrcweir         rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
2796cdf0e10cSrcweir         return;
2797cdf0e10cSrcweir     }
2798cdf0e10cSrcweir 
2799cdf0e10cSrcweir 	if ( nCmd == COMMAND_WHEEL || nCmd == COMMAND_STARTAUTOSCROLL || nCmd == COMMAND_AUTOSCROLL )
2800cdf0e10cSrcweir 	{
2801cdf0e10cSrcweir 		sal_Bool bDone = pViewData->GetView()->ScrollCommand( rCEvt, eWhich );
2802cdf0e10cSrcweir 		if (!bDone)
2803cdf0e10cSrcweir 			Window::Command(rCEvt);
2804cdf0e10cSrcweir 		return;
2805cdf0e10cSrcweir 	}
2806cdf0e10cSrcweir     // #i7560# FormulaMode check is below scrolling - scrolling is allowed during formula input
2807cdf0e10cSrcweir 	sal_Bool bDisable = pScMod->IsFormulaMode() ||
2808cdf0e10cSrcweir 					pScMod->IsModalMode(pViewData->GetSfxDocShell());
2809cdf0e10cSrcweir 	if (bDisable)
2810cdf0e10cSrcweir 		return;
2811cdf0e10cSrcweir 
2812cdf0e10cSrcweir 	if ( nCmd == COMMAND_CONTEXTMENU && !SC_MOD()->GetIsWaterCan() )
2813cdf0e10cSrcweir 	{
2814cdf0e10cSrcweir         sal_Bool bMouse = rCEvt.IsMouseEvent();
2815cdf0e10cSrcweir         if ( bMouse && nMouseStatus == SC_GM_IGNORE )
2816cdf0e10cSrcweir             return;
2817cdf0e10cSrcweir 
2818cdf0e10cSrcweir 		if (pViewData->IsAnyFillMode())
2819cdf0e10cSrcweir 		{
2820cdf0e10cSrcweir 			pViewData->GetView()->StopRefMode();
2821cdf0e10cSrcweir 			pViewData->ResetFillMode();
2822cdf0e10cSrcweir 		}
2823cdf0e10cSrcweir 		ReleaseMouse();
2824cdf0e10cSrcweir 		StopMarking();
2825cdf0e10cSrcweir 
2826cdf0e10cSrcweir 		Point aPosPixel = rCEvt.GetMousePosPixel();
2827cdf0e10cSrcweir 		Point aMenuPos = aPosPixel;
2828cdf0e10cSrcweir 
2829cdf0e10cSrcweir 		if ( bMouse )
2830cdf0e10cSrcweir 		{
2831cdf0e10cSrcweir             SCsCOL nCellX = -1;
2832cdf0e10cSrcweir             SCsROW nCellY = -1;
2833cdf0e10cSrcweir             pViewData->GetPosFromPixel(aPosPixel.X(), aPosPixel.Y(), eWhich, nCellX, nCellY);
2834cdf0e10cSrcweir             ScDocument* pDoc = pViewData->GetDocument();
2835cdf0e10cSrcweir             SCTAB nTab = pViewData->GetTabNo();
2836cdf0e10cSrcweir             const ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
2837cdf0e10cSrcweir             bool bSelectAllowed = true;
2838cdf0e10cSrcweir             if ( pProtect && pProtect->isProtected() )
2839cdf0e10cSrcweir             {
2840cdf0e10cSrcweir                 // This sheet is protected.  Check if a context menu is allowed on this cell.
2841cdf0e10cSrcweir                 bool bCellProtected = pDoc->HasAttrib(nCellX, nCellY, nTab, nCellX, nCellY, nTab, HASATTR_PROTECTED);
2842cdf0e10cSrcweir                 bool bSelProtected   = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
2843cdf0e10cSrcweir                 bool bSelUnprotected = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
2844cdf0e10cSrcweir 
2845cdf0e10cSrcweir                 if (bCellProtected)
2846cdf0e10cSrcweir                     bSelectAllowed = bSelProtected;
2847cdf0e10cSrcweir                 else
2848cdf0e10cSrcweir                     bSelectAllowed = bSelUnprotected;
2849cdf0e10cSrcweir             }
2850cdf0e10cSrcweir             if (!bSelectAllowed)
2851cdf0e10cSrcweir                 // Selecting this cell is not allowed, neither is context menu.
2852cdf0e10cSrcweir                 return;
2853cdf0e10cSrcweir 
2854cdf0e10cSrcweir 			//	#i18735# First select the item under the mouse pointer.
2855cdf0e10cSrcweir 			//	This can change the selection, and the view state (edit mode, etc).
2856cdf0e10cSrcweir             SelectForContextMenu( aPosPixel, nCellX, nCellY );
2857cdf0e10cSrcweir 		}
2858cdf0e10cSrcweir 
2859cdf0e10cSrcweir 		sal_Bool bDone = sal_False;
2860cdf0e10cSrcweir 		sal_Bool bEdit = pViewData->HasEditView(eWhich);
2861cdf0e10cSrcweir 		if ( !bEdit )
2862cdf0e10cSrcweir 		{
2863cdf0e10cSrcweir 				// Edit-Zelle mit Spelling-Errors ?
2864cdf0e10cSrcweir 			if ( bMouse && GetEditUrlOrError( sal_True, aPosPixel ) )
2865cdf0e10cSrcweir 			{
2866cdf0e10cSrcweir 				//	GetEditUrlOrError hat den Cursor schon bewegt
2867cdf0e10cSrcweir 
2868cdf0e10cSrcweir 				pScMod->SetInputMode( SC_INPUT_TABLE );
2869cdf0e10cSrcweir 				bEdit = pViewData->HasEditView(eWhich);		// hat's geklappt ?
2870cdf0e10cSrcweir 
2871cdf0e10cSrcweir 				DBG_ASSERT( bEdit, "kann nicht in Edit-Modus schalten" );
2872cdf0e10cSrcweir 			}
2873cdf0e10cSrcweir 		}
2874cdf0e10cSrcweir 		if ( bEdit )
2875cdf0e10cSrcweir 		{
2876cdf0e10cSrcweir 			EditView* pEditView = pViewData->GetEditView( eWhich );		// ist dann nicht 0
2877cdf0e10cSrcweir 
2878cdf0e10cSrcweir 			if ( !bMouse )
2879cdf0e10cSrcweir 			{
2880cdf0e10cSrcweir 				Cursor* pCur = pEditView->GetCursor();
2881cdf0e10cSrcweir 				if ( pCur )
2882cdf0e10cSrcweir 				{
2883cdf0e10cSrcweir 					Point aLogicPos = pCur->GetPos();
2884cdf0e10cSrcweir 					//	use the position right of the cursor (spell popup is opened if
2885cdf0e10cSrcweir 					//	the cursor is before the word, but not if behind it)
2886cdf0e10cSrcweir 					aLogicPos.X() += pCur->GetWidth();
2887cdf0e10cSrcweir 					aLogicPos.Y() += pCur->GetHeight() / 2;		// center vertically
2888cdf0e10cSrcweir 					aMenuPos = LogicToPixel( aLogicPos );
2889cdf0e10cSrcweir 				}
2890cdf0e10cSrcweir 			}
2891cdf0e10cSrcweir 
2892cdf0e10cSrcweir 			//	if edit mode was just started above, online spelling may be incomplete
2893cdf0e10cSrcweir 			pEditView->GetEditEngine()->CompleteOnlineSpelling();
2894cdf0e10cSrcweir 
2895cdf0e10cSrcweir 			//	IsCursorAtWrongSpelledWord could be used for !bMouse
2896cdf0e10cSrcweir 			//	if there was a corresponding ExecuteSpellPopup call
2897cdf0e10cSrcweir 
2898cdf0e10cSrcweir 			if( pEditView->IsWrongSpelledWordAtPos( aMenuPos ) )
2899cdf0e10cSrcweir 			{
2900cdf0e10cSrcweir 				//	Wenn man unter OS/2 neben das Popupmenue klickt, kommt MouseButtonDown
2901cdf0e10cSrcweir 				//	vor dem Ende des Menue-Execute, darum muss SetModified vorher kommen
2902cdf0e10cSrcweir 				//	(Bug #40968#)
2903cdf0e10cSrcweir 				ScInputHandler* pHdl = pScMod->GetInputHdl();
2904cdf0e10cSrcweir 				if (pHdl)
2905cdf0e10cSrcweir 					pHdl->SetModified();
2906cdf0e10cSrcweir 
2907cdf0e10cSrcweir                 Link aLink = LINK( this, ScGridWindow, PopupSpellingHdl );
2908cdf0e10cSrcweir                 pEditView->ExecuteSpellPopup( aMenuPos, &aLink );
2909cdf0e10cSrcweir 
2910cdf0e10cSrcweir 				bDone = sal_True;
2911cdf0e10cSrcweir 			}
2912cdf0e10cSrcweir 		}
2913cdf0e10cSrcweir 		else if ( !bMouse )
2914cdf0e10cSrcweir 		{
2915cdf0e10cSrcweir 			//	non-edit menu by keyboard -> use lower right of cell cursor position
2916cdf0e10cSrcweir 
2917cdf0e10cSrcweir 			SCCOL nCurX = pViewData->GetCurX();
2918cdf0e10cSrcweir 			SCROW nCurY = pViewData->GetCurY();
2919cdf0e10cSrcweir 			aMenuPos = pViewData->GetScrPos( nCurX, nCurY, eWhich, sal_True );
2920cdf0e10cSrcweir 			long nSizeXPix;
2921cdf0e10cSrcweir 			long nSizeYPix;
2922cdf0e10cSrcweir 			pViewData->GetMergeSizePixel( nCurX, nCurY, nSizeXPix, nSizeYPix );
2923cdf0e10cSrcweir 			aMenuPos.X() += nSizeXPix;
2924cdf0e10cSrcweir 			aMenuPos.Y() += nSizeYPix;
2925cdf0e10cSrcweir 
2926cdf0e10cSrcweir             if (pViewData)
2927cdf0e10cSrcweir             {
2928cdf0e10cSrcweir         	    ScTabViewShell* pViewSh = pViewData->GetViewShell();
2929cdf0e10cSrcweir 	            if (pViewSh)
2930cdf0e10cSrcweir 	            {
2931cdf0e10cSrcweir 		            //	Is a draw object selected?
2932cdf0e10cSrcweir 
2933cdf0e10cSrcweir 		            SdrView* pDrawView = pViewSh->GetSdrView();
2934cdf0e10cSrcweir 		            if (pDrawView && pDrawView->AreObjectsMarked())
2935cdf0e10cSrcweir 		            {
2936cdf0e10cSrcweir                         // #100442#; the conext menu should open in the middle of the selected objects
2937cdf0e10cSrcweir                         Rectangle aSelectRect(LogicToPixel(pDrawView->GetAllMarkedBoundRect()));
2938cdf0e10cSrcweir                         aMenuPos = aSelectRect.Center();
2939cdf0e10cSrcweir 		            }
2940cdf0e10cSrcweir                 }
2941cdf0e10cSrcweir             }
2942cdf0e10cSrcweir 		}
2943cdf0e10cSrcweir 
2944cdf0e10cSrcweir 		if (!bDone)
2945cdf0e10cSrcweir 		{
2946cdf0e10cSrcweir 			SfxDispatcher::ExecutePopup( 0, this, &aMenuPos );
2947cdf0e10cSrcweir 		}
2948cdf0e10cSrcweir 	}
2949cdf0e10cSrcweir }
2950cdf0e10cSrcweir 
2951cdf0e10cSrcweir void ScGridWindow::SelectForContextMenu( const Point& rPosPixel, SCsCOL nCellX, SCsROW nCellY )
2952cdf0e10cSrcweir {
2953cdf0e10cSrcweir     //  #i18735# if the click was outside of the current selection,
2954cdf0e10cSrcweir     //  the cursor is moved or an object at the click position selected.
2955cdf0e10cSrcweir     //  (see SwEditWin::SelectMenuPosition in Writer)
2956cdf0e10cSrcweir 
2957cdf0e10cSrcweir     ScTabView* pView = pViewData->GetView();
2958cdf0e10cSrcweir     ScDrawView* pDrawView = pView->GetScDrawView();
2959cdf0e10cSrcweir 
2960cdf0e10cSrcweir     //  check cell edit mode
2961cdf0e10cSrcweir 
2962cdf0e10cSrcweir     if ( pViewData->HasEditView(eWhich) )
2963cdf0e10cSrcweir     {
2964cdf0e10cSrcweir         ScModule* pScMod = SC_MOD();
2965cdf0e10cSrcweir         SCCOL nEditStartCol = pViewData->GetEditViewCol(); //! change to GetEditStartCol after calcrtl is integrated
2966cdf0e10cSrcweir         SCROW nEditStartRow = pViewData->GetEditViewRow();
2967cdf0e10cSrcweir         SCCOL nEditEndCol = pViewData->GetEditEndCol();
2968cdf0e10cSrcweir         SCROW nEditEndRow = pViewData->GetEditEndRow();
2969cdf0e10cSrcweir 
2970cdf0e10cSrcweir         if ( nCellX >= (SCsCOL) nEditStartCol && nCellX <= (SCsCOL) nEditEndCol &&
2971cdf0e10cSrcweir              nCellY >= (SCsROW) nEditStartRow && nCellY <= (SCsROW) nEditEndRow )
2972cdf0e10cSrcweir         {
2973cdf0e10cSrcweir             //  handle selection within the EditView
2974cdf0e10cSrcweir 
2975cdf0e10cSrcweir             EditView* pEditView = pViewData->GetEditView( eWhich );     // not NULL (HasEditView)
2976cdf0e10cSrcweir             EditEngine* pEditEngine = pEditView->GetEditEngine();
2977cdf0e10cSrcweir             Rectangle aOutputArea = pEditView->GetOutputArea();
2978cdf0e10cSrcweir             Rectangle aVisArea = pEditView->GetVisArea();
2979cdf0e10cSrcweir 
2980cdf0e10cSrcweir             Point aTextPos = PixelToLogic( rPosPixel );
2981cdf0e10cSrcweir             if ( pEditEngine->IsVertical() )            // have to manually transform position
2982cdf0e10cSrcweir             {
2983cdf0e10cSrcweir                 aTextPos -= aOutputArea.TopRight();
2984cdf0e10cSrcweir                 long nTemp = -aTextPos.X();
2985cdf0e10cSrcweir                 aTextPos.X() = aTextPos.Y();
2986cdf0e10cSrcweir                 aTextPos.Y() = nTemp;
2987cdf0e10cSrcweir             }
2988cdf0e10cSrcweir             else
2989cdf0e10cSrcweir                 aTextPos -= aOutputArea.TopLeft();
2990cdf0e10cSrcweir             aTextPos += aVisArea.TopLeft();             // position in the edit document
2991cdf0e10cSrcweir 
2992cdf0e10cSrcweir             EPosition aDocPosition = pEditEngine->FindDocPosition(aTextPos);
2993cdf0e10cSrcweir             ESelection aCompare(aDocPosition.nPara, aDocPosition.nIndex);
2994cdf0e10cSrcweir             ESelection aSelection = pEditView->GetSelection();
2995cdf0e10cSrcweir             aSelection.Adjust();    // needed for IsLess/IsGreater
2996cdf0e10cSrcweir             if ( aCompare.IsLess(aSelection) || aCompare.IsGreater(aSelection) )
2997cdf0e10cSrcweir             {
2998cdf0e10cSrcweir                 // clicked outside the selected text - deselect and move text cursor
2999cdf0e10cSrcweir                 MouseEvent aEvent( rPosPixel );
3000cdf0e10cSrcweir                 pEditView->MouseButtonDown( aEvent );
3001cdf0e10cSrcweir                 pEditView->MouseButtonUp( aEvent );
3002cdf0e10cSrcweir                 pScMod->InputSelection( pEditView );
3003cdf0e10cSrcweir             }
3004cdf0e10cSrcweir 
3005cdf0e10cSrcweir             return;     // clicked within the edit view - keep edit mode
3006cdf0e10cSrcweir         }
3007cdf0e10cSrcweir         else
3008cdf0e10cSrcweir         {
3009cdf0e10cSrcweir             // outside of the edit view - end edit mode, regardless of cell selection, then continue
3010cdf0e10cSrcweir             pScMod->InputEnterHandler();
3011cdf0e10cSrcweir         }
3012cdf0e10cSrcweir     }
3013cdf0e10cSrcweir 
3014cdf0e10cSrcweir     //  check draw text edit mode
3015cdf0e10cSrcweir 
3016cdf0e10cSrcweir     Point aLogicPos = PixelToLogic( rPosPixel );        // after cell edit mode is ended
3017cdf0e10cSrcweir     if ( pDrawView && pDrawView->GetTextEditObject() && pDrawView->GetTextEditOutlinerView() )
3018cdf0e10cSrcweir     {
3019cdf0e10cSrcweir         OutlinerView* pOlView = pDrawView->GetTextEditOutlinerView();
3020cdf0e10cSrcweir         Rectangle aOutputArea = pOlView->GetOutputArea();
3021cdf0e10cSrcweir         if ( aOutputArea.IsInside( aLogicPos ) )
3022cdf0e10cSrcweir         {
3023cdf0e10cSrcweir             //  handle selection within the OutlinerView
3024cdf0e10cSrcweir 
3025cdf0e10cSrcweir             Outliner* pOutliner = pOlView->GetOutliner();
3026cdf0e10cSrcweir             const EditEngine& rEditEngine = pOutliner->GetEditEngine();
3027cdf0e10cSrcweir             Rectangle aVisArea = pOlView->GetVisArea();
3028cdf0e10cSrcweir 
3029cdf0e10cSrcweir             Point aTextPos = aLogicPos;
3030cdf0e10cSrcweir             if ( pOutliner->IsVertical() )              // have to manually transform position
3031cdf0e10cSrcweir             {
3032cdf0e10cSrcweir                 aTextPos -= aOutputArea.TopRight();
3033cdf0e10cSrcweir                 long nTemp = -aTextPos.X();
3034cdf0e10cSrcweir                 aTextPos.X() = aTextPos.Y();
3035cdf0e10cSrcweir                 aTextPos.Y() = nTemp;
3036cdf0e10cSrcweir             }
3037cdf0e10cSrcweir             else
3038cdf0e10cSrcweir                 aTextPos -= aOutputArea.TopLeft();
3039cdf0e10cSrcweir             aTextPos += aVisArea.TopLeft();             // position in the edit document
3040cdf0e10cSrcweir 
3041cdf0e10cSrcweir             EPosition aDocPosition = rEditEngine.FindDocPosition(aTextPos);
3042cdf0e10cSrcweir             ESelection aCompare(aDocPosition.nPara, aDocPosition.nIndex);
3043cdf0e10cSrcweir             ESelection aSelection = pOlView->GetSelection();
3044cdf0e10cSrcweir             aSelection.Adjust();    // needed for IsLess/IsGreater
3045cdf0e10cSrcweir             if ( aCompare.IsLess(aSelection) || aCompare.IsGreater(aSelection) )
3046cdf0e10cSrcweir             {
3047cdf0e10cSrcweir                 // clicked outside the selected text - deselect and move text cursor
3048cdf0e10cSrcweir                 // use DrawView to allow extra handling there (none currently)
3049cdf0e10cSrcweir                 MouseEvent aEvent( rPosPixel );
3050cdf0e10cSrcweir                 pDrawView->MouseButtonDown( aEvent, this );
3051cdf0e10cSrcweir                 pDrawView->MouseButtonUp( aEvent, this );
3052cdf0e10cSrcweir             }
3053cdf0e10cSrcweir 
3054cdf0e10cSrcweir             return;     // clicked within the edit area - keep edit mode
3055cdf0e10cSrcweir         }
3056cdf0e10cSrcweir         else
3057cdf0e10cSrcweir         {
3058cdf0e10cSrcweir             // Outside of the edit area - end text edit mode, then continue.
3059cdf0e10cSrcweir             // DrawDeselectAll also ends text edit mode and updates the shells.
3060cdf0e10cSrcweir             // If the click was on the edited object, it will be selected again below.
3061cdf0e10cSrcweir             pView->DrawDeselectAll();
3062cdf0e10cSrcweir         }
3063cdf0e10cSrcweir     }
3064cdf0e10cSrcweir 
3065cdf0e10cSrcweir     //  look for existing selection
3066cdf0e10cSrcweir 
3067cdf0e10cSrcweir     sal_Bool bHitSelected = sal_False;
3068cdf0e10cSrcweir     if ( pDrawView && pDrawView->IsMarkedObjHit( aLogicPos ) )
3069cdf0e10cSrcweir     {
3070cdf0e10cSrcweir         //  clicked on selected object -> don't change anything
3071cdf0e10cSrcweir         bHitSelected = sal_True;
3072cdf0e10cSrcweir     }
3073cdf0e10cSrcweir     else if ( pViewData->GetMarkData().IsCellMarked(nCellX, nCellY) )
3074cdf0e10cSrcweir     {
3075cdf0e10cSrcweir         //  clicked on selected cell -> don't change anything
3076cdf0e10cSrcweir         bHitSelected = sal_True;
3077cdf0e10cSrcweir     }
3078cdf0e10cSrcweir 
3079cdf0e10cSrcweir     //  select drawing object or move cell cursor
3080cdf0e10cSrcweir 
3081cdf0e10cSrcweir     if ( !bHitSelected )
3082cdf0e10cSrcweir     {
3083cdf0e10cSrcweir         sal_Bool bWasDraw = ( pDrawView && pDrawView->AreObjectsMarked() );
3084cdf0e10cSrcweir         sal_Bool bHitDraw = sal_False;
3085cdf0e10cSrcweir         if ( pDrawView )
3086cdf0e10cSrcweir         {
3087cdf0e10cSrcweir             pDrawView->UnmarkAllObj();
3088cdf0e10cSrcweir             // Unlock the Internal Layer in order to activate the context menu.
3089cdf0e10cSrcweir             // re-lock in ScDrawView::MarkListHasChanged()
3090cdf0e10cSrcweir             lcl_UnLockComment( pDrawView, pDrawView->GetSdrPageView(), pDrawView->GetModel(), aLogicPos ,pViewData);
3091cdf0e10cSrcweir             bHitDraw = pDrawView->MarkObj( aLogicPos );
3092cdf0e10cSrcweir             // draw shell is activated in MarkListHasChanged
3093cdf0e10cSrcweir         }
3094cdf0e10cSrcweir         if ( !bHitDraw )
3095cdf0e10cSrcweir         {
3096cdf0e10cSrcweir             pView->Unmark();
3097cdf0e10cSrcweir             pView->SetCursor(nCellX, nCellY);
3098cdf0e10cSrcweir             if ( bWasDraw )
3099cdf0e10cSrcweir                 pViewData->GetViewShell()->SetDrawShell( sal_False );   // switch shells
3100cdf0e10cSrcweir         }
3101cdf0e10cSrcweir     }
3102cdf0e10cSrcweir }
3103cdf0e10cSrcweir 
3104cdf0e10cSrcweir void __EXPORT ScGridWindow::KeyInput(const KeyEvent& rKEvt)
3105cdf0e10cSrcweir {
3106cdf0e10cSrcweir     // #96965# Cursor control for ref input dialog
3107cdf0e10cSrcweir     if( SC_MOD()->IsRefDialogOpen() )
3108cdf0e10cSrcweir     {
3109cdf0e10cSrcweir         const KeyCode& rKeyCode = rKEvt.GetKeyCode();
3110cdf0e10cSrcweir         if( !rKeyCode.GetModifier() && (rKeyCode.GetCode() == KEY_F2) )
3111cdf0e10cSrcweir         {
3112cdf0e10cSrcweir             SC_MOD()->EndReference();
3113*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
3114*0deba7fbSSteve Yin             //return;
3115*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
3116cdf0e10cSrcweir         }
3117cdf0e10cSrcweir         else if( pViewData->GetViewShell()->MoveCursorKeyInput( rKEvt ) )
3118cdf0e10cSrcweir         {
3119cdf0e10cSrcweir             ScRange aRef(
3120cdf0e10cSrcweir                 pViewData->GetRefStartX(), pViewData->GetRefStartY(), pViewData->GetRefStartZ(),
3121cdf0e10cSrcweir                 pViewData->GetRefEndX(), pViewData->GetRefEndY(), pViewData->GetRefEndZ() );
3122cdf0e10cSrcweir             SC_MOD()->SetReference( aRef, pViewData->GetDocument() );
3123*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
3124*0deba7fbSSteve Yin             //return;
3125*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
3126cdf0e10cSrcweir         }
3127*0deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
3128*0deba7fbSSteve Yin 		pViewData->GetViewShell()->SelectionChanged();
3129*0deba7fbSSteve Yin 		return ;
3130*0deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
3131cdf0e10cSrcweir     }
3132cdf0e10cSrcweir 	// wenn semi-Modeless-SfxChildWindow-Dialog oben, keine KeyInputs:
3133cdf0e10cSrcweir     else if( !pViewData->IsAnyFillMode() )
3134cdf0e10cSrcweir 	{
3135cdf0e10cSrcweir 		//	query for existing note marker before calling ViewShell's keyboard handling
3136cdf0e10cSrcweir 		//	which may remove the marker
3137cdf0e10cSrcweir 		sal_Bool bHadKeyMarker = ( pNoteMarker && pNoteMarker->IsByKeyboard() );
3138cdf0e10cSrcweir 		ScTabViewShell* pViewSh = pViewData->GetViewShell();
3139cdf0e10cSrcweir 
3140cdf0e10cSrcweir 		if (pViewData->GetDocShell()->GetProgress())
3141cdf0e10cSrcweir 			return;
3142cdf0e10cSrcweir 
3143cdf0e10cSrcweir         if (DrawKeyInput(rKEvt))
3144ee093554SAndre Fischer         {
3145ee093554SAndre Fischer             const KeyCode& rKeyCode = rKEvt.GetKeyCode();
3146ee093554SAndre Fischer             if (rKeyCode.GetCode() == KEY_DOWN
3147ee093554SAndre Fischer                 || rKeyCode.GetCode() == KEY_UP
3148ee093554SAndre Fischer                 || rKeyCode.GetCode() == KEY_LEFT
3149ee093554SAndre Fischer                 || rKeyCode.GetCode() == KEY_RIGHT)
3150ee093554SAndre Fischer             {
3151ee093554SAndre Fischer                 ScTabViewShell* pViewShell = pViewData->GetViewShell();
3152ee093554SAndre Fischer                 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
3153ee093554SAndre Fischer                 rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_X);
3154ee093554SAndre Fischer                 rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_Y);
3155ee093554SAndre Fischer  			}
3156cdf0e10cSrcweir 			return;
3157ee093554SAndre Fischer         }
3158cdf0e10cSrcweir 
3159cdf0e10cSrcweir 		if (!pViewData->GetView()->IsDrawSelMode() && !DrawHasMarkedObj())	//	keine Eingaben im Zeichenmodus
3160cdf0e10cSrcweir 		{															//! DrawShell abfragen !!!
3161cdf0e10cSrcweir 			if (pViewSh->TabKeyInput(rKEvt))
3162cdf0e10cSrcweir 				return;
3163cdf0e10cSrcweir 		}
3164cdf0e10cSrcweir 		else
3165cdf0e10cSrcweir 			if (pViewSh->SfxViewShell::KeyInput(rKEvt))				// von SfxViewShell
3166cdf0e10cSrcweir 				return;
3167cdf0e10cSrcweir 
3168cdf0e10cSrcweir 		KeyCode aCode = rKEvt.GetKeyCode();
3169cdf0e10cSrcweir 		if ( aCode.GetCode() == KEY_ESCAPE && aCode.GetModifier() == 0 )
3170cdf0e10cSrcweir 		{
3171cdf0e10cSrcweir 			if ( bHadKeyMarker )
3172cdf0e10cSrcweir 				HideNoteMarker();
3173cdf0e10cSrcweir             else
3174cdf0e10cSrcweir                 pViewSh->Escape();
3175cdf0e10cSrcweir 			return;
3176cdf0e10cSrcweir 		}
3177cdf0e10cSrcweir 		if ( aCode.GetCode() == KEY_F1 && aCode.GetModifier() == KEY_MOD1 )
3178cdf0e10cSrcweir 		{
3179cdf0e10cSrcweir 			//	ctrl-F1 shows or hides the note or redlining info for the cursor position
3180cdf0e10cSrcweir 			//	(hard-coded because F1 can't be configured)
3181cdf0e10cSrcweir 
3182cdf0e10cSrcweir 			if ( bHadKeyMarker )
3183cdf0e10cSrcweir 				HideNoteMarker();		// hide when previously visible
3184cdf0e10cSrcweir 			else
3185cdf0e10cSrcweir 				ShowNoteMarker( pViewData->GetCurX(), pViewData->GetCurY(), sal_True );
3186cdf0e10cSrcweir 			return;
3187cdf0e10cSrcweir 		}
3188cdf0e10cSrcweir 	}
3189cdf0e10cSrcweir 
3190cdf0e10cSrcweir 	Window::KeyInput(rKEvt);
3191cdf0e10cSrcweir }
3192cdf0e10cSrcweir 
3193cdf0e10cSrcweir void ScGridWindow::StopMarking()
3194cdf0e10cSrcweir {
3195cdf0e10cSrcweir 	DrawEndAction();				// Markieren/Verschieben auf Drawing-Layer abbrechen
3196cdf0e10cSrcweir 
3197cdf0e10cSrcweir 	if (nButtonDown)
3198cdf0e10cSrcweir 	{
3199cdf0e10cSrcweir 		pViewData->GetMarkData().SetMarking(sal_False);
3200cdf0e10cSrcweir 		nMouseStatus = SC_GM_IGNORE;
3201cdf0e10cSrcweir 	}
3202cdf0e10cSrcweir }
3203cdf0e10cSrcweir 
3204cdf0e10cSrcweir void ScGridWindow::UpdateInputContext()
3205cdf0e10cSrcweir {
3206cdf0e10cSrcweir 	sal_Bool bReadOnly = pViewData->GetDocShell()->IsReadOnly();
3207cdf0e10cSrcweir 	sal_uLong nOptions = bReadOnly ? 0 : ( INPUTCONTEXT_TEXT | INPUTCONTEXT_EXTTEXTINPUT );
3208cdf0e10cSrcweir 
3209cdf0e10cSrcweir 	//	when font from InputContext is used,
3210cdf0e10cSrcweir 	//	it must be taken from the cursor position's cell attributes
3211cdf0e10cSrcweir 
3212cdf0e10cSrcweir 	InputContext aContext;
3213cdf0e10cSrcweir 	aContext.SetOptions( nOptions );
3214cdf0e10cSrcweir 	SetInputContext( aContext );
3215cdf0e10cSrcweir }
3216cdf0e10cSrcweir 
3217cdf0e10cSrcweir //--------------------------------------------------------
3218cdf0e10cSrcweir 
3219cdf0e10cSrcweir 								// sensitiver Bereich (Pixel)
3220cdf0e10cSrcweir #define SCROLL_SENSITIVE 20
3221cdf0e10cSrcweir 
3222cdf0e10cSrcweir sal_Bool ScGridWindow::DropScroll( const Point& rMousePos )
3223cdf0e10cSrcweir {
3224cdf0e10cSrcweir /*	doch auch auf nicht aktiven Views...
3225cdf0e10cSrcweir 	if ( !pViewData->IsActive() )
3226cdf0e10cSrcweir 		return sal_False;
3227cdf0e10cSrcweir */
3228cdf0e10cSrcweir 	SCsCOL nDx = 0;
3229cdf0e10cSrcweir 	SCsROW nDy = 0;
3230cdf0e10cSrcweir 	Size aSize = GetOutputSizePixel();
3231cdf0e10cSrcweir 
3232cdf0e10cSrcweir 	if (aSize.Width() > SCROLL_SENSITIVE * 3)
3233cdf0e10cSrcweir 	{
3234cdf0e10cSrcweir 		if ( rMousePos.X() < SCROLL_SENSITIVE && pViewData->GetPosX(WhichH(eWhich)) > 0 )
3235cdf0e10cSrcweir 			nDx = -1;
3236cdf0e10cSrcweir 		if ( rMousePos.X() >= aSize.Width() - SCROLL_SENSITIVE
3237cdf0e10cSrcweir 				&& pViewData->GetPosX(WhichH(eWhich)) < MAXCOL )
3238cdf0e10cSrcweir 			nDx = 1;
3239cdf0e10cSrcweir 	}
3240cdf0e10cSrcweir 	if (aSize.Height() > SCROLL_SENSITIVE * 3)
3241cdf0e10cSrcweir 	{
3242cdf0e10cSrcweir 		if ( rMousePos.Y() < SCROLL_SENSITIVE && pViewData->GetPosY(WhichV(eWhich)) > 0 )
3243cdf0e10cSrcweir 			nDy = -1;
3244cdf0e10cSrcweir 		if ( rMousePos.Y() >= aSize.Height() - SCROLL_SENSITIVE
3245cdf0e10cSrcweir 				&& pViewData->GetPosY(WhichV(eWhich)) < MAXROW )
3246cdf0e10cSrcweir 			nDy = 1;
3247cdf0e10cSrcweir 	}
3248cdf0e10cSrcweir 
3249cdf0e10cSrcweir 	if ( nDx != 0 || nDy != 0 )
3250cdf0e10cSrcweir 	{
3251cdf0e10cSrcweir //		if (bDragRect)
3252cdf0e10cSrcweir //			pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3253cdf0e10cSrcweir 
3254cdf0e10cSrcweir 		if ( nDx != 0 )
3255cdf0e10cSrcweir 			pViewData->GetView()->ScrollX( nDx, WhichH(eWhich) );
3256cdf0e10cSrcweir 		if ( nDy != 0 )
3257cdf0e10cSrcweir 			pViewData->GetView()->ScrollY( nDy, WhichV(eWhich) );
3258cdf0e10cSrcweir 
3259cdf0e10cSrcweir //		if (bDragRect)
3260cdf0e10cSrcweir //			pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3261cdf0e10cSrcweir 	}
3262cdf0e10cSrcweir 
3263cdf0e10cSrcweir 	return sal_False;
3264cdf0e10cSrcweir }
3265cdf0e10cSrcweir 
3266cdf0e10cSrcweir sal_Bool lcl_TestScenarioRedliningDrop( ScDocument* pDoc, const ScRange& aDragRange)
3267cdf0e10cSrcweir {
3268cdf0e10cSrcweir 	//	Testet, ob bei eingeschalteten RedLining,
3269cdf0e10cSrcweir 	//  bei einem Drop ein Scenario betroffen ist.
3270cdf0e10cSrcweir 
3271cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
3272cdf0e10cSrcweir 	SCTAB nTab = aDragRange.aStart.Tab();
3273cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
3274cdf0e10cSrcweir 
3275cdf0e10cSrcweir 	if(pDoc->GetChangeTrack()!=NULL)
3276cdf0e10cSrcweir 	{
3277cdf0e10cSrcweir 		if( pDoc->IsScenario(nTab) && pDoc->HasScenarioRange(nTab, aDragRange))
3278cdf0e10cSrcweir 		{
3279cdf0e10cSrcweir 			bReturn = sal_True;
3280cdf0e10cSrcweir 		}
3281cdf0e10cSrcweir 		else
3282cdf0e10cSrcweir 		{
3283cdf0e10cSrcweir 			for(SCTAB i=nTab+1; i<nTabCount && pDoc->IsScenario(i); i++)
3284cdf0e10cSrcweir 			{
3285cdf0e10cSrcweir 				if(pDoc->HasScenarioRange(i, aDragRange))
3286cdf0e10cSrcweir 				{
3287cdf0e10cSrcweir 					bReturn = sal_True;
3288cdf0e10cSrcweir 					break;
3289cdf0e10cSrcweir 				}
3290cdf0e10cSrcweir 			}
3291cdf0e10cSrcweir 		}
3292cdf0e10cSrcweir 	}
3293cdf0e10cSrcweir 	return bReturn;
3294cdf0e10cSrcweir }
3295cdf0e10cSrcweir 
3296cdf0e10cSrcweir ScRange lcl_MakeDropRange( SCCOL nPosX, SCROW nPosY, SCTAB nTab, const ScRange& rSource )
3297cdf0e10cSrcweir {
3298cdf0e10cSrcweir 	SCCOL nCol1 = nPosX;
3299cdf0e10cSrcweir 	SCCOL nCol2 = nCol1 + ( rSource.aEnd.Col() - rSource.aStart.Col() );
3300cdf0e10cSrcweir 	if ( nCol2 > MAXCOL )
3301cdf0e10cSrcweir 	{
3302cdf0e10cSrcweir 		nCol1 -= nCol2 - MAXCOL;
3303cdf0e10cSrcweir 		nCol2 = MAXCOL;
3304cdf0e10cSrcweir 	}
3305cdf0e10cSrcweir 	SCROW nRow1 = nPosY;
3306cdf0e10cSrcweir 	SCROW nRow2 = nRow1 + ( rSource.aEnd.Row() - rSource.aStart.Row() );
3307cdf0e10cSrcweir 	if ( nRow2 > MAXROW )
3308cdf0e10cSrcweir 	{
3309cdf0e10cSrcweir 		nRow1 -= nRow2 - MAXROW;
3310cdf0e10cSrcweir 		nRow2 = MAXROW;
3311cdf0e10cSrcweir 	}
3312cdf0e10cSrcweir 
3313cdf0e10cSrcweir 	return ScRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
3314cdf0e10cSrcweir }
3315cdf0e10cSrcweir 
3316cdf0e10cSrcweir //--------------------------------------------------------
3317cdf0e10cSrcweir 
3318cdf0e10cSrcweir extern sal_Bool bPasteIsDrop;		// viewfun4 -> move to header
3319cdf0e10cSrcweir extern sal_Bool bPasteIsMove;		// viewfun7 -> move to header
3320cdf0e10cSrcweir 
3321cdf0e10cSrcweir //--------------------------------------------------------
3322cdf0e10cSrcweir 
3323cdf0e10cSrcweir sal_Int8 ScGridWindow::AcceptPrivateDrop( const AcceptDropEvent& rEvt )
3324cdf0e10cSrcweir {
3325cdf0e10cSrcweir 	if ( rEvt.mbLeaving )
3326cdf0e10cSrcweir 	{
3327cdf0e10cSrcweir 		// if (bDragRect)
3328cdf0e10cSrcweir 		//	pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3329cdf0e10cSrcweir 		bDragRect = sal_False;
3330cdf0e10cSrcweir 		UpdateDragRectOverlay();
3331cdf0e10cSrcweir 		return rEvt.mnAction;
3332cdf0e10cSrcweir 	}
3333cdf0e10cSrcweir 
3334cdf0e10cSrcweir 	const ScDragData& rData = SC_MOD()->GetDragData();
3335cdf0e10cSrcweir 	if ( rData.pCellTransfer )
3336cdf0e10cSrcweir 	{
3337cdf0e10cSrcweir         // Don't move source that would include filtered rows.
3338cdf0e10cSrcweir         if ((rEvt.mnAction & DND_ACTION_MOVE) && rData.pCellTransfer->HasFilteredRows())
3339cdf0e10cSrcweir         {
3340cdf0e10cSrcweir             if (bDragRect)
3341cdf0e10cSrcweir             {
3342cdf0e10cSrcweir                 bDragRect = sal_False;
3343cdf0e10cSrcweir                 UpdateDragRectOverlay();
3344cdf0e10cSrcweir             }
3345cdf0e10cSrcweir             return DND_ACTION_NONE;
3346cdf0e10cSrcweir         }
3347cdf0e10cSrcweir 
3348cdf0e10cSrcweir 		Point aPos = rEvt.maPosPixel;
3349cdf0e10cSrcweir 
3350cdf0e10cSrcweir 		ScDocument* pSourceDoc = rData.pCellTransfer->GetSourceDocument();
3351cdf0e10cSrcweir 		ScDocument* pThisDoc   = pViewData->GetDocument();
3352cdf0e10cSrcweir 		if (pSourceDoc == pThisDoc)
3353cdf0e10cSrcweir 		{
3354cdf0e10cSrcweir 			if ( pThisDoc->HasChartAtPoint(pViewData->GetTabNo(), PixelToLogic(aPos)) )
3355cdf0e10cSrcweir 			{
3356cdf0e10cSrcweir 				if (bDragRect)			// Rechteck loeschen
3357cdf0e10cSrcweir 				{
3358cdf0e10cSrcweir 					// pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3359cdf0e10cSrcweir 					bDragRect = sal_False;
3360cdf0e10cSrcweir 					UpdateDragRectOverlay();
3361cdf0e10cSrcweir 				}
3362cdf0e10cSrcweir 
3363cdf0e10cSrcweir 				//!	highlight chart? (selection border?)
3364cdf0e10cSrcweir 
3365cdf0e10cSrcweir 				sal_Int8 nRet = rEvt.mnAction;
3366cdf0e10cSrcweir //!				if ( rEvt.GetAction() == DROP_LINK )
3367cdf0e10cSrcweir //!					bOk = rEvt.SetAction( DROP_COPY );			// can't link onto chart
3368cdf0e10cSrcweir 				return nRet;
3369cdf0e10cSrcweir 			}
3370cdf0e10cSrcweir 		}
3371cdf0e10cSrcweir //!		else
3372cdf0e10cSrcweir //!			if ( rEvt.GetAction() == DROP_MOVE )
3373cdf0e10cSrcweir //!				rEvt.SetAction( DROP_COPY );					// different doc: default=COPY
3374cdf0e10cSrcweir 
3375cdf0e10cSrcweir 
3376cdf0e10cSrcweir 		if ( rData.pCellTransfer->GetDragSourceFlags() & SC_DROP_TABLE )		// whole sheet?
3377cdf0e10cSrcweir 		{
3378cdf0e10cSrcweir 			sal_Bool bOk = pThisDoc->IsDocEditable();
3379cdf0e10cSrcweir 			return bOk ? rEvt.mnAction : 0;						// don't draw selection frame
3380cdf0e10cSrcweir 		}
3381cdf0e10cSrcweir 
3382cdf0e10cSrcweir 		SCsCOL	nPosX;
3383cdf0e10cSrcweir 		SCsROW	nPosY;
3384cdf0e10cSrcweir 		pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
3385cdf0e10cSrcweir 
3386cdf0e10cSrcweir 		ScRange aSourceRange = rData.pCellTransfer->GetRange();
3387cdf0e10cSrcweir         SCCOL nSourceStartX = aSourceRange.aStart.Col();
3388cdf0e10cSrcweir         SCROW nSourceStartY = aSourceRange.aStart.Row();
3389cdf0e10cSrcweir         SCCOL nSourceEndX = aSourceRange.aEnd.Col();
3390cdf0e10cSrcweir         SCROW nSourceEndY = aSourceRange.aEnd.Row();
3391cdf0e10cSrcweir         SCCOL nSizeX = nSourceEndX - nSourceStartX + 1;
3392cdf0e10cSrcweir         SCROW nSizeY = nSourceEndY - nSourceStartY + 1;
3393cdf0e10cSrcweir 
3394cdf0e10cSrcweir 		if ( rEvt.mnAction != DND_ACTION_MOVE )
3395cdf0e10cSrcweir 			nSizeY = rData.pCellTransfer->GetNonFilteredRows();		// copy/link: no filtered rows
3396cdf0e10cSrcweir 
3397cdf0e10cSrcweir 		SCsCOL nNewDragX = nPosX - rData.pCellTransfer->GetDragHandleX();
3398cdf0e10cSrcweir 		if (nNewDragX<0) nNewDragX=0;
3399cdf0e10cSrcweir 		if (nNewDragX+(nSizeX-1) > MAXCOL)
3400cdf0e10cSrcweir 			nNewDragX = MAXCOL-(nSizeX-1);
3401cdf0e10cSrcweir 		SCsROW nNewDragY = nPosY - rData.pCellTransfer->GetDragHandleY();
3402cdf0e10cSrcweir 		if (nNewDragY<0) nNewDragY=0;
3403cdf0e10cSrcweir 		if (nNewDragY+(nSizeY-1) > MAXROW)
3404cdf0e10cSrcweir 			nNewDragY = MAXROW-(nSizeY-1);
3405cdf0e10cSrcweir 
3406cdf0e10cSrcweir 		//	don't break scenario ranges, don't drop on filtered
3407cdf0e10cSrcweir 		SCTAB nTab = pViewData->GetTabNo();
3408cdf0e10cSrcweir 		ScRange aDropRange = lcl_MakeDropRange( nNewDragX, nNewDragY, nTab, aSourceRange );
3409cdf0e10cSrcweir 		if ( lcl_TestScenarioRedliningDrop( pThisDoc, aDropRange ) ||
3410cdf0e10cSrcweir 			 lcl_TestScenarioRedliningDrop( pSourceDoc, aSourceRange ) ||
3411cdf0e10cSrcweir              ScViewUtil::HasFiltered( aDropRange, pThisDoc) )
3412cdf0e10cSrcweir 		{
3413cdf0e10cSrcweir 			if (bDragRect)
3414cdf0e10cSrcweir 			{
3415cdf0e10cSrcweir 				// pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3416cdf0e10cSrcweir 				bDragRect = sal_False;
3417cdf0e10cSrcweir                 UpdateDragRectOverlay();
3418cdf0e10cSrcweir 			}
3419cdf0e10cSrcweir 			return DND_ACTION_NONE;
3420cdf0e10cSrcweir 		}
3421cdf0e10cSrcweir 
3422cdf0e10cSrcweir         InsCellCmd eDragInsertMode = INS_NONE;
3423cdf0e10cSrcweir         Window::PointerState aState = GetPointerState();
3424cdf0e10cSrcweir 
3425cdf0e10cSrcweir         // check for datapilot item sorting
3426cdf0e10cSrcweir         ScDPObject* pDPObj = NULL;
3427cdf0e10cSrcweir         if ( pThisDoc == pSourceDoc && ( pDPObj = pThisDoc->GetDPAtCursor( nNewDragX, nNewDragY, nTab ) ) != NULL )
3428cdf0e10cSrcweir         {
3429cdf0e10cSrcweir             // drop on DataPilot table: sort or nothing
3430cdf0e10cSrcweir 
3431cdf0e10cSrcweir             bool bDPSort = false;
3432cdf0e10cSrcweir             if ( pThisDoc->GetDPAtCursor( nSourceStartX, nSourceStartY, aSourceRange.aStart.Tab() ) == pDPObj )
3433cdf0e10cSrcweir             {
3434cdf0e10cSrcweir                 sheet::DataPilotTableHeaderData aDestData;
3435cdf0e10cSrcweir                 pDPObj->GetHeaderPositionData( ScAddress(nNewDragX, nNewDragY, nTab), aDestData );
3436cdf0e10cSrcweir                 bool bValid = ( aDestData.Dimension >= 0 );        // dropping onto a field
3437cdf0e10cSrcweir 
3438cdf0e10cSrcweir                 // look through the source range
3439cdf0e10cSrcweir                 for (SCROW nRow = aSourceRange.aStart.Row(); bValid && nRow <= aSourceRange.aEnd.Row(); ++nRow )
3440cdf0e10cSrcweir                     for (SCCOL nCol = aSourceRange.aStart.Col(); bValid && nCol <= aSourceRange.aEnd.Col(); ++nCol )
3441cdf0e10cSrcweir                     {
3442cdf0e10cSrcweir                         sheet::DataPilotTableHeaderData aSourceData;
3443cdf0e10cSrcweir                         pDPObj->GetHeaderPositionData( ScAddress( nCol, nRow, aSourceRange.aStart.Tab() ), aSourceData );
3444cdf0e10cSrcweir                         if ( aSourceData.Dimension != aDestData.Dimension || !aSourceData.MemberName.getLength() )
3445cdf0e10cSrcweir                             bValid = false;     // empty (subtotal) or different field
3446cdf0e10cSrcweir                     }
3447cdf0e10cSrcweir 
3448cdf0e10cSrcweir                 if ( bValid )
3449cdf0e10cSrcweir                 {
3450cdf0e10cSrcweir                     sal_Bool bIsDataLayout;
3451cdf0e10cSrcweir                     String aDimName = pDPObj->GetDimName( aDestData.Dimension, bIsDataLayout );
3452cdf0e10cSrcweir                     const ScDPSaveDimension* pDim = pDPObj->GetSaveData()->GetExistingDimensionByName( aDimName );
3453cdf0e10cSrcweir                     if ( pDim )
3454cdf0e10cSrcweir                     {
3455cdf0e10cSrcweir                         ScRange aOutRange = pDPObj->GetOutRange();
3456cdf0e10cSrcweir 
3457cdf0e10cSrcweir                         sal_uInt16 nOrient = pDim->GetOrientation();
3458cdf0e10cSrcweir                         if ( nOrient == sheet::DataPilotFieldOrientation_COLUMN )
3459cdf0e10cSrcweir                         {
3460cdf0e10cSrcweir                             eDragInsertMode = INS_CELLSRIGHT;
3461cdf0e10cSrcweir                             nSizeY = aOutRange.aEnd.Row() - nNewDragY + 1;
3462cdf0e10cSrcweir                             bDPSort = true;
3463cdf0e10cSrcweir                         }
3464cdf0e10cSrcweir                         else if ( nOrient == sheet::DataPilotFieldOrientation_ROW )
3465cdf0e10cSrcweir                         {
3466cdf0e10cSrcweir                             eDragInsertMode = INS_CELLSDOWN;
3467cdf0e10cSrcweir                             nSizeX = aOutRange.aEnd.Col() - nNewDragX + 1;
3468cdf0e10cSrcweir                             bDPSort = true;
3469cdf0e10cSrcweir                         }
3470cdf0e10cSrcweir                     }
3471cdf0e10cSrcweir                 }
3472cdf0e10cSrcweir             }
3473cdf0e10cSrcweir 
3474cdf0e10cSrcweir             if ( !bDPSort )
3475cdf0e10cSrcweir             {
3476cdf0e10cSrcweir                 // no valid sorting in a DataPilot table -> disallow
3477cdf0e10cSrcweir                 if ( bDragRect )
3478cdf0e10cSrcweir                 {
3479cdf0e10cSrcweir                     bDragRect = sal_False;
3480cdf0e10cSrcweir                     UpdateDragRectOverlay();
3481cdf0e10cSrcweir                 }
3482cdf0e10cSrcweir                 return DND_ACTION_NONE;
3483cdf0e10cSrcweir             }
3484cdf0e10cSrcweir         }
3485cdf0e10cSrcweir         else if ( aState.mnState & KEY_MOD2 )
3486cdf0e10cSrcweir         {
3487cdf0e10cSrcweir             if ( pThisDoc == pSourceDoc && nTab == aSourceRange.aStart.Tab() )
3488cdf0e10cSrcweir             {
3489cdf0e10cSrcweir                 long nDeltaX = labs( static_cast< long >( nNewDragX - nSourceStartX ) );
3490cdf0e10cSrcweir                 long nDeltaY = labs( static_cast< long >( nNewDragY - nSourceStartY ) );
3491cdf0e10cSrcweir                 if ( nDeltaX <= nDeltaY )
3492cdf0e10cSrcweir                 {
3493cdf0e10cSrcweir                     eDragInsertMode = INS_CELLSDOWN;
3494cdf0e10cSrcweir                 }
3495cdf0e10cSrcweir                 else
3496cdf0e10cSrcweir                 {
3497cdf0e10cSrcweir                     eDragInsertMode = INS_CELLSRIGHT;
3498cdf0e10cSrcweir                 }
3499cdf0e10cSrcweir 
3500cdf0e10cSrcweir                 if ( ( eDragInsertMode == INS_CELLSDOWN && nNewDragY <= nSourceEndY &&
3501cdf0e10cSrcweir                        ( nNewDragX + nSizeX - 1 ) >= nSourceStartX && nNewDragX <= nSourceEndX &&
3502cdf0e10cSrcweir                        ( nNewDragX != nSourceStartX || nNewDragY >= nSourceStartY ) ) ||
3503cdf0e10cSrcweir                      ( eDragInsertMode == INS_CELLSRIGHT && nNewDragX <= nSourceEndX &&
3504cdf0e10cSrcweir                        ( nNewDragY + nSizeY - 1 ) >= nSourceStartY && nNewDragY <= nSourceEndY &&
3505cdf0e10cSrcweir                        ( nNewDragY != nSourceStartY || nNewDragX >= nSourceStartX ) ) )
3506cdf0e10cSrcweir                 {
3507cdf0e10cSrcweir                     if ( bDragRect )
3508cdf0e10cSrcweir                     {
3509cdf0e10cSrcweir                         bDragRect = sal_False;
3510cdf0e10cSrcweir                         UpdateDragRectOverlay();
3511cdf0e10cSrcweir                     }
3512cdf0e10cSrcweir                     return DND_ACTION_NONE;
3513cdf0e10cSrcweir                 }
3514cdf0e10cSrcweir             }
3515cdf0e10cSrcweir             else
3516cdf0e10cSrcweir             {
3517cdf0e10cSrcweir                 if ( static_cast< long >( nSizeX ) >= static_cast< long >( nSizeY ) )
3518cdf0e10cSrcweir                 {
3519cdf0e10cSrcweir                     eDragInsertMode = INS_CELLSDOWN;
3520cdf0e10cSrcweir 
3521cdf0e10cSrcweir                 }
3522cdf0e10cSrcweir                 else
3523cdf0e10cSrcweir                 {
3524cdf0e10cSrcweir                     eDragInsertMode = INS_CELLSRIGHT;
3525cdf0e10cSrcweir                 }
3526cdf0e10cSrcweir             }
3527cdf0e10cSrcweir         }
3528cdf0e10cSrcweir 
3529cdf0e10cSrcweir 		if ( nNewDragX != (SCsCOL) nDragStartX || nNewDragY != (SCsROW) nDragStartY ||
3530cdf0e10cSrcweir 			 nDragStartX+nSizeX-1 != nDragEndX || nDragStartY+nSizeY-1 != nDragEndY ||
3531cdf0e10cSrcweir 			 !bDragRect || eDragInsertMode != meDragInsertMode )
3532cdf0e10cSrcweir 		{
3533cdf0e10cSrcweir 			// if (bDragRect)
3534cdf0e10cSrcweir 			//	pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3535cdf0e10cSrcweir 
3536cdf0e10cSrcweir 			nDragStartX = nNewDragX;
3537cdf0e10cSrcweir 			nDragStartY = nNewDragY;
3538cdf0e10cSrcweir 			nDragEndX = nDragStartX+nSizeX-1;
3539cdf0e10cSrcweir 			nDragEndY = nDragStartY+nSizeY-1;
3540cdf0e10cSrcweir 			bDragRect = sal_True;
3541cdf0e10cSrcweir             meDragInsertMode = eDragInsertMode;
3542cdf0e10cSrcweir 
3543cdf0e10cSrcweir 			// pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3544cdf0e10cSrcweir 
3545cdf0e10cSrcweir             UpdateDragRectOverlay();
3546cdf0e10cSrcweir 
3547cdf0e10cSrcweir 			//	show target position as tip help
3548cdf0e10cSrcweir #if 0
3549cdf0e10cSrcweir 			if (Help::IsQuickHelpEnabled())
3550cdf0e10cSrcweir 			{
3551cdf0e10cSrcweir 				ScRange aRange( nDragStartX, nDragStartY, nTab, nDragEndX, nDragEndY, nTab );
3552cdf0e10cSrcweir 				String aHelpStr;
3553cdf0e10cSrcweir 				aRange.Format( aHelpStr, SCA_VALID );	// non-3D
3554cdf0e10cSrcweir 
3555cdf0e10cSrcweir 				Point aPos = Pointer::GetPosPixel();
3556cdf0e10cSrcweir 				sal_uInt16 nAlign = QUICKHELP_BOTTOM|QUICKHELP_RIGHT;
3557cdf0e10cSrcweir 				Rectangle aRect( aPos, aPos );
3558cdf0e10cSrcweir 				Help::ShowQuickHelp(aRect, aHelpStr, nAlign);
3559cdf0e10cSrcweir 			}
3560cdf0e10cSrcweir #endif
3561cdf0e10cSrcweir 		}
3562cdf0e10cSrcweir 	}
3563cdf0e10cSrcweir 
3564cdf0e10cSrcweir 	return rEvt.mnAction;
3565cdf0e10cSrcweir }
3566cdf0e10cSrcweir 
3567cdf0e10cSrcweir sal_Int8 ScGridWindow::AcceptDrop( const AcceptDropEvent& rEvt )
3568cdf0e10cSrcweir {
3569cdf0e10cSrcweir 	const ScDragData& rData = SC_MOD()->GetDragData();
3570cdf0e10cSrcweir 	if ( rEvt.mbLeaving )
3571cdf0e10cSrcweir 	{
3572cdf0e10cSrcweir 		DrawMarkDropObj( NULL );
3573cdf0e10cSrcweir 		if ( rData.pCellTransfer )
3574cdf0e10cSrcweir 			return AcceptPrivateDrop( rEvt );	// hide drop marker for internal D&D
3575cdf0e10cSrcweir 		else
3576cdf0e10cSrcweir 			return rEvt.mnAction;
3577cdf0e10cSrcweir 	}
3578cdf0e10cSrcweir 
3579cdf0e10cSrcweir 	if ( pViewData->GetDocShell()->IsReadOnly() )
3580cdf0e10cSrcweir 		return DND_ACTION_NONE;
3581cdf0e10cSrcweir 
3582cdf0e10cSrcweir 
3583cdf0e10cSrcweir 	sal_Int8 nRet = DND_ACTION_NONE;
3584cdf0e10cSrcweir 
3585cdf0e10cSrcweir 	if (rData.pCellTransfer)
3586cdf0e10cSrcweir 	{
3587cdf0e10cSrcweir 		ScRange aSource = rData.pCellTransfer->GetRange();
3588cdf0e10cSrcweir 		if ( aSource.aStart.Col() != 0 || aSource.aEnd.Col() != MAXCOL ||
3589cdf0e10cSrcweir 			 aSource.aStart.Row() != 0 || aSource.aEnd.Row() != MAXROW )
3590cdf0e10cSrcweir 			DropScroll( rEvt.maPosPixel );
3591cdf0e10cSrcweir 
3592cdf0e10cSrcweir 		nRet = AcceptPrivateDrop( rEvt );
3593cdf0e10cSrcweir 	}
3594cdf0e10cSrcweir 	else
3595cdf0e10cSrcweir 	{
3596cdf0e10cSrcweir 		if ( rData.aLinkDoc.Len() )
3597cdf0e10cSrcweir 		{
3598cdf0e10cSrcweir 			String aThisName;
3599cdf0e10cSrcweir 			ScDocShell* pDocSh = pViewData->GetDocShell();
3600cdf0e10cSrcweir 			if (pDocSh && pDocSh->HasName())
3601cdf0e10cSrcweir 				aThisName = pDocSh->GetMedium()->GetName();
3602cdf0e10cSrcweir 
3603cdf0e10cSrcweir 			if ( rData.aLinkDoc != aThisName )
3604cdf0e10cSrcweir 				nRet = rEvt.mnAction;
3605cdf0e10cSrcweir 		}
3606cdf0e10cSrcweir 		else if (rData.aJumpTarget.Len())
3607cdf0e10cSrcweir 		{
3608cdf0e10cSrcweir 			//	internal bookmarks (from Navigator)
3609cdf0e10cSrcweir 			//	local jumps from an unnamed document are possible only within a document
3610cdf0e10cSrcweir 
3611cdf0e10cSrcweir 			if ( !rData.pJumpLocalDoc || rData.pJumpLocalDoc == pViewData->GetDocument() )
3612cdf0e10cSrcweir 				nRet = rEvt.mnAction;
3613cdf0e10cSrcweir 		}
3614cdf0e10cSrcweir 		else
3615cdf0e10cSrcweir 		{
3616cdf0e10cSrcweir 			sal_Int8 nMyAction = rEvt.mnAction;
3617cdf0e10cSrcweir 
36183cc56398SArmin Le Grand 			// clear DND_ACTION_LINK when other actions are set. The usage below cannot handle
36193cc56398SArmin Le Grand 			// multiple set values
36203cc56398SArmin Le Grand 			if((nMyAction & DND_ACTION_LINK) && (nMyAction & (DND_ACTION_COPYMOVE)))
36213cc56398SArmin Le Grand 			{
36223cc56398SArmin Le Grand 			    nMyAction &= ~DND_ACTION_LINK;
36233cc56398SArmin Le Grand 			}
36243cc56398SArmin Le Grand 
3625cdf0e10cSrcweir 			if ( !rData.pDrawTransfer ||
3626cdf0e10cSrcweir 					!IsMyModel(rData.pDrawTransfer->GetDragSourceView()) )		// drawing within the document
3627cdf0e10cSrcweir 				if ( rEvt.mbDefault && nMyAction == DND_ACTION_MOVE )
3628cdf0e10cSrcweir 					nMyAction = DND_ACTION_COPY;
3629cdf0e10cSrcweir 
3630cdf0e10cSrcweir 			ScDocument* pThisDoc = pViewData->GetDocument();
3631cdf0e10cSrcweir 			SdrObject* pHitObj = pThisDoc->GetObjectAtPoint(
3632cdf0e10cSrcweir 						pViewData->GetTabNo(), PixelToLogic(rEvt.maPosPixel) );
36333cc56398SArmin Le Grand 			if ( pHitObj && nMyAction == DND_ACTION_LINK ) // && !rData.pDrawTransfer )
3634cdf0e10cSrcweir 			{
3635cdf0e10cSrcweir 				if ( IsDropFormatSupported(SOT_FORMATSTR_ID_SVXB)
3636cdf0e10cSrcweir 					|| IsDropFormatSupported(SOT_FORMAT_GDIMETAFILE)
3637cdf0e10cSrcweir 					|| IsDropFormatSupported(SOT_FORMAT_BITMAP) )
3638cdf0e10cSrcweir 				{
3639cdf0e10cSrcweir 					//	graphic dragged onto drawing object
3640cdf0e10cSrcweir 					DrawMarkDropObj( pHitObj );
3641cdf0e10cSrcweir 					nRet = nMyAction;
3642cdf0e10cSrcweir 				}
3643cdf0e10cSrcweir 			}
3644cdf0e10cSrcweir 			if (!nRet)
3645cdf0e10cSrcweir 				DrawMarkDropObj( NULL );
3646cdf0e10cSrcweir 
3647cdf0e10cSrcweir 			if (!nRet)
3648cdf0e10cSrcweir 			{
3649cdf0e10cSrcweir 				switch ( nMyAction )
3650cdf0e10cSrcweir 				{
3651cdf0e10cSrcweir 					case DND_ACTION_COPY:
3652cdf0e10cSrcweir 					case DND_ACTION_MOVE:
3653cdf0e10cSrcweir 					case DND_ACTION_COPYMOVE:
3654cdf0e10cSrcweir 						{
3655cdf0e10cSrcweir 							sal_Bool bMove = ( nMyAction == DND_ACTION_MOVE );
3656cdf0e10cSrcweir 							if ( IsDropFormatSupported( SOT_FORMATSTR_ID_EMBED_SOURCE ) ||
3657cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_LINK_SOURCE ) ||
3658cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) ||
3659cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ) ||
3660cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) ||
3661cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMAT_STRING ) ||
3662cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_SYLK ) ||
3663cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_LINK ) ||
3664cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_HTML ) ||
3665cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_HTML_SIMPLE ) ||
3666cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_DIF ) ||
3667cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_DRAWING ) ||
3668cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_SVXB ) ||
3669cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMAT_RTF ) ||
3670cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMAT_GDIMETAFILE ) ||
3671cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMAT_BITMAP ) ||
3672cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_SBA_DATAEXCHANGE ) ||
3673cdf0e10cSrcweir 								 IsDropFormatSupported( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE ) ||
3674cdf0e10cSrcweir 								 ( !bMove && (
3675cdf0e10cSrcweir                                     IsDropFormatSupported( SOT_FORMAT_FILE_LIST ) ||
3676cdf0e10cSrcweir 								 	IsDropFormatSupported( SOT_FORMAT_FILE ) ||
3677cdf0e10cSrcweir 								 	IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
3678cdf0e10cSrcweir 								 	IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
3679cdf0e10cSrcweir 								 	IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) ||
3680cdf0e10cSrcweir 								 	IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ) ) )
3681cdf0e10cSrcweir 							{
3682cdf0e10cSrcweir 								nRet = nMyAction;
3683cdf0e10cSrcweir 							}
3684cdf0e10cSrcweir 						}
3685cdf0e10cSrcweir 						break;
3686cdf0e10cSrcweir 					case DND_ACTION_LINK:
3687cdf0e10cSrcweir 						if ( IsDropFormatSupported( SOT_FORMATSTR_ID_LINK_SOURCE ) ||
3688cdf0e10cSrcweir 							 IsDropFormatSupported( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ) ||
3689cdf0e10cSrcweir 							 IsDropFormatSupported( SOT_FORMATSTR_ID_LINK ) ||
3690cdf0e10cSrcweir                              IsDropFormatSupported( SOT_FORMAT_FILE_LIST ) ||
3691cdf0e10cSrcweir 							 IsDropFormatSupported( SOT_FORMAT_FILE ) ||
3692cdf0e10cSrcweir 							 IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
3693cdf0e10cSrcweir 							 IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
3694cdf0e10cSrcweir 							 IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) ||
3695cdf0e10cSrcweir 							 IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) )
3696cdf0e10cSrcweir 						{
3697cdf0e10cSrcweir 							nRet = nMyAction;
3698cdf0e10cSrcweir 						}
3699cdf0e10cSrcweir 						break;
3700cdf0e10cSrcweir 				}
3701cdf0e10cSrcweir 
3702cdf0e10cSrcweir                 if ( nRet )
3703cdf0e10cSrcweir                 {
3704cdf0e10cSrcweir                     // Simple check for protection: It's not known here if the drop will result
3705cdf0e10cSrcweir                     // in cells or drawing objects (some formats can be both) and how many cells
3706cdf0e10cSrcweir                     // the result will be. But if IsFormatEditable for the drop cell position
3707cdf0e10cSrcweir                     // is sal_False (ignores matrix formulas), nothing can be pasted, so the drop
3708cdf0e10cSrcweir                     // can already be rejected here.
3709cdf0e10cSrcweir 
3710cdf0e10cSrcweir                     Point aPos = rEvt.maPosPixel;
3711cdf0e10cSrcweir                     SCsCOL nPosX;
3712cdf0e10cSrcweir                     SCsROW nPosY;
3713cdf0e10cSrcweir                     pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
3714cdf0e10cSrcweir                     SCTAB nTab = pViewData->GetTabNo();
3715cdf0e10cSrcweir                     ScDocument* pDoc = pViewData->GetDocument();
3716cdf0e10cSrcweir 
3717cdf0e10cSrcweir                     ScEditableTester aTester( pDoc, nTab, nPosX,nPosY, nPosX,nPosY );
3718cdf0e10cSrcweir                     if ( !aTester.IsFormatEditable() )
3719cdf0e10cSrcweir                         nRet = DND_ACTION_NONE;             // forbidden
3720cdf0e10cSrcweir                 }
3721cdf0e10cSrcweir 			}
3722cdf0e10cSrcweir 		}
3723cdf0e10cSrcweir 
3724cdf0e10cSrcweir 		//	scroll only for accepted formats
3725cdf0e10cSrcweir 		if (nRet)
3726cdf0e10cSrcweir 			DropScroll( rEvt.maPosPixel );
3727cdf0e10cSrcweir 	}
3728cdf0e10cSrcweir 
3729cdf0e10cSrcweir 	return nRet;
3730cdf0e10cSrcweir }
3731cdf0e10cSrcweir 
3732cdf0e10cSrcweir sal_uLong lcl_GetDropFormatId( const uno::Reference<datatransfer::XTransferable>& xTransfer, bool bPreferText = false )
3733cdf0e10cSrcweir {
3734cdf0e10cSrcweir 	TransferableDataHelper aDataHelper( xTransfer );
3735cdf0e10cSrcweir 
3736cdf0e10cSrcweir 	if ( !aDataHelper.HasFormat( SOT_FORMATSTR_ID_SBA_DATAEXCHANGE ) )
3737cdf0e10cSrcweir 	{
3738cdf0e10cSrcweir 		//	use bookmark formats if no sba is present
3739cdf0e10cSrcweir 
3740cdf0e10cSrcweir 		if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SOLK ) )
3741cdf0e10cSrcweir 			return SOT_FORMATSTR_ID_SOLK;
3742cdf0e10cSrcweir 		else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) )
3743cdf0e10cSrcweir 			return SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR;
3744cdf0e10cSrcweir 		else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) )
3745cdf0e10cSrcweir 			return SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK;
3746cdf0e10cSrcweir 		else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) )
3747cdf0e10cSrcweir 			return SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR;
3748cdf0e10cSrcweir 	}
3749cdf0e10cSrcweir 
3750cdf0e10cSrcweir 	sal_uLong nFormatId = 0;
3751cdf0e10cSrcweir 	if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
3752cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_DRAWING;
3753cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
3754cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_SVXB;
3755cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ) )
3756cdf0e10cSrcweir 	{
3757cdf0e10cSrcweir 		//	If it's a Writer object, insert RTF instead of OLE
3758cdf0e10cSrcweir 
3759cdf0e10cSrcweir 		sal_Bool bDoRtf = sal_False;
3760cdf0e10cSrcweir 		SotStorageStreamRef xStm;
3761cdf0e10cSrcweir 		TransferableObjectDescriptor aObjDesc;
3762cdf0e10cSrcweir 		if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) &&
3763cdf0e10cSrcweir 			aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_EMBED_SOURCE, xStm ) )
3764cdf0e10cSrcweir 		{
3765cdf0e10cSrcweir 			SotStorageRef xStore( new SotStorage( *xStm ) );
3766cdf0e10cSrcweir 			bDoRtf = ( ( aObjDesc.maClassName == SvGlobalName( SO3_SW_CLASSID ) ||
3767cdf0e10cSrcweir 						 aObjDesc.maClassName == SvGlobalName( SO3_SWWEB_CLASSID ) )
3768cdf0e10cSrcweir 					   && aDataHelper.HasFormat( SOT_FORMAT_RTF ) );
3769cdf0e10cSrcweir 		}
3770cdf0e10cSrcweir 		if ( bDoRtf )
3771cdf0e10cSrcweir 			nFormatId = FORMAT_RTF;
3772cdf0e10cSrcweir 		else
3773cdf0e10cSrcweir 			nFormatId = SOT_FORMATSTR_ID_EMBED_SOURCE;
3774cdf0e10cSrcweir 	}
3775cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ) )
3776cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE;
3777cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SBA_DATAEXCHANGE ) )
3778cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_SBA_DATAEXCHANGE;
3779cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE ) )
3780cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE;
3781cdf0e10cSrcweir     else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_BIFF_8 ) )
3782cdf0e10cSrcweir         nFormatId = SOT_FORMATSTR_ID_BIFF_8;
3783cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_BIFF_5 ) )
3784cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_BIFF_5;
3785cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) )
3786cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
3787cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) )
3788cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE;
3789cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ) )
3790cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE_OLE;
3791cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMAT_RTF ) )
3792cdf0e10cSrcweir 		nFormatId = SOT_FORMAT_RTF;
3793cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_HTML ) )
3794cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_HTML;
3795cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_HTML_SIMPLE ) )
3796cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_HTML_SIMPLE;
3797cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SYLK ) )
3798cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_SYLK;
3799cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK ) )
3800cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_LINK;
3801cdf0e10cSrcweir 	else if ( bPreferText && aDataHelper.HasFormat( SOT_FORMAT_STRING ) ) // #i86734# the behaviour introduced in #i62773# is wrong when pasting
3802cdf0e10cSrcweir 		nFormatId = SOT_FORMAT_STRING;
3803cdf0e10cSrcweir     else if ( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) )
3804cdf0e10cSrcweir         nFormatId = SOT_FORMAT_FILE_LIST;
3805cdf0e10cSrcweir     else if ( aDataHelper.HasFormat( SOT_FORMAT_FILE ) )    // #i62773# FILE_LIST/FILE before STRING (Unix file managers)
3806cdf0e10cSrcweir         nFormatId = SOT_FORMAT_FILE;
3807cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMAT_STRING ) )
3808cdf0e10cSrcweir 		nFormatId = SOT_FORMAT_STRING;
3809cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMAT_GDIMETAFILE ) )
3810cdf0e10cSrcweir 		nFormatId = SOT_FORMAT_GDIMETAFILE;
3811cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMAT_BITMAP ) )
3812cdf0e10cSrcweir 		nFormatId = SOT_FORMAT_BITMAP;
3813cdf0e10cSrcweir 
3814cdf0e10cSrcweir 	return nFormatId;
3815cdf0e10cSrcweir }
3816cdf0e10cSrcweir 
3817cdf0e10cSrcweir sal_uLong lcl_GetDropLinkId( const uno::Reference<datatransfer::XTransferable>& xTransfer )
3818cdf0e10cSrcweir {
3819cdf0e10cSrcweir 	TransferableDataHelper aDataHelper( xTransfer );
3820cdf0e10cSrcweir 
3821cdf0e10cSrcweir 	sal_uLong nFormatId = 0;
3822cdf0e10cSrcweir 	if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE ) )
3823cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE;
3824cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK_SOURCE_OLE ) )
3825cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_LINK_SOURCE_OLE;
3826cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_LINK ) )
3827cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_LINK;
3828cdf0e10cSrcweir     else if ( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) )
3829cdf0e10cSrcweir         nFormatId = SOT_FORMAT_FILE_LIST;
3830cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMAT_FILE ) )
3831cdf0e10cSrcweir 		nFormatId = SOT_FORMAT_FILE;
3832cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SOLK ) )
3833cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_SOLK;
3834cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) )
3835cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR;
3836cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) )
3837cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK;
3838cdf0e10cSrcweir 	else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) )
3839cdf0e10cSrcweir 		nFormatId = SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR;
3840cdf0e10cSrcweir 
3841cdf0e10cSrcweir 	return nFormatId;
3842cdf0e10cSrcweir }
3843cdf0e10cSrcweir 
3844cdf0e10cSrcweir 
3845cdf0e10cSrcweir sal_Int8 ScGridWindow::ExecutePrivateDrop( const ExecuteDropEvent& rEvt )
3846cdf0e10cSrcweir {
3847cdf0e10cSrcweir 	// hide drop marker
3848cdf0e10cSrcweir 	// if (bDragRect)
3849cdf0e10cSrcweir 	//	pViewData->GetView()->DrawDragRect( nDragStartX, nDragStartY, nDragEndX, nDragEndY, eWhich );
3850cdf0e10cSrcweir 	bDragRect = sal_False;
3851cdf0e10cSrcweir     UpdateDragRectOverlay();
3852cdf0e10cSrcweir 
3853cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
3854cdf0e10cSrcweir 	const ScDragData& rData = pScMod->GetDragData();
3855cdf0e10cSrcweir 
3856cdf0e10cSrcweir 	return DropTransferObj( rData.pCellTransfer, nDragStartX, nDragStartY,
3857cdf0e10cSrcweir 								PixelToLogic(rEvt.maPosPixel), rEvt.mnAction );
3858cdf0e10cSrcweir }
3859cdf0e10cSrcweir 
3860cdf0e10cSrcweir sal_Int8 ScGridWindow::DropTransferObj( ScTransferObj* pTransObj, SCCOL nDestPosX, SCROW nDestPosY,
3861cdf0e10cSrcweir 										const Point& rLogicPos, sal_Int8 nDndAction )
3862cdf0e10cSrcweir {
3863cdf0e10cSrcweir 	if ( !pTransObj )
3864cdf0e10cSrcweir 		return 0;
3865cdf0e10cSrcweir 
3866cdf0e10cSrcweir 	ScDocument* pSourceDoc = pTransObj->GetSourceDocument();
3867cdf0e10cSrcweir     ScDocShell* pDocSh     = pViewData->GetDocShell();
3868cdf0e10cSrcweir 	ScDocument* pThisDoc   = pViewData->GetDocument();
3869cdf0e10cSrcweir 	ScViewFunc* pView	   = pViewData->GetView();
3870cdf0e10cSrcweir 	SCTAB       nThisTab   = pViewData->GetTabNo();
3871cdf0e10cSrcweir 	sal_uInt16 nFlags = pTransObj->GetDragSourceFlags();
3872cdf0e10cSrcweir 
3873cdf0e10cSrcweir 	sal_Bool bIsNavi = ( nFlags & SC_DROP_NAVIGATOR ) != 0;
3874cdf0e10cSrcweir 	sal_Bool bIsMove = ( nDndAction == DND_ACTION_MOVE && !bIsNavi );
3875cdf0e10cSrcweir 
3876cdf0e10cSrcweir     // workaround for wrong nDndAction on Windows when pressing solely
3877cdf0e10cSrcweir     // the Alt key during drag and drop;
3878cdf0e10cSrcweir     // can be removed after #i79215# has been fixed
3879cdf0e10cSrcweir     if ( meDragInsertMode != INS_NONE )
3880cdf0e10cSrcweir     {
3881cdf0e10cSrcweir         bIsMove = ( nDndAction & DND_ACTION_MOVE && !bIsNavi );
3882cdf0e10cSrcweir     }
3883cdf0e10cSrcweir 
3884cdf0e10cSrcweir 	sal_Bool bIsLink = ( nDndAction == DND_ACTION_LINK );
3885cdf0e10cSrcweir 
3886cdf0e10cSrcweir 	ScRange aSource = pTransObj->GetRange();
3887cdf0e10cSrcweir 
3888cdf0e10cSrcweir 	//	only use visible tab from source range - when dragging within one table,
3889cdf0e10cSrcweir 	//	all selected tables at the time of dropping are used (handled in MoveBlockTo)
3890cdf0e10cSrcweir 	SCTAB nSourceTab = pTransObj->GetVisibleTab();
3891cdf0e10cSrcweir 	aSource.aStart.SetTab( nSourceTab );
3892cdf0e10cSrcweir 	aSource.aEnd.SetTab( nSourceTab );
3893cdf0e10cSrcweir 
3894cdf0e10cSrcweir     SCCOL nSizeX = aSource.aEnd.Col() - aSource.aStart.Col() + 1;
3895cdf0e10cSrcweir     SCROW nSizeY = (bIsMove ? (aSource.aEnd.Row() - aSource.aStart.Row() + 1) :
3896cdf0e10cSrcweir             pTransObj->GetNonFilteredRows());   // copy/link: no filtered rows
3897cdf0e10cSrcweir     ScRange aDest( nDestPosX, nDestPosY, nThisTab,
3898cdf0e10cSrcweir                    nDestPosX + nSizeX - 1, nDestPosY + nSizeY - 1, nThisTab );
3899cdf0e10cSrcweir 
3900cdf0e10cSrcweir 
3901cdf0e10cSrcweir     /* NOTE: AcceptPrivateDrop() already checked for filtered conditions during
3902cdf0e10cSrcweir      * dragging and adapted drawing of the selection frame. We check here
3903cdf0e10cSrcweir      * (again) because this may actually also be called from PasteSelection(),
3904cdf0e10cSrcweir      * we would have to duplicate determination of flags and destination range
3905cdf0e10cSrcweir      * and would lose the context of the "filtered destination is OK" cases
3906cdf0e10cSrcweir      * below, which is already awkward enough as is. */
3907cdf0e10cSrcweir 
3908cdf0e10cSrcweir     // Don't move filtered source.
3909cdf0e10cSrcweir     bool bFiltered = (bIsMove && pTransObj->HasFilteredRows());
3910cdf0e10cSrcweir     if (!bFiltered)
3911cdf0e10cSrcweir     {
3912cdf0e10cSrcweir         if (pSourceDoc != pThisDoc && ((nFlags & SC_DROP_TABLE) ||
3913cdf0e10cSrcweir                     (!bIsLink && meDragInsertMode == INS_NONE)))
3914cdf0e10cSrcweir         {
3915cdf0e10cSrcweir             // Nothing. Either entire sheet to be dropped, or the one case
3916cdf0e10cSrcweir             // where PasteFromClip() is to be called that handles a filtered
3917cdf0e10cSrcweir             // destination itself. Drag-copy from another document without
3918cdf0e10cSrcweir             // inserting cells.
3919cdf0e10cSrcweir         }
3920cdf0e10cSrcweir         else
3921cdf0e10cSrcweir             // Don't copy or move to filtered destination.
3922cdf0e10cSrcweir             bFiltered = ScViewUtil::HasFiltered( aDest, pThisDoc);
3923cdf0e10cSrcweir     }
3924cdf0e10cSrcweir 
3925cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
3926cdf0e10cSrcweir 
3927cdf0e10cSrcweir 	if (!bFiltered && pSourceDoc == pThisDoc)
3928cdf0e10cSrcweir 	{
3929cdf0e10cSrcweir 		if ( nFlags & SC_DROP_TABLE )			// whole sheet?
3930cdf0e10cSrcweir 		{
3931cdf0e10cSrcweir 			if ( pThisDoc->IsDocEditable() )
3932cdf0e10cSrcweir 			{
3933cdf0e10cSrcweir 				SCTAB nSrcTab = aSource.aStart.Tab();
3934cdf0e10cSrcweir 				pViewData->GetDocShell()->MoveTable( nSrcTab, nThisTab, !bIsMove, sal_True );	// with Undo
3935cdf0e10cSrcweir 				pView->SetTabNo( nThisTab, sal_True );
3936cdf0e10cSrcweir 				bDone = sal_True;
3937cdf0e10cSrcweir 			}
3938cdf0e10cSrcweir 		}
3939cdf0e10cSrcweir 		else										// move/copy block
3940cdf0e10cSrcweir 		{
3941cdf0e10cSrcweir 			String aChartName;
3942cdf0e10cSrcweir 			if (pThisDoc->HasChartAtPoint( nThisTab, rLogicPos, &aChartName ))
3943cdf0e10cSrcweir 			{
3944cdf0e10cSrcweir 				String aRangeName;
3945cdf0e10cSrcweir 				aSource.Format( aRangeName, SCR_ABS_3D, pThisDoc );
3946cdf0e10cSrcweir 				SfxStringItem aNameItem( SID_CHART_NAME, aChartName );
3947cdf0e10cSrcweir 				SfxStringItem aRangeItem( SID_CHART_SOURCE, aRangeName );
3948cdf0e10cSrcweir 				sal_uInt16 nId = bIsMove ? SID_CHART_SOURCE : SID_CHART_ADDSOURCE;
3949cdf0e10cSrcweir 				pViewData->GetDispatcher().Execute( nId, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
3950cdf0e10cSrcweir 											&aRangeItem, &aNameItem, (void*) NULL );
3951cdf0e10cSrcweir 				bDone = sal_True;
3952cdf0e10cSrcweir 			}
3953cdf0e10cSrcweir             else if ( pThisDoc->GetDPAtCursor( nDestPosX, nDestPosY, nThisTab ) )
3954cdf0e10cSrcweir             {
3955cdf0e10cSrcweir                 // drop on DataPilot table: try to sort, fail if that isn't possible
3956cdf0e10cSrcweir 
3957cdf0e10cSrcweir                 ScAddress aDestPos( nDestPosX, nDestPosY, nThisTab );
3958cdf0e10cSrcweir                 if ( aDestPos != aSource.aStart )
3959cdf0e10cSrcweir                     bDone = pViewData->GetView()->DataPilotMove( aSource, aDestPos );
3960cdf0e10cSrcweir                 else
3961cdf0e10cSrcweir                     bDone = sal_True;   // same position: nothing
3962cdf0e10cSrcweir             }
3963cdf0e10cSrcweir 			else if ( nDestPosX != aSource.aStart.Col() || nDestPosY != aSource.aStart.Row() ||
3964cdf0e10cSrcweir 						nSourceTab != nThisTab )
3965cdf0e10cSrcweir 			{
3966cdf0e10cSrcweir                 String aUndo = ScGlobal::GetRscString( bIsMove ? STR_UNDO_MOVE : STR_UNDO_COPY );
3967cdf0e10cSrcweir                 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
3968cdf0e10cSrcweir 
3969cdf0e10cSrcweir                 bDone = sal_True;
3970cdf0e10cSrcweir                 if ( meDragInsertMode != INS_NONE )
3971cdf0e10cSrcweir                 {
3972cdf0e10cSrcweir                     // call with bApi = sal_True to avoid error messages in drop handler
3973cdf0e10cSrcweir                     bDone = pDocSh->GetDocFunc().InsertCells( aDest, NULL, meDragInsertMode, sal_True /*bRecord*/, sal_True /*bApi*/, sal_True /*bPartOfPaste*/ );
3974cdf0e10cSrcweir                     if ( bDone )
3975cdf0e10cSrcweir                     {
3976cdf0e10cSrcweir                         if ( nThisTab == nSourceTab )
3977cdf0e10cSrcweir                         {
3978cdf0e10cSrcweir                             if ( meDragInsertMode == INS_CELLSDOWN &&
3979cdf0e10cSrcweir                                  nDestPosX == aSource.aStart.Col() && nDestPosY < aSource.aStart.Row() )
3980cdf0e10cSrcweir                             {
3981cdf0e10cSrcweir                                 bDone = aSource.Move( 0, nSizeY, 0, pSourceDoc );
3982cdf0e10cSrcweir                             }
3983cdf0e10cSrcweir                             else if ( meDragInsertMode == INS_CELLSRIGHT &&
3984cdf0e10cSrcweir                                       nDestPosY == aSource.aStart.Row() && nDestPosX < aSource.aStart.Col() )
3985cdf0e10cSrcweir                             {
3986cdf0e10cSrcweir                                 bDone = aSource.Move( nSizeX, 0, 0, pSourceDoc );
3987cdf0e10cSrcweir                             }
3988cdf0e10cSrcweir                         }
3989cdf0e10cSrcweir                         pDocSh->UpdateOle( pViewData );
3990cdf0e10cSrcweir                         pView->CellContentChanged();
3991cdf0e10cSrcweir                     }
3992cdf0e10cSrcweir                 }
3993cdf0e10cSrcweir 
3994cdf0e10cSrcweir                 if ( bDone )
3995cdf0e10cSrcweir                 {
3996cdf0e10cSrcweir                     if ( bIsLink )
3997cdf0e10cSrcweir                     {
3998cdf0e10cSrcweir                         // call with bApi = sal_True to avoid error messages in drop handler
3999cdf0e10cSrcweir                         bDone = pView->LinkBlock( aSource, aDest.aStart, sal_True /*bApi*/ );
4000cdf0e10cSrcweir                     }
4001cdf0e10cSrcweir                     else
4002cdf0e10cSrcweir                     {
4003cdf0e10cSrcweir                         // call with bApi = sal_True to avoid error messages in drop handler
4004cdf0e10cSrcweir                         bDone = pView->MoveBlockTo( aSource, aDest.aStart, bIsMove, sal_True /*bRecord*/, sal_True /*bPaint*/, sal_True /*bApi*/ );
4005cdf0e10cSrcweir                     }
4006cdf0e10cSrcweir                 }
4007cdf0e10cSrcweir 
4008cdf0e10cSrcweir                 if ( bDone && meDragInsertMode != INS_NONE && bIsMove && nThisTab == nSourceTab )
4009cdf0e10cSrcweir                 {
4010cdf0e10cSrcweir                     DelCellCmd eCmd = DEL_NONE;
4011cdf0e10cSrcweir                     if ( meDragInsertMode == INS_CELLSDOWN )
4012cdf0e10cSrcweir                     {
4013cdf0e10cSrcweir                         eCmd = DEL_CELLSUP;
4014cdf0e10cSrcweir                     }
4015cdf0e10cSrcweir                     else if ( meDragInsertMode == INS_CELLSRIGHT )
4016cdf0e10cSrcweir                     {
4017cdf0e10cSrcweir                         eCmd = DEL_CELLSLEFT;
4018cdf0e10cSrcweir                     }
4019cdf0e10cSrcweir 
4020cdf0e10cSrcweir                     if ( ( eCmd == DEL_CELLSUP  && nDestPosX == aSource.aStart.Col() ) ||
4021cdf0e10cSrcweir                          ( eCmd == DEL_CELLSLEFT && nDestPosY == aSource.aStart.Row() ) )
4022cdf0e10cSrcweir                     {
4023cdf0e10cSrcweir                         // call with bApi = sal_True to avoid error messages in drop handler
4024cdf0e10cSrcweir                         bDone = pDocSh->GetDocFunc().DeleteCells( aSource, NULL, eCmd, sal_True /*bRecord*/, sal_True /*bApi*/ );
4025cdf0e10cSrcweir                         if ( bDone )
4026cdf0e10cSrcweir                         {
4027cdf0e10cSrcweir                             if ( eCmd == DEL_CELLSUP && nDestPosY > aSource.aEnd.Row() )
4028cdf0e10cSrcweir                             {
4029cdf0e10cSrcweir                                 bDone = aDest.Move( 0, -nSizeY, 0, pThisDoc );
4030cdf0e10cSrcweir                             }
4031cdf0e10cSrcweir                             else if ( eCmd == DEL_CELLSLEFT && nDestPosX > aSource.aEnd.Col() )
4032cdf0e10cSrcweir                             {
4033cdf0e10cSrcweir                                 bDone = aDest.Move( -nSizeX, 0, 0, pThisDoc );
4034cdf0e10cSrcweir                             }
4035cdf0e10cSrcweir                             pDocSh->UpdateOle( pViewData );
4036cdf0e10cSrcweir                             pView->CellContentChanged();
4037cdf0e10cSrcweir                         }
4038cdf0e10cSrcweir                     }
4039cdf0e10cSrcweir                 }
4040cdf0e10cSrcweir 
4041cdf0e10cSrcweir                 if ( bDone )
4042cdf0e10cSrcweir                 {
4043cdf0e10cSrcweir                     pView->MarkRange( aDest, sal_False, sal_False );
4044cdf0e10cSrcweir                     pView->SetCursor( aDest.aEnd.Col(), aDest.aEnd.Row() );
4045cdf0e10cSrcweir                 }
4046cdf0e10cSrcweir 
4047cdf0e10cSrcweir                 pDocSh->GetUndoManager()->LeaveListAction();
4048cdf0e10cSrcweir 
4049cdf0e10cSrcweir 				if (!bDone)
4050cdf0e10cSrcweir 					Sound::Beep();	// instead of error message in drop handler
4051cdf0e10cSrcweir 			}
4052cdf0e10cSrcweir 			else
4053cdf0e10cSrcweir 				bDone = sal_True;		// nothing to do
4054cdf0e10cSrcweir 		}
4055cdf0e10cSrcweir 
4056cdf0e10cSrcweir 		if (bDone)
4057cdf0e10cSrcweir 			pTransObj->SetDragWasInternal();	// don't delete source in DragFinished
4058cdf0e10cSrcweir 	}
4059cdf0e10cSrcweir 	else if ( !bFiltered && pSourceDoc )						// between documents
4060cdf0e10cSrcweir 	{
4061cdf0e10cSrcweir 		if ( nFlags & SC_DROP_TABLE )			// copy/link sheets between documents
4062cdf0e10cSrcweir 		{
4063cdf0e10cSrcweir 			if ( pThisDoc->IsDocEditable() )
4064cdf0e10cSrcweir 			{
4065cdf0e10cSrcweir 				ScDocShell* pSrcShell = pTransObj->GetSourceDocShell();
4066cdf0e10cSrcweir 
4067cdf0e10cSrcweir 				SCTAB nTabs[MAXTABCOUNT];
4068cdf0e10cSrcweir 
4069cdf0e10cSrcweir 				ScMarkData	aMark		= pTransObj->GetSourceMarkData();
4070cdf0e10cSrcweir 				SCTAB		nTabCount	= pSourceDoc->GetTableCount();
4071cdf0e10cSrcweir 				SCTAB		nTabSelCount = 0;
4072cdf0e10cSrcweir 
4073cdf0e10cSrcweir 				for(SCTAB i=0; i<nTabCount; i++)
4074cdf0e10cSrcweir 				{
4075cdf0e10cSrcweir 					if(aMark.GetTableSelect(i))
4076cdf0e10cSrcweir 					{
4077cdf0e10cSrcweir 						nTabs[nTabSelCount++]=i;
4078cdf0e10cSrcweir 						for(SCTAB j=i+1;j<nTabCount;j++)
4079cdf0e10cSrcweir 						{
4080cdf0e10cSrcweir 							if((!pSourceDoc->IsVisible(j))&&(pSourceDoc->IsScenario(j)))
4081cdf0e10cSrcweir 							{
4082cdf0e10cSrcweir 								nTabs[nTabSelCount++]=j;
4083cdf0e10cSrcweir 								i=j;
4084cdf0e10cSrcweir 							}
4085cdf0e10cSrcweir 							else break;
4086cdf0e10cSrcweir 						}
4087cdf0e10cSrcweir 					}
4088cdf0e10cSrcweir 				}
4089cdf0e10cSrcweir 
4090cdf0e10cSrcweir 				pView->ImportTables( pSrcShell,nTabSelCount, nTabs, bIsLink, nThisTab );
4091cdf0e10cSrcweir 				bDone = sal_True;
4092cdf0e10cSrcweir 			}
4093cdf0e10cSrcweir 		}
4094cdf0e10cSrcweir 		else if ( bIsLink )
4095cdf0e10cSrcweir 		{
4096cdf0e10cSrcweir 			//	as in PasteDDE
4097cdf0e10cSrcweir 			//	(external references might be used instead?)
4098cdf0e10cSrcweir 
4099cdf0e10cSrcweir 			SfxObjectShell* pSourceSh = pSourceDoc->GetDocumentShell();
4100cdf0e10cSrcweir 			DBG_ASSERT(pSourceSh, "drag document has no shell");
4101cdf0e10cSrcweir 			if (pSourceSh)
4102cdf0e10cSrcweir 			{
4103cdf0e10cSrcweir                 String aUndo = ScGlobal::GetRscString( STR_UNDO_COPY );
4104cdf0e10cSrcweir                 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
4105cdf0e10cSrcweir 
4106cdf0e10cSrcweir                 bDone = sal_True;
4107cdf0e10cSrcweir                 if ( meDragInsertMode != INS_NONE )
4108cdf0e10cSrcweir                 {
4109cdf0e10cSrcweir                     // call with bApi = sal_True to avoid error messages in drop handler
4110cdf0e10cSrcweir                     bDone = pDocSh->GetDocFunc().InsertCells( aDest, NULL, meDragInsertMode, sal_True /*bRecord*/, sal_True /*bApi*/, sal_True /*bPartOfPaste*/ );
4111cdf0e10cSrcweir                     if ( bDone )
4112cdf0e10cSrcweir                     {
4113cdf0e10cSrcweir                         pDocSh->UpdateOle( pViewData );
4114cdf0e10cSrcweir                         pView->CellContentChanged();
4115cdf0e10cSrcweir                     }
4116cdf0e10cSrcweir                 }
4117cdf0e10cSrcweir 
4118cdf0e10cSrcweir                 if ( bDone )
4119cdf0e10cSrcweir                 {
4120cdf0e10cSrcweir                     String aApp = Application::GetAppName();
4121cdf0e10cSrcweir                     String aTopic = pSourceSh->GetTitle( SFX_TITLE_FULLNAME );
4122cdf0e10cSrcweir                     String aItem;
4123cdf0e10cSrcweir                     aSource.Format( aItem, SCA_VALID | SCA_TAB_3D, pSourceDoc );
4124cdf0e10cSrcweir 
4125cdf0e10cSrcweir                     // TODO: we could define ocQuote for "
4126cdf0e10cSrcweir                     const String aQuote( '"' );
4127cdf0e10cSrcweir                     const String& sSep = ScCompiler::GetNativeSymbol( ocSep);
4128cdf0e10cSrcweir                     String aFormula( '=' );
4129cdf0e10cSrcweir                     aFormula += ScCompiler::GetNativeSymbol( ocDde);
4130cdf0e10cSrcweir                     aFormula += ScCompiler::GetNativeSymbol( ocOpen);
4131cdf0e10cSrcweir                     aFormula += aQuote;
4132cdf0e10cSrcweir                     aFormula += aApp;
4133cdf0e10cSrcweir                     aFormula += aQuote;
4134cdf0e10cSrcweir                     aFormula += sSep;
4135cdf0e10cSrcweir                     aFormula += aQuote;
4136cdf0e10cSrcweir                     aFormula += aTopic;
4137cdf0e10cSrcweir                     aFormula += aQuote;
4138cdf0e10cSrcweir                     aFormula += sSep;
4139cdf0e10cSrcweir                     aFormula += aQuote;
4140cdf0e10cSrcweir                     aFormula += aItem;
4141cdf0e10cSrcweir                     aFormula += aQuote;
4142cdf0e10cSrcweir                     aFormula += ScCompiler::GetNativeSymbol( ocClose);
4143cdf0e10cSrcweir 
4144cdf0e10cSrcweir                     pView->DoneBlockMode();
4145cdf0e10cSrcweir                     pView->InitBlockMode( nDestPosX, nDestPosY, nThisTab );
4146cdf0e10cSrcweir                     pView->MarkCursor( nDestPosX + nSizeX - 1,
4147cdf0e10cSrcweir                                        nDestPosY + nSizeY - 1, nThisTab );
4148cdf0e10cSrcweir 
4149cdf0e10cSrcweir                     pView->EnterMatrix( aFormula );
4150cdf0e10cSrcweir 
4151cdf0e10cSrcweir                     pView->MarkRange( aDest, sal_False, sal_False );
4152cdf0e10cSrcweir                     pView->SetCursor( aDest.aEnd.Col(), aDest.aEnd.Row() );
4153cdf0e10cSrcweir                 }
4154cdf0e10cSrcweir 
4155cdf0e10cSrcweir                 pDocSh->GetUndoManager()->LeaveListAction();
4156cdf0e10cSrcweir 			}
4157cdf0e10cSrcweir 		}
4158cdf0e10cSrcweir 		else
4159cdf0e10cSrcweir 		{
4160cdf0e10cSrcweir 			//!	HasSelectedBlockMatrixFragment without selected sheet?
4161cdf0e10cSrcweir 			//!	or don't start dragging on a part of a matrix
4162cdf0e10cSrcweir 
4163cdf0e10cSrcweir             String aUndo = ScGlobal::GetRscString( bIsMove ? STR_UNDO_MOVE : STR_UNDO_COPY );
4164cdf0e10cSrcweir             pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
4165cdf0e10cSrcweir 
4166cdf0e10cSrcweir             bDone = sal_True;
4167cdf0e10cSrcweir             if ( meDragInsertMode != INS_NONE )
4168cdf0e10cSrcweir             {
4169cdf0e10cSrcweir                 // call with bApi = sal_True to avoid error messages in drop handler
4170cdf0e10cSrcweir                 bDone = pDocSh->GetDocFunc().InsertCells( aDest, NULL, meDragInsertMode, sal_True /*bRecord*/, sal_True /*bApi*/, sal_True /*bPartOfPaste*/ );
4171cdf0e10cSrcweir                 if ( bDone )
4172cdf0e10cSrcweir                 {
4173cdf0e10cSrcweir                     pDocSh->UpdateOle( pViewData );
4174cdf0e10cSrcweir                     pView->CellContentChanged();
4175cdf0e10cSrcweir                 }
4176cdf0e10cSrcweir             }
4177cdf0e10cSrcweir 
4178cdf0e10cSrcweir             if ( bDone )
4179cdf0e10cSrcweir             {
4180cdf0e10cSrcweir                 pView->Unmark();  // before SetCursor, so CheckSelectionTransfer isn't called with a selection
4181cdf0e10cSrcweir                 pView->SetCursor( nDestPosX, nDestPosY );
4182cdf0e10cSrcweir                 bDone = pView->PasteFromClip( IDF_ALL, pTransObj->GetDocument() );  // clip-doc
4183cdf0e10cSrcweir                 if ( bDone )
4184cdf0e10cSrcweir                 {
4185cdf0e10cSrcweir                     pView->MarkRange( aDest, sal_False, sal_False );
4186cdf0e10cSrcweir                     pView->SetCursor( aDest.aEnd.Col(), aDest.aEnd.Row() );
4187cdf0e10cSrcweir                 }
4188cdf0e10cSrcweir             }
4189cdf0e10cSrcweir 
4190cdf0e10cSrcweir             pDocSh->GetUndoManager()->LeaveListAction();
4191cdf0e10cSrcweir 
4192cdf0e10cSrcweir 			//	no longer call ResetMark here - the inserted block has been selected
4193cdf0e10cSrcweir 			//	and may have been copied to primary selection
4194cdf0e10cSrcweir 		}
4195cdf0e10cSrcweir 	}
4196cdf0e10cSrcweir 
4197cdf0e10cSrcweir 	sal_Int8 nRet = bDone ? nDndAction : DND_ACTION_NONE;
4198cdf0e10cSrcweir 	return nRet;
4199cdf0e10cSrcweir }
4200cdf0e10cSrcweir 
4201cdf0e10cSrcweir sal_Int8 ScGridWindow::ExecuteDrop( const ExecuteDropEvent& rEvt )
4202cdf0e10cSrcweir {
4203cdf0e10cSrcweir 	DrawMarkDropObj( NULL );	// drawing layer
4204cdf0e10cSrcweir 
4205cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
4206cdf0e10cSrcweir 	const ScDragData& rData = pScMod->GetDragData();
4207cdf0e10cSrcweir 	if (rData.pCellTransfer)
4208cdf0e10cSrcweir 		return ExecutePrivateDrop( rEvt );
4209cdf0e10cSrcweir 
4210cdf0e10cSrcweir 	Point aPos = rEvt.maPosPixel;
4211cdf0e10cSrcweir 
4212cdf0e10cSrcweir 	if ( rData.aLinkDoc.Len() )
4213cdf0e10cSrcweir 	{
4214cdf0e10cSrcweir 		//	try to insert a link
4215cdf0e10cSrcweir 
4216cdf0e10cSrcweir 		sal_Bool bOk = sal_True;
4217cdf0e10cSrcweir 		String aThisName;
4218cdf0e10cSrcweir 		ScDocShell* pDocSh = pViewData->GetDocShell();
4219cdf0e10cSrcweir 		if (pDocSh && pDocSh->HasName())
4220cdf0e10cSrcweir 			aThisName = pDocSh->GetMedium()->GetName();
4221cdf0e10cSrcweir 
4222cdf0e10cSrcweir 		if ( rData.aLinkDoc == aThisName )				// error - no link within a document
4223cdf0e10cSrcweir 			bOk = sal_False;
4224cdf0e10cSrcweir 		else
4225cdf0e10cSrcweir 		{
4226cdf0e10cSrcweir 			ScViewFunc* pView = pViewData->GetView();
4227cdf0e10cSrcweir 			if ( rData.aLinkTable.Len() )
4228cdf0e10cSrcweir 				pView->InsertTableLink( rData.aLinkDoc, EMPTY_STRING, EMPTY_STRING,
4229cdf0e10cSrcweir 										rData.aLinkTable );
4230cdf0e10cSrcweir 			else if ( rData.aLinkArea.Len() )
4231cdf0e10cSrcweir 			{
4232cdf0e10cSrcweir 				SCsCOL	nPosX;
4233cdf0e10cSrcweir 				SCsROW	nPosY;
4234cdf0e10cSrcweir 				pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
4235cdf0e10cSrcweir 				pView->MoveCursorAbs( nPosX, nPosY, SC_FOLLOW_NONE, sal_False, sal_False );
4236cdf0e10cSrcweir 
4237cdf0e10cSrcweir 				pView->InsertAreaLink( rData.aLinkDoc, EMPTY_STRING, EMPTY_STRING,
4238cdf0e10cSrcweir 										rData.aLinkArea, 0 );
4239cdf0e10cSrcweir 			}
4240cdf0e10cSrcweir 			else
4241cdf0e10cSrcweir 			{
4242cdf0e10cSrcweir 				DBG_ERROR("drop with link: no sheet nor area");
4243cdf0e10cSrcweir 				bOk = sal_False;
4244cdf0e10cSrcweir 			}
4245cdf0e10cSrcweir 		}
4246cdf0e10cSrcweir 
4247cdf0e10cSrcweir 		return bOk ? rEvt.mnAction : DND_ACTION_NONE;			// don't try anything else
4248cdf0e10cSrcweir 	}
4249cdf0e10cSrcweir 
4250cdf0e10cSrcweir 	Point aLogicPos = PixelToLogic(aPos);
42513cc56398SArmin Le Grand 	sal_Bool bIsLink = ( rEvt.mnAction == DND_ACTION_LINK );
4252cdf0e10cSrcweir 
42533cc56398SArmin Le Grand 	if (!bIsLink && rData.pDrawTransfer)
4254cdf0e10cSrcweir 	{
4255cdf0e10cSrcweir 		sal_uInt16 nFlags = rData.pDrawTransfer->GetDragSourceFlags();
4256cdf0e10cSrcweir 
4257cdf0e10cSrcweir 		sal_Bool bIsNavi = ( nFlags & SC_DROP_NAVIGATOR ) != 0;
4258cdf0e10cSrcweir 		sal_Bool bIsMove = ( rEvt.mnAction == DND_ACTION_MOVE && !bIsNavi );
4259cdf0e10cSrcweir 
4260cdf0e10cSrcweir 		bPasteIsMove = bIsMove;
4261cdf0e10cSrcweir 
4262cdf0e10cSrcweir 		pViewData->GetView()->PasteDraw( aLogicPos, rData.pDrawTransfer->GetModel() );
4263cdf0e10cSrcweir 
4264cdf0e10cSrcweir 		if (bPasteIsMove)
4265cdf0e10cSrcweir 			rData.pDrawTransfer->SetDragWasInternal();
4266cdf0e10cSrcweir 		bPasteIsMove = sal_False;
4267cdf0e10cSrcweir 
4268cdf0e10cSrcweir 		return rEvt.mnAction;
4269cdf0e10cSrcweir 	}
4270cdf0e10cSrcweir 
4271cdf0e10cSrcweir 
4272cdf0e10cSrcweir 	SCsCOL	nPosX;
4273cdf0e10cSrcweir 	SCsROW	nPosY;
4274cdf0e10cSrcweir 	pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
4275cdf0e10cSrcweir 
4276cdf0e10cSrcweir 	if (rData.aJumpTarget.Len())
4277cdf0e10cSrcweir 	{
4278cdf0e10cSrcweir 		//	internal bookmark (from Navigator)
4279cdf0e10cSrcweir 		//	bookmark clipboard formats are in PasteScDataObject
4280cdf0e10cSrcweir 
4281cdf0e10cSrcweir 		if ( !rData.pJumpLocalDoc || rData.pJumpLocalDoc == pViewData->GetDocument() )
4282cdf0e10cSrcweir 		{
4283cdf0e10cSrcweir 			pViewData->GetViewShell()->InsertBookmark( rData.aJumpText, rData.aJumpTarget,
4284cdf0e10cSrcweir 														nPosX, nPosY );
4285cdf0e10cSrcweir 			return rEvt.mnAction;
4286cdf0e10cSrcweir 		}
4287cdf0e10cSrcweir 	}
4288cdf0e10cSrcweir 
4289cdf0e10cSrcweir 	ScDocument* pThisDoc = pViewData->GetDocument();
4290cdf0e10cSrcweir 	SdrObject* pHitObj = pThisDoc->GetObjectAtPoint( pViewData->GetTabNo(), PixelToLogic(aPos) );
4291cdf0e10cSrcweir 	if ( pHitObj && bIsLink )
4292cdf0e10cSrcweir 	{
4293cdf0e10cSrcweir 		//	dropped on drawing object
4294cdf0e10cSrcweir 		//	PasteOnDrawObject checks for valid formats
4295cdf0e10cSrcweir 		if ( pViewData->GetView()->PasteOnDrawObject( rEvt.maDropEvent.Transferable, pHitObj, sal_True ) )
4296cdf0e10cSrcweir 			return rEvt.mnAction;
4297cdf0e10cSrcweir 	}
4298cdf0e10cSrcweir 
4299cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
4300cdf0e10cSrcweir 
4301cdf0e10cSrcweir 	sal_uLong nFormatId = bIsLink ?
4302cdf0e10cSrcweir 						lcl_GetDropLinkId( rEvt.maDropEvent.Transferable ) :
4303cdf0e10cSrcweir 						lcl_GetDropFormatId( rEvt.maDropEvent.Transferable );
4304cdf0e10cSrcweir 	if ( nFormatId )
4305cdf0e10cSrcweir 	{
4306cdf0e10cSrcweir         pScMod->SetInExecuteDrop( sal_True );   // #i28468# prevent error messages from PasteDataFormat
4307cdf0e10cSrcweir 		bPasteIsDrop = sal_True;
4308cdf0e10cSrcweir 		bDone = pViewData->GetView()->PasteDataFormat(
4309cdf0e10cSrcweir 					nFormatId, rEvt.maDropEvent.Transferable, nPosX, nPosY, &aLogicPos, bIsLink );
4310cdf0e10cSrcweir 		bPasteIsDrop = sal_False;
4311cdf0e10cSrcweir         pScMod->SetInExecuteDrop( sal_False );
4312cdf0e10cSrcweir 	}
4313cdf0e10cSrcweir 
4314cdf0e10cSrcweir 	sal_Int8 nRet = bDone ? rEvt.mnAction : DND_ACTION_NONE;
4315cdf0e10cSrcweir 	return nRet;
4316cdf0e10cSrcweir }
4317cdf0e10cSrcweir 
4318cdf0e10cSrcweir //--------------------------------------------------------
4319cdf0e10cSrcweir 
4320cdf0e10cSrcweir void ScGridWindow::PasteSelection( const Point& rPosPixel )
4321cdf0e10cSrcweir {
4322cdf0e10cSrcweir 	Point aLogicPos = PixelToLogic( rPosPixel );
4323cdf0e10cSrcweir 
4324cdf0e10cSrcweir 	SCsCOL	nPosX;
4325cdf0e10cSrcweir 	SCsROW	nPosY;
4326cdf0e10cSrcweir 	pViewData->GetPosFromPixel( rPosPixel.X(), rPosPixel.Y(), eWhich, nPosX, nPosY );
4327cdf0e10cSrcweir 
4328cdf0e10cSrcweir 	ScSelectionTransferObj* pOwnSelection = SC_MOD()->GetSelectionTransfer();
4329cdf0e10cSrcweir 	if ( pOwnSelection )
4330cdf0e10cSrcweir 	{
4331cdf0e10cSrcweir 		//	within Calc
4332cdf0e10cSrcweir 
4333cdf0e10cSrcweir 		ScTransferObj* pCellTransfer = pOwnSelection->GetCellData();
4334cdf0e10cSrcweir 		if ( pCellTransfer )
4335cdf0e10cSrcweir 		{
4336cdf0e10cSrcweir 			// keep a reference to the data in case the selection is changed during paste
4337cdf0e10cSrcweir 			uno::Reference<datatransfer::XTransferable> xRef( pCellTransfer );
4338cdf0e10cSrcweir 			DropTransferObj( pCellTransfer, nPosX, nPosY, aLogicPos, DND_ACTION_COPY );
4339cdf0e10cSrcweir 		}
4340cdf0e10cSrcweir 		else
4341cdf0e10cSrcweir 		{
4342cdf0e10cSrcweir 			ScDrawTransferObj* pDrawTransfer = pOwnSelection->GetDrawData();
4343cdf0e10cSrcweir 			if ( pDrawTransfer )
4344cdf0e10cSrcweir 			{
4345cdf0e10cSrcweir 				// keep a reference to the data in case the selection is changed during paste
4346cdf0e10cSrcweir 				uno::Reference<datatransfer::XTransferable> xRef( pDrawTransfer );
4347cdf0e10cSrcweir 
4348cdf0e10cSrcweir 				//	#96821# bSameDocClipboard argument for PasteDraw is needed
4349cdf0e10cSrcweir 				//	because only DragData is checked directly inside PasteDraw
4350cdf0e10cSrcweir 				pViewData->GetView()->PasteDraw( aLogicPos, pDrawTransfer->GetModel(), sal_False,
4351cdf0e10cSrcweir 							pDrawTransfer->GetSourceDocID() == pViewData->GetDocument()->GetDocumentID() );
4352cdf0e10cSrcweir 			}
4353cdf0e10cSrcweir 		}
4354cdf0e10cSrcweir 	}
4355cdf0e10cSrcweir 	else
4356cdf0e10cSrcweir 	{
4357cdf0e10cSrcweir 		//	get selection from system
4358cdf0e10cSrcweir 
4359cdf0e10cSrcweir 		TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSelection( this ) );
4360cdf0e10cSrcweir 		uno::Reference<datatransfer::XTransferable> xTransferable = aDataHelper.GetTransferable();
4361cdf0e10cSrcweir 		if ( xTransferable.is() )
4362cdf0e10cSrcweir 		{
4363cdf0e10cSrcweir 			sal_uLong nFormatId = lcl_GetDropFormatId( xTransferable, true );
4364cdf0e10cSrcweir 			if ( nFormatId )
4365cdf0e10cSrcweir 			{
4366cdf0e10cSrcweir 				bPasteIsDrop = sal_True;
4367cdf0e10cSrcweir 				pViewData->GetView()->PasteDataFormat( nFormatId, xTransferable, nPosX, nPosY, &aLogicPos );
4368cdf0e10cSrcweir 				bPasteIsDrop = sal_False;
4369cdf0e10cSrcweir 			}
4370cdf0e10cSrcweir 		}
4371cdf0e10cSrcweir 	}
4372cdf0e10cSrcweir }
4373cdf0e10cSrcweir 
4374cdf0e10cSrcweir //--------------------------------------------------------
4375cdf0e10cSrcweir 
4376cdf0e10cSrcweir void ScGridWindow::UpdateEditViewPos()
4377cdf0e10cSrcweir {
4378cdf0e10cSrcweir 	if (pViewData->HasEditView(eWhich))
4379cdf0e10cSrcweir 	{
4380cdf0e10cSrcweir 		EditView* pView;
4381cdf0e10cSrcweir 		SCCOL nCol;
4382cdf0e10cSrcweir 		SCROW nRow;
4383cdf0e10cSrcweir 		pViewData->GetEditView( eWhich, pView, nCol, nRow );
4384cdf0e10cSrcweir 		SCCOL nEndCol = pViewData->GetEditEndCol();
4385cdf0e10cSrcweir 		SCROW nEndRow = pViewData->GetEditEndRow();
4386cdf0e10cSrcweir 
4387cdf0e10cSrcweir 		//	hide EditView?
4388cdf0e10cSrcweir 
4389cdf0e10cSrcweir 		sal_Bool bHide = ( nEndCol<pViewData->GetPosX(eHWhich) || nEndRow<pViewData->GetPosY(eVWhich) );
4390cdf0e10cSrcweir 		if ( SC_MOD()->IsFormulaMode() )
4391cdf0e10cSrcweir 			if ( pViewData->GetTabNo() != pViewData->GetRefTabNo() )
4392cdf0e10cSrcweir 				bHide = sal_True;
4393cdf0e10cSrcweir 
4394cdf0e10cSrcweir 		if (bHide)
4395cdf0e10cSrcweir 		{
4396cdf0e10cSrcweir 			Rectangle aRect = pView->GetOutputArea();
4397cdf0e10cSrcweir 			long nHeight = aRect.Bottom() - aRect.Top();
4398cdf0e10cSrcweir 			aRect.Top() = PixelToLogic(GetOutputSizePixel(), pViewData->GetLogicMode()).
4399cdf0e10cSrcweir 							Height() * 2;
4400cdf0e10cSrcweir 			aRect.Bottom() = aRect.Top() + nHeight;
4401cdf0e10cSrcweir 			pView->SetOutputArea( aRect );
4402cdf0e10cSrcweir 			pView->HideCursor();
4403cdf0e10cSrcweir 		}
4404cdf0e10cSrcweir 		else
4405cdf0e10cSrcweir 		{
4406cdf0e10cSrcweir 			// bForceToTop = sal_True for editing
4407cdf0e10cSrcweir 			Rectangle aPixRect = pViewData->GetEditArea( eWhich, nCol, nRow, this, NULL, sal_True );
4408cdf0e10cSrcweir 			Point aScrPos = PixelToLogic( aPixRect.TopLeft(), pViewData->GetLogicMode() );
4409cdf0e10cSrcweir 
4410cdf0e10cSrcweir 			Rectangle aRect = pView->GetOutputArea();
4411cdf0e10cSrcweir 			aRect.SetPos( aScrPos );
4412cdf0e10cSrcweir 			pView->SetOutputArea( aRect );
4413cdf0e10cSrcweir 			pView->ShowCursor();
4414cdf0e10cSrcweir 		}
4415cdf0e10cSrcweir 	}
4416cdf0e10cSrcweir }
4417cdf0e10cSrcweir 
4418cdf0e10cSrcweir void ScGridWindow::ScrollPixel( long nDifX, long nDifY )
4419cdf0e10cSrcweir {
4420cdf0e10cSrcweir 	ClickExtern();
4421cdf0e10cSrcweir 	HideNoteMarker();
4422cdf0e10cSrcweir 
4423cdf0e10cSrcweir 	bIsInScroll = sal_True;
4424cdf0e10cSrcweir 	//sal_Bool bXor=DrawBeforeScroll();
4425cdf0e10cSrcweir 
4426cdf0e10cSrcweir 	SetMapMode(MAP_PIXEL);
4427cdf0e10cSrcweir 	Scroll( nDifX, nDifY, SCROLL_CHILDREN );
4428cdf0e10cSrcweir 	SetMapMode( GetDrawMapMode() );				// verschobenen MapMode erzeugen
4429cdf0e10cSrcweir 
4430cdf0e10cSrcweir 	UpdateEditViewPos();
4431cdf0e10cSrcweir 
4432cdf0e10cSrcweir 	DrawAfterScroll(); //bXor);
4433cdf0e10cSrcweir 	bIsInScroll = sal_False;
4434cdf0e10cSrcweir }
4435cdf0e10cSrcweir 
4436cdf0e10cSrcweir // 	Formeln neu zeichnen -------------------------------------------------
4437cdf0e10cSrcweir 
4438cdf0e10cSrcweir void ScGridWindow::UpdateFormulas()
4439cdf0e10cSrcweir {
4440cdf0e10cSrcweir 	if (pViewData->GetView()->IsMinimized())
4441cdf0e10cSrcweir 		return;
4442cdf0e10cSrcweir 
4443cdf0e10cSrcweir 	if ( nPaintCount )
4444cdf0e10cSrcweir 	{
4445cdf0e10cSrcweir 		//	nicht anfangen, verschachtelt zu painten
4446cdf0e10cSrcweir 		//	(dann wuerde zumindest der MapMode nicht mehr stimmen)
4447cdf0e10cSrcweir 
4448cdf0e10cSrcweir 		bNeedsRepaint = sal_True;			// -> am Ende vom Paint nochmal Invalidate auf alles
4449cdf0e10cSrcweir 		aRepaintPixel = Rectangle();	// alles
4450cdf0e10cSrcweir 		return;
4451cdf0e10cSrcweir 	}
4452cdf0e10cSrcweir 
4453cdf0e10cSrcweir 	SCCOL	nX1 = pViewData->GetPosX( eHWhich );
4454cdf0e10cSrcweir 	SCROW	nY1 = pViewData->GetPosY( eVWhich );
4455cdf0e10cSrcweir 	SCCOL	nX2 = nX1 + pViewData->VisibleCellsX( eHWhich );
4456cdf0e10cSrcweir 	SCROW	nY2 = nY1 + pViewData->VisibleCellsY( eVWhich );
4457cdf0e10cSrcweir 
4458cdf0e10cSrcweir 	if (nX2 > MAXCOL) nX2 = MAXCOL;
4459cdf0e10cSrcweir 	if (nY2 > MAXROW) nY2 = MAXROW;
4460cdf0e10cSrcweir 
4461cdf0e10cSrcweir     // Draw( nX1, nY1, nX2, nY2, SC_UPDATE_CHANGED );
4462cdf0e10cSrcweir 
4463cdf0e10cSrcweir     // don't draw directly - instead use OutputData to find changed area and invalidate
4464cdf0e10cSrcweir 
4465cdf0e10cSrcweir     SCROW nPosY = nY1;
4466cdf0e10cSrcweir 
4467cdf0e10cSrcweir     ScDocShell* pDocSh = pViewData->GetDocShell();
4468cdf0e10cSrcweir     ScDocument* pDoc = pDocSh->GetDocument();
4469cdf0e10cSrcweir     SCTAB nTab = pViewData->GetTabNo();
4470cdf0e10cSrcweir 
4471cdf0e10cSrcweir     pDoc->ExtendHidden( nX1, nY1, nX2, nY2, nTab );
4472cdf0e10cSrcweir 
4473cdf0e10cSrcweir     Point aScrPos = pViewData->GetScrPos( nX1, nY1, eWhich );
4474cdf0e10cSrcweir     long nMirrorWidth = GetSizePixel().Width();
4475cdf0e10cSrcweir     sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
4476cdf0e10cSrcweir     // unused variable long nLayoutSign = bLayoutRTL ? -1 : 1;
4477cdf0e10cSrcweir     if ( bLayoutRTL )
4478cdf0e10cSrcweir     {
4479cdf0e10cSrcweir         long nEndPixel = pViewData->GetScrPos( nX2+1, nPosY, eWhich ).X();
4480cdf0e10cSrcweir         nMirrorWidth = aScrPos.X() - nEndPixel;
4481cdf0e10cSrcweir         aScrPos.X() = nEndPixel + 1;
4482cdf0e10cSrcweir     }
4483cdf0e10cSrcweir 
4484cdf0e10cSrcweir     long nScrX = aScrPos.X();
4485cdf0e10cSrcweir     long nScrY = aScrPos.Y();
4486cdf0e10cSrcweir 
4487cdf0e10cSrcweir     double nPPTX = pViewData->GetPPTX();
4488cdf0e10cSrcweir     double nPPTY = pViewData->GetPPTY();
4489cdf0e10cSrcweir 
4490cdf0e10cSrcweir     ScTableInfo aTabInfo;
4491cdf0e10cSrcweir     pDoc->FillInfo( aTabInfo, nX1, nY1, nX2, nY2, nTab, nPPTX, nPPTY, sal_False, sal_False );
4492cdf0e10cSrcweir 
4493cdf0e10cSrcweir     Fraction aZoomX = pViewData->GetZoomX();
4494cdf0e10cSrcweir     Fraction aZoomY = pViewData->GetZoomY();
4495cdf0e10cSrcweir     ScOutputData aOutputData( this, OUTTYPE_WINDOW, aTabInfo, pDoc, nTab,
4496cdf0e10cSrcweir                                 nScrX, nScrY, nX1, nY1, nX2, nY2, nPPTX, nPPTY,
4497cdf0e10cSrcweir                                 &aZoomX, &aZoomY );
4498cdf0e10cSrcweir     aOutputData.SetMirrorWidth( nMirrorWidth );
4499cdf0e10cSrcweir 
4500cdf0e10cSrcweir     aOutputData.FindChanged();
4501cdf0e10cSrcweir 
4502d8ed516eSArmin Le Grand     // #122149# do not use old GetChangedArea() which used polygon-based Regions, but use
4503d8ed516eSArmin Le Grand     // the region-band based new version; anyways, only rectangles are added
4504d8ed516eSArmin Le Grand     Region aChangedRegion( aOutputData.GetChangedAreaRegion() );   // logic (PixelToLogic)
4505d8ed516eSArmin Le Grand     if(!aChangedRegion.IsEmpty())
4506cdf0e10cSrcweir     {
4507d8ed516eSArmin Le Grand         Invalidate(aChangedRegion);
4508cdf0e10cSrcweir     }
4509cdf0e10cSrcweir 
4510cdf0e10cSrcweir     CheckNeedsRepaint();    // #i90362# used to be called via Draw() - still needed here
4511cdf0e10cSrcweir }
4512cdf0e10cSrcweir 
4513cdf0e10cSrcweir void ScGridWindow::UpdateAutoFillMark(sal_Bool bMarked, const ScRange& rMarkRange)
4514cdf0e10cSrcweir {
4515cdf0e10cSrcweir 	if ( bMarked != bAutoMarkVisible || ( bMarked && rMarkRange.aEnd != aAutoMarkPos ) )
4516cdf0e10cSrcweir 	{
4517cdf0e10cSrcweir 		HideCursor();
4518cdf0e10cSrcweir 		bAutoMarkVisible = bMarked;
4519cdf0e10cSrcweir 		if ( bMarked )
4520cdf0e10cSrcweir 			aAutoMarkPos = rMarkRange.aEnd;
4521cdf0e10cSrcweir 		ShowCursor();
4522cdf0e10cSrcweir 
4523cdf0e10cSrcweir         UpdateAutoFillOverlay();
4524cdf0e10cSrcweir 	}
4525cdf0e10cSrcweir }
4526cdf0e10cSrcweir 
4527cdf0e10cSrcweir void ScGridWindow::UpdateListValPos( sal_Bool bVisible, const ScAddress& rPos )
4528cdf0e10cSrcweir {
4529cdf0e10cSrcweir     sal_Bool bOldButton = bListValButton;
4530cdf0e10cSrcweir     ScAddress aOldPos = aListValPos;
4531cdf0e10cSrcweir 
4532cdf0e10cSrcweir     bListValButton = bVisible;
4533cdf0e10cSrcweir     aListValPos = rPos;
4534cdf0e10cSrcweir 
4535cdf0e10cSrcweir     if ( bListValButton )
4536cdf0e10cSrcweir     {
4537cdf0e10cSrcweir         if ( !bOldButton || aListValPos != aOldPos )
4538cdf0e10cSrcweir         {
4539cdf0e10cSrcweir             // paint area of new button
4540cdf0e10cSrcweir             Invalidate( PixelToLogic( GetListValButtonRect( aListValPos ) ) );
4541cdf0e10cSrcweir         }
4542cdf0e10cSrcweir     }
4543cdf0e10cSrcweir     if ( bOldButton )
4544cdf0e10cSrcweir     {
4545cdf0e10cSrcweir         if ( !bListValButton || aListValPos != aOldPos )
4546cdf0e10cSrcweir         {
4547cdf0e10cSrcweir             // paint area of old button
4548cdf0e10cSrcweir             Invalidate( PixelToLogic( GetListValButtonRect( aOldPos ) ) );
4549cdf0e10cSrcweir         }
4550cdf0e10cSrcweir     }
4551cdf0e10cSrcweir }
4552cdf0e10cSrcweir 
4553cdf0e10cSrcweir void ScGridWindow::HideCursor()
4554cdf0e10cSrcweir {
4555cdf0e10cSrcweir 	++nCursorHideCount;
4556cdf0e10cSrcweir 	if (nCursorHideCount==1)
4557cdf0e10cSrcweir 	{
4558cdf0e10cSrcweir 		DrawCursor();
4559cdf0e10cSrcweir 		DrawAutoFillMark();
4560cdf0e10cSrcweir 	}
4561cdf0e10cSrcweir }
4562cdf0e10cSrcweir 
4563cdf0e10cSrcweir void ScGridWindow::ShowCursor()
4564cdf0e10cSrcweir {
4565cdf0e10cSrcweir 	if (nCursorHideCount==0)
4566cdf0e10cSrcweir 	{
4567cdf0e10cSrcweir 		DBG_ERROR("zuviel ShowCursor");
4568cdf0e10cSrcweir 		return;
4569cdf0e10cSrcweir 	}
4570cdf0e10cSrcweir 
4571cdf0e10cSrcweir     if (nCursorHideCount==1)
4572cdf0e10cSrcweir     {
4573cdf0e10cSrcweir         // #i57745# Draw the cursor before setting the variable, in case the
4574cdf0e10cSrcweir         // GetSizePixel call from drawing causes a repaint (resize handler is called)
4575cdf0e10cSrcweir         DrawAutoFillMark();
4576cdf0e10cSrcweir         DrawCursor();
4577cdf0e10cSrcweir     }
4578cdf0e10cSrcweir 
4579cdf0e10cSrcweir 	--nCursorHideCount;
4580cdf0e10cSrcweir }
4581cdf0e10cSrcweir 
4582cdf0e10cSrcweir void __EXPORT ScGridWindow::GetFocus()
4583cdf0e10cSrcweir {
4584cdf0e10cSrcweir 	ScTabViewShell* pViewShell = pViewData->GetViewShell();
4585cdf0e10cSrcweir 	pViewShell->GotFocus();
4586cdf0e10cSrcweir     pViewShell->SetFormShellAtTop( sal_False );     // focus in GridWindow -> FormShell no longer on top
4587cdf0e10cSrcweir 
4588cdf0e10cSrcweir     if (pViewShell->HasAccessibilityObjects())
4589cdf0e10cSrcweir 		pViewShell->BroadcastAccessibility(ScAccGridWinFocusGotHint(eWhich, GetAccessible()));
4590cdf0e10cSrcweir 
4591cdf0e10cSrcweir 
4592cdf0e10cSrcweir 	if ( !SC_MOD()->IsFormulaMode() )
4593cdf0e10cSrcweir 	{
4594cdf0e10cSrcweir 		pViewShell->UpdateInputHandler();
4595cdf0e10cSrcweir //		StopMarking();		// falls Dialog (Fehler), weil dann kein ButtonUp
4596cdf0e10cSrcweir 							// MO: nur wenn nicht im RefInput-Modus
4597cdf0e10cSrcweir 							//     -> GetFocus/MouseButtonDown-Reihenfolge
4598cdf0e10cSrcweir 							//		  auf dem Mac
4599cdf0e10cSrcweir 	}
4600cdf0e10cSrcweir 
4601cdf0e10cSrcweir 	Window::GetFocus();
4602cdf0e10cSrcweir }
4603cdf0e10cSrcweir 
4604cdf0e10cSrcweir void __EXPORT ScGridWindow::LoseFocus()
4605cdf0e10cSrcweir {
4606cdf0e10cSrcweir 	ScTabViewShell* pViewShell = pViewData->GetViewShell();
4607cdf0e10cSrcweir 	pViewShell->LostFocus();
4608cdf0e10cSrcweir 
4609cdf0e10cSrcweir     if (pViewShell->HasAccessibilityObjects())
4610cdf0e10cSrcweir 		pViewShell->BroadcastAccessibility(ScAccGridWinFocusLostHint(eWhich, GetAccessible()));
4611cdf0e10cSrcweir 
4612cdf0e10cSrcweir 	Window::LoseFocus();
4613cdf0e10cSrcweir }
4614cdf0e10cSrcweir 
4615cdf0e10cSrcweir Point ScGridWindow::GetMousePosPixel() const  { return aCurMousePos; }
4616cdf0e10cSrcweir 
4617cdf0e10cSrcweir //------------------------------------------------------------------------
4618cdf0e10cSrcweir 
4619cdf0e10cSrcweir sal_Bool ScGridWindow::HitRangeFinder( const Point& rMouse, sal_Bool& rCorner,
4620cdf0e10cSrcweir 								sal_uInt16* pIndex, SCsCOL* pAddX, SCsROW* pAddY )
4621cdf0e10cSrcweir {
4622cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
4623cdf0e10cSrcweir 	ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pViewData->GetViewShell() );
4624cdf0e10cSrcweir 	if (pHdl)
4625cdf0e10cSrcweir 	{
4626cdf0e10cSrcweir 		ScRangeFindList* pRangeFinder = pHdl->GetRangeFindList();
4627cdf0e10cSrcweir 		if ( pRangeFinder && !pRangeFinder->IsHidden() &&
4628cdf0e10cSrcweir 				pRangeFinder->GetDocName() == pViewData->GetDocShell()->GetTitle() )
4629cdf0e10cSrcweir 		{
4630cdf0e10cSrcweir 			ScDocument* pDoc = pViewData->GetDocument();
4631cdf0e10cSrcweir 			SCTAB nTab = pViewData->GetTabNo();
4632cdf0e10cSrcweir 			sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
4633cdf0e10cSrcweir 			long nLayoutSign = bLayoutRTL ? -1 : 1;
4634cdf0e10cSrcweir 
4635cdf0e10cSrcweir             SCsCOL nPosX;
4636cdf0e10cSrcweir             SCsROW nPosY;
4637cdf0e10cSrcweir 			pViewData->GetPosFromPixel( rMouse.X(), rMouse.Y(), eWhich, nPosX, nPosY );
4638cdf0e10cSrcweir 			//	zusammengefasste (einzeln/Bereich) ???
4639cdf0e10cSrcweir 			ScAddress aAddr( nPosX, nPosY, nTab );
4640cdf0e10cSrcweir 
4641cdf0e10cSrcweir //			Point aNext = pViewData->GetScrPos( nPosX+1, nPosY+1, eWhich );
4642cdf0e10cSrcweir 
4643cdf0e10cSrcweir 			Point aNext = pViewData->GetScrPos( nPosX, nPosY, eWhich, sal_True );
4644cdf0e10cSrcweir 			long nSizeXPix;
4645cdf0e10cSrcweir 			long nSizeYPix;
4646cdf0e10cSrcweir 			pViewData->GetMergeSizePixel( nPosX, nPosY, nSizeXPix, nSizeYPix );
4647cdf0e10cSrcweir 			aNext.X() += nSizeXPix * nLayoutSign;
4648cdf0e10cSrcweir 			aNext.Y() += nSizeYPix;
4649cdf0e10cSrcweir 
4650cdf0e10cSrcweir 			sal_Bool bCornerHor;
4651cdf0e10cSrcweir 			if ( bLayoutRTL )
4652cdf0e10cSrcweir 				bCornerHor = ( rMouse.X() >= aNext.X() && rMouse.X() <= aNext.X() + 8 );
4653cdf0e10cSrcweir 			else
4654cdf0e10cSrcweir 				bCornerHor = ( rMouse.X() >= aNext.X() - 8 && rMouse.X() <= aNext.X() );
4655cdf0e10cSrcweir 
4656cdf0e10cSrcweir 			sal_Bool bCellCorner = ( bCornerHor &&
4657cdf0e10cSrcweir 								 rMouse.Y() >= aNext.Y() - 8 && rMouse.Y() <= aNext.Y() );
4658cdf0e10cSrcweir 			//	corner is hit only if the mouse is within the cell
4659cdf0e10cSrcweir 
4660cdf0e10cSrcweir 			sal_uInt16 nCount = (sal_uInt16)pRangeFinder->Count();
4661cdf0e10cSrcweir 			for (sal_uInt16 i=nCount; i;)
4662cdf0e10cSrcweir 			{
4663cdf0e10cSrcweir 				//	rueckwaerts suchen, damit der zuletzt gepaintete Rahmen gefunden wird
4664cdf0e10cSrcweir 				--i;
4665cdf0e10cSrcweir 				ScRangeFindData* pData = pRangeFinder->GetObject(i);
4666cdf0e10cSrcweir 				if ( pData && pData->aRef.In(aAddr) )
4667cdf0e10cSrcweir 				{
4668cdf0e10cSrcweir 					if (pIndex)	*pIndex = i;
4669cdf0e10cSrcweir 					if (pAddX)	*pAddX = nPosX - pData->aRef.aStart.Col();
4670cdf0e10cSrcweir 					if (pAddY)	*pAddY = nPosY - pData->aRef.aStart.Row();
4671cdf0e10cSrcweir 					bFound = sal_True;
4672cdf0e10cSrcweir 					rCorner = ( bCellCorner && aAddr == pData->aRef.aEnd );
4673cdf0e10cSrcweir 					break;
4674cdf0e10cSrcweir 				}
4675cdf0e10cSrcweir 			}
4676cdf0e10cSrcweir 		}
4677cdf0e10cSrcweir 	}
4678cdf0e10cSrcweir 	return bFound;
4679cdf0e10cSrcweir }
4680cdf0e10cSrcweir 
4681cdf0e10cSrcweir #define SCE_TOP		1
4682cdf0e10cSrcweir #define SCE_BOTTOM	2
4683cdf0e10cSrcweir #define SCE_LEFT	4
4684cdf0e10cSrcweir #define SCE_RIGHT	8
4685cdf0e10cSrcweir #define SCE_ALL		15
4686cdf0e10cSrcweir 
4687cdf0e10cSrcweir void lcl_PaintOneRange( ScDocShell* pDocSh, const ScRange& rRange, sal_uInt16 nEdges )
4688cdf0e10cSrcweir {
4689cdf0e10cSrcweir 	//	der Range ist immer richtigherum
4690cdf0e10cSrcweir 
4691cdf0e10cSrcweir 	SCCOL nCol1 = rRange.aStart.Col();
4692cdf0e10cSrcweir 	SCROW nRow1 = rRange.aStart.Row();
4693cdf0e10cSrcweir 	SCTAB nTab1 = rRange.aStart.Tab();
4694cdf0e10cSrcweir 	SCCOL nCol2 = rRange.aEnd.Col();
4695cdf0e10cSrcweir 	SCROW nRow2 = rRange.aEnd.Row();
4696cdf0e10cSrcweir 	SCTAB nTab2 = rRange.aEnd.Tab();
4697cdf0e10cSrcweir 	sal_Bool bHiddenEdge = sal_False;
4698cdf0e10cSrcweir     SCROW nTmp;
4699cdf0e10cSrcweir 
4700cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
4701cdf0e10cSrcweir     while ( nCol1 > 0 && pDoc->ColHidden(nCol1, nTab1) )
4702cdf0e10cSrcweir 	{
4703cdf0e10cSrcweir 		--nCol1;
4704cdf0e10cSrcweir 		bHiddenEdge = sal_True;
4705cdf0e10cSrcweir 	}
4706cdf0e10cSrcweir     while ( nCol2 < MAXCOL && pDoc->ColHidden(nCol2, nTab1) )
4707cdf0e10cSrcweir 	{
4708cdf0e10cSrcweir 		++nCol2;
4709cdf0e10cSrcweir 		bHiddenEdge = sal_True;
4710cdf0e10cSrcweir 	}
4711cdf0e10cSrcweir     nTmp = pDoc->FirstVisibleRow(0, nRow1, nTab1);
4712cdf0e10cSrcweir     if (!ValidRow(nTmp))
4713cdf0e10cSrcweir         nTmp = 0;
4714cdf0e10cSrcweir     if (nTmp < nRow1)
4715cdf0e10cSrcweir     {
4716cdf0e10cSrcweir         nRow1 = nTmp;
4717cdf0e10cSrcweir         bHiddenEdge = sal_True;
4718cdf0e10cSrcweir     }
4719cdf0e10cSrcweir     nTmp = pDoc->FirstVisibleRow(nRow2, MAXROW, nTab1);
4720cdf0e10cSrcweir     if (!ValidRow(nTmp))
4721cdf0e10cSrcweir         nTmp = MAXROW;
4722cdf0e10cSrcweir     if (nTmp > nRow2)
4723cdf0e10cSrcweir     {
4724cdf0e10cSrcweir         nRow2 = nTmp;
4725cdf0e10cSrcweir         bHiddenEdge = sal_True;
4726cdf0e10cSrcweir     }
4727cdf0e10cSrcweir 
4728cdf0e10cSrcweir 	if ( nCol2 > nCol1 + 1 && nRow2 > nRow1 + 1 && !bHiddenEdge )
4729cdf0e10cSrcweir 	{
4730cdf0e10cSrcweir 		//	nur an den Raendern entlang
4731cdf0e10cSrcweir 		//	(die Ecken werden evtl. zweimal getroffen)
4732cdf0e10cSrcweir 
4733cdf0e10cSrcweir 		if ( nEdges & SCE_TOP )
4734cdf0e10cSrcweir 			pDocSh->PostPaint( nCol1, nRow1, nTab1, nCol2, nRow1, nTab2, PAINT_MARKS );
4735cdf0e10cSrcweir 		if ( nEdges & SCE_LEFT )
4736cdf0e10cSrcweir 			pDocSh->PostPaint( nCol1, nRow1, nTab1, nCol1, nRow2, nTab2, PAINT_MARKS );
4737cdf0e10cSrcweir 		if ( nEdges & SCE_RIGHT )
4738cdf0e10cSrcweir 			pDocSh->PostPaint( nCol2, nRow1, nTab1, nCol2, nRow2, nTab2, PAINT_MARKS );
4739cdf0e10cSrcweir 		if ( nEdges & SCE_BOTTOM )
4740cdf0e10cSrcweir 			pDocSh->PostPaint( nCol1, nRow2, nTab1, nCol2, nRow2, nTab2, PAINT_MARKS );
4741cdf0e10cSrcweir 	}
4742cdf0e10cSrcweir 	else	// everything in one call
4743cdf0e10cSrcweir 		pDocSh->PostPaint( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2, PAINT_MARKS );
4744cdf0e10cSrcweir }
4745cdf0e10cSrcweir 
4746cdf0e10cSrcweir void lcl_PaintRefChanged( ScDocShell* pDocSh, const ScRange& rOldUn, const ScRange& rNewUn )
4747cdf0e10cSrcweir {
4748cdf0e10cSrcweir 	//	Repaint fuer die Teile des Rahmens in Old, die bei New nicht mehr da sind
4749cdf0e10cSrcweir 
4750cdf0e10cSrcweir 	ScRange aOld = rOldUn;
4751cdf0e10cSrcweir 	ScRange aNew = rNewUn;
4752cdf0e10cSrcweir 	aOld.Justify();
4753cdf0e10cSrcweir 	aNew.Justify();
4754cdf0e10cSrcweir 
4755cdf0e10cSrcweir 	if ( aOld.aStart == aOld.aEnd )					//! Tab ignorieren?
4756cdf0e10cSrcweir 		pDocSh->GetDocument()->ExtendMerge(aOld);
4757cdf0e10cSrcweir 	if ( aNew.aStart == aNew.aEnd )					//! Tab ignorieren?
4758cdf0e10cSrcweir 		pDocSh->GetDocument()->ExtendMerge(aNew);
4759cdf0e10cSrcweir 
4760cdf0e10cSrcweir 	SCCOL nOldCol1 = aOld.aStart.Col();
4761cdf0e10cSrcweir 	SCROW nOldRow1 = aOld.aStart.Row();
4762cdf0e10cSrcweir 	SCCOL nOldCol2 = aOld.aEnd.Col();
4763cdf0e10cSrcweir 	SCROW nOldRow2 = aOld.aEnd.Row();
4764cdf0e10cSrcweir 	SCCOL nNewCol1 = aNew.aStart.Col();
4765cdf0e10cSrcweir 	SCROW nNewRow1 = aNew.aStart.Row();
4766cdf0e10cSrcweir 	SCCOL nNewCol2 = aNew.aEnd.Col();
4767cdf0e10cSrcweir 	SCROW nNewRow2 = aNew.aEnd.Row();
4768cdf0e10cSrcweir 	SCTAB nTab1 = aOld.aStart.Tab();		// Tab aendert sich nicht
4769cdf0e10cSrcweir 	SCTAB nTab2 = aOld.aEnd.Tab();
4770cdf0e10cSrcweir 
4771cdf0e10cSrcweir 	if ( nNewRow2 < nOldRow1 || nNewRow1 > nOldRow2 ||
4772cdf0e10cSrcweir 		 nNewCol2 < nOldCol1 || nNewCol1 > nOldCol2 ||
4773cdf0e10cSrcweir 		 ( nNewCol1 != nOldCol1 && nNewRow1 != nOldRow1 &&
4774cdf0e10cSrcweir 		   nNewCol2 != nOldCol2 && nNewRow2 != nOldRow2 ) )
4775cdf0e10cSrcweir 	{
4776cdf0e10cSrcweir 		//	komplett weggeschoben oder alle Seiten veraendert
4777cdf0e10cSrcweir 		//	(Abfrage <= statt < geht schief bei einzelnen Zeilen/Spalten)
4778cdf0e10cSrcweir 
4779cdf0e10cSrcweir 		lcl_PaintOneRange( pDocSh, aOld, SCE_ALL );
4780cdf0e10cSrcweir 	}
4781cdf0e10cSrcweir 	else		//	alle vier Kanten einzeln testen
4782cdf0e10cSrcweir 	{
4783cdf0e10cSrcweir 		//	oberer Teil
4784cdf0e10cSrcweir 		if ( nNewRow1 < nOldRow1 )					//	nur obere Linie loeschen
4785cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4786cdf0e10cSrcweir 					nOldCol1, nOldRow1, nTab1, nOldCol2, nOldRow1, nTab2 ), SCE_ALL );
4787cdf0e10cSrcweir 		else if ( nNewRow1 > nOldRow1 )				//	den Teil, der oben wegkommt
4788cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4789cdf0e10cSrcweir 					nOldCol1, nOldRow1, nTab1, nOldCol2, nNewRow1-1, nTab2 ),
4790cdf0e10cSrcweir 					SCE_ALL &~ SCE_BOTTOM );
4791cdf0e10cSrcweir 
4792cdf0e10cSrcweir 		//	unterer Teil
4793cdf0e10cSrcweir 		if ( nNewRow2 > nOldRow2 )					//	nur untere Linie loeschen
4794cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4795cdf0e10cSrcweir 					nOldCol1, nOldRow2, nTab1, nOldCol2, nOldRow2, nTab2 ), SCE_ALL );
4796cdf0e10cSrcweir 		else if ( nNewRow2 < nOldRow2 )				//	den Teil, der unten wegkommt
4797cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4798cdf0e10cSrcweir 					nOldCol1, nNewRow2+1, nTab1, nOldCol2, nOldRow2, nTab2 ),
4799cdf0e10cSrcweir 					SCE_ALL &~ SCE_TOP );
4800cdf0e10cSrcweir 
4801cdf0e10cSrcweir 		//	linker Teil
4802cdf0e10cSrcweir 		if ( nNewCol1 < nOldCol1 )					//	nur linke Linie loeschen
4803cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4804cdf0e10cSrcweir 					nOldCol1, nOldRow1, nTab1, nOldCol1, nOldRow2, nTab2 ), SCE_ALL );
4805cdf0e10cSrcweir 		else if ( nNewCol1 > nOldCol1 )				//	den Teil, der links wegkommt
4806cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4807cdf0e10cSrcweir 					nOldCol1, nOldRow1, nTab1, nNewCol1-1, nOldRow2, nTab2 ),
4808cdf0e10cSrcweir 					SCE_ALL &~ SCE_RIGHT );
4809cdf0e10cSrcweir 
4810cdf0e10cSrcweir 		//	rechter Teil
4811cdf0e10cSrcweir 		if ( nNewCol2 > nOldCol2 )					//	nur rechte Linie loeschen
4812cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4813cdf0e10cSrcweir 					nOldCol2, nOldRow1, nTab1, nOldCol2, nOldRow2, nTab2 ), SCE_ALL );
4814cdf0e10cSrcweir 		else if ( nNewCol2 < nOldCol2 )				//	den Teil, der rechts wegkommt
4815cdf0e10cSrcweir 			lcl_PaintOneRange( pDocSh, ScRange(
4816cdf0e10cSrcweir 					nNewCol2+1, nOldRow1, nTab1, nOldCol2, nOldRow2, nTab2 ),
4817cdf0e10cSrcweir 					SCE_ALL &~ SCE_LEFT );
4818cdf0e10cSrcweir 	}
4819cdf0e10cSrcweir }
4820cdf0e10cSrcweir 
4821cdf0e10cSrcweir void ScGridWindow::RFMouseMove( const MouseEvent& rMEvt, sal_Bool bUp )
4822cdf0e10cSrcweir {
4823cdf0e10cSrcweir 	ScInputHandler* pHdl = SC_MOD()->GetInputHdl( pViewData->GetViewShell() );
4824cdf0e10cSrcweir 	if (!pHdl)
4825cdf0e10cSrcweir 		return;
4826cdf0e10cSrcweir 	ScRangeFindList* pRangeFinder = pHdl->GetRangeFindList();
4827cdf0e10cSrcweir 	if (!pRangeFinder || nRFIndex >= pRangeFinder->Count())
4828cdf0e10cSrcweir 		return;
4829cdf0e10cSrcweir 	ScRangeFindData* pData = pRangeFinder->GetObject( nRFIndex );
4830cdf0e10cSrcweir 	if (!pData)
4831cdf0e10cSrcweir 		return;
4832cdf0e10cSrcweir 
4833cdf0e10cSrcweir 	//	Mauszeiger
4834cdf0e10cSrcweir 
4835cdf0e10cSrcweir 	if (bRFSize)
4836cdf0e10cSrcweir 		SetPointer( Pointer( POINTER_CROSS ) );
4837cdf0e10cSrcweir 	else
4838cdf0e10cSrcweir 		SetPointer( Pointer( POINTER_HAND ) );
4839cdf0e10cSrcweir 
4840cdf0e10cSrcweir 	//	Scrolling
4841cdf0e10cSrcweir 
4842cdf0e10cSrcweir 	sal_Bool bTimer = sal_False;
4843cdf0e10cSrcweir 	Point aPos = rMEvt.GetPosPixel();
4844cdf0e10cSrcweir 	SCsCOL nDx = 0;
4845cdf0e10cSrcweir 	SCsROW nDy = 0;
4846cdf0e10cSrcweir 	if ( aPos.X() < 0 ) nDx = -1;
4847cdf0e10cSrcweir 	if ( aPos.Y() < 0 ) nDy = -1;
4848cdf0e10cSrcweir 	Size aSize = GetOutputSizePixel();
4849cdf0e10cSrcweir 	if ( aPos.X() >= aSize.Width() )
4850cdf0e10cSrcweir 		nDx = 1;
4851cdf0e10cSrcweir 	if ( aPos.Y() >= aSize.Height() )
4852cdf0e10cSrcweir 		nDy = 1;
4853cdf0e10cSrcweir 	if ( nDx != 0 || nDy != 0 )
4854cdf0e10cSrcweir 	{
4855cdf0e10cSrcweir 		if ( nDx != 0) pViewData->GetView()->ScrollX( nDx, WhichH(eWhich) );
4856cdf0e10cSrcweir 		if ( nDy != 0 ) pViewData->GetView()->ScrollY( nDy, WhichV(eWhich) );
4857cdf0e10cSrcweir 		bTimer = sal_True;
4858cdf0e10cSrcweir 	}
4859cdf0e10cSrcweir 
4860cdf0e10cSrcweir 	//	Umschalten bei Fixierung (damit Scrolling funktioniert)
4861cdf0e10cSrcweir 
4862cdf0e10cSrcweir 	if ( eWhich == pViewData->GetActivePart() )		//??
4863cdf0e10cSrcweir 	{
4864cdf0e10cSrcweir 		if ( pViewData->GetHSplitMode() == SC_SPLIT_FIX )
4865cdf0e10cSrcweir 			if ( nDx > 0 )
4866cdf0e10cSrcweir 			{
4867cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
4868cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_TOPRIGHT );
4869cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_BOTTOMLEFT )
4870cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT );
4871cdf0e10cSrcweir 			}
4872cdf0e10cSrcweir 
4873cdf0e10cSrcweir 		if ( pViewData->GetVSplitMode() == SC_SPLIT_FIX )
4874cdf0e10cSrcweir 			if ( nDy > 0 )
4875cdf0e10cSrcweir 			{
4876cdf0e10cSrcweir 				if ( eWhich == SC_SPLIT_TOPLEFT )
4877cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMLEFT );
4878cdf0e10cSrcweir 				else if ( eWhich == SC_SPLIT_TOPRIGHT )
4879cdf0e10cSrcweir 					pViewData->GetView()->ActivatePart( SC_SPLIT_BOTTOMRIGHT );
4880cdf0e10cSrcweir 			}
4881cdf0e10cSrcweir 	}
4882cdf0e10cSrcweir 
4883cdf0e10cSrcweir 	//	Verschieben
4884cdf0e10cSrcweir 
4885cdf0e10cSrcweir 	SCsCOL	nPosX;
4886cdf0e10cSrcweir 	SCsROW	nPosY;
4887cdf0e10cSrcweir 	pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
4888cdf0e10cSrcweir 
4889cdf0e10cSrcweir 	ScRange aOld = pData->aRef;
4890cdf0e10cSrcweir 	ScRange aNew = aOld;
4891cdf0e10cSrcweir 	if ( bRFSize )
4892cdf0e10cSrcweir 	{
4893cdf0e10cSrcweir 		aNew.aEnd.SetCol((SCCOL)nPosX);
4894cdf0e10cSrcweir 		aNew.aEnd.SetRow((SCROW)nPosY);
4895cdf0e10cSrcweir 	}
4896cdf0e10cSrcweir 	else
4897cdf0e10cSrcweir 	{
4898cdf0e10cSrcweir 		long nStartX = nPosX - nRFAddX;
4899cdf0e10cSrcweir 		if ( nStartX < 0 ) nStartX = 0;
4900cdf0e10cSrcweir 		long nStartY = nPosY - nRFAddY;
4901cdf0e10cSrcweir 		if ( nStartY < 0 ) nStartY = 0;
4902cdf0e10cSrcweir 		long nEndX = nStartX + aOld.aEnd.Col() - aOld.aStart.Col();
4903cdf0e10cSrcweir 		if ( nEndX > MAXCOL )
4904cdf0e10cSrcweir 		{
4905cdf0e10cSrcweir 			nStartX -= ( nEndX - MAXROW );
4906cdf0e10cSrcweir 			nEndX = MAXCOL;
4907cdf0e10cSrcweir 		}
4908cdf0e10cSrcweir 		long nEndY = nStartY + aOld.aEnd.Row() - aOld.aStart.Row();
4909cdf0e10cSrcweir 		if ( nEndY > MAXROW )
4910cdf0e10cSrcweir 		{
4911cdf0e10cSrcweir 			nStartY -= ( nEndY - MAXROW );
4912cdf0e10cSrcweir 			nEndY = MAXROW;
4913cdf0e10cSrcweir 		}
4914cdf0e10cSrcweir 
4915cdf0e10cSrcweir 		aNew.aStart.SetCol((SCCOL)nStartX);
4916cdf0e10cSrcweir 		aNew.aStart.SetRow((SCROW)nStartY);
4917cdf0e10cSrcweir 		aNew.aEnd.SetCol((SCCOL)nEndX);
4918cdf0e10cSrcweir 		aNew.aEnd.SetRow((SCROW)nEndY);
4919cdf0e10cSrcweir 	}
4920cdf0e10cSrcweir 
4921cdf0e10cSrcweir 	if ( bUp )
4922cdf0e10cSrcweir 		aNew.Justify();				// beim ButtonUp wieder richtigherum
4923cdf0e10cSrcweir 
4924cdf0e10cSrcweir 	if ( aNew != aOld )
4925cdf0e10cSrcweir 	{
4926cdf0e10cSrcweir 		pHdl->UpdateRange( nRFIndex, aNew );
4927cdf0e10cSrcweir 
4928cdf0e10cSrcweir 		ScDocShell* pDocSh = pViewData->GetDocShell();
4929cdf0e10cSrcweir 
4930cdf0e10cSrcweir 		//	nur das neuzeichnen, was sich veraendert hat...
4931cdf0e10cSrcweir 		lcl_PaintRefChanged( pDocSh, aOld, aNew );
4932cdf0e10cSrcweir 
4933cdf0e10cSrcweir 		//	neuen Rahmen nur drueberzeichnen (synchron)
4934cdf0e10cSrcweir 		pDocSh->Broadcast( ScIndexHint( SC_HINT_SHOWRANGEFINDER, nRFIndex ) );
4935cdf0e10cSrcweir 
4936cdf0e10cSrcweir 		Update();	// was man bewegt, will man auch sofort sehen
4937cdf0e10cSrcweir 	}
4938cdf0e10cSrcweir 
4939cdf0e10cSrcweir 	//	Timer fuer Scrolling
4940cdf0e10cSrcweir 
4941cdf0e10cSrcweir 	if (bTimer)
4942cdf0e10cSrcweir 		pViewData->GetView()->SetTimer( this, rMEvt );			// Event wiederholen
4943cdf0e10cSrcweir 	else
4944cdf0e10cSrcweir 		pViewData->GetView()->ResetTimer();
4945cdf0e10cSrcweir }
4946cdf0e10cSrcweir 
4947cdf0e10cSrcweir //------------------------------------------------------------------------
4948cdf0e10cSrcweir 
4949cdf0e10cSrcweir sal_Bool ScGridWindow::GetEditUrl( const Point& rPos,
4950cdf0e10cSrcweir 								String* pName, String* pUrl, String* pTarget )
4951cdf0e10cSrcweir {
4952cdf0e10cSrcweir 	return GetEditUrlOrError( sal_False, rPos, pName, pUrl, pTarget );
4953cdf0e10cSrcweir }
4954cdf0e10cSrcweir 
4955cdf0e10cSrcweir sal_Bool ScGridWindow::GetEditUrlOrError( sal_Bool bSpellErr, const Point& rPos,
4956cdf0e10cSrcweir 								String* pName, String* pUrl, String* pTarget )
4957cdf0e10cSrcweir {
4958cdf0e10cSrcweir 	//!	nPosX/Y mit uebergeben?
4959cdf0e10cSrcweir 	SCsCOL nPosX;
4960cdf0e10cSrcweir 	SCsROW nPosY;
4961cdf0e10cSrcweir 	pViewData->GetPosFromPixel( rPos.X(), rPos.Y(), eWhich, nPosX, nPosY );
4962cdf0e10cSrcweir 
4963cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
4964cdf0e10cSrcweir 	ScDocShell* pDocSh = pViewData->GetDocShell();
4965cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
4966cdf0e10cSrcweir 	ScBaseCell* pCell = NULL;
4967cdf0e10cSrcweir 
4968cdf0e10cSrcweir 	sal_Bool bFound = lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell );
4969cdf0e10cSrcweir 	if( !bFound )
4970cdf0e10cSrcweir 		return sal_False;
4971cdf0e10cSrcweir 
4972cdf0e10cSrcweir 	ScHideTextCursor aHideCursor( pViewData, eWhich );	// before GetEditArea (MapMode is changed)
4973cdf0e10cSrcweir 
4974cdf0e10cSrcweir 	const ScPatternAttr* pPattern = pDoc->GetPattern( nPosX, nPosY, nTab );
4975cdf0e10cSrcweir 	// bForceToTop = sal_False, use the cell's real position
4976cdf0e10cSrcweir 	Rectangle aEditRect = pViewData->GetEditArea( eWhich, nPosX, nPosY, this, pPattern, sal_False );
4977cdf0e10cSrcweir 	if (rPos.Y() < aEditRect.Top())
4978cdf0e10cSrcweir 		return sal_False;
4979cdf0e10cSrcweir 
4980cdf0e10cSrcweir 		//	vertikal kann (noch) nicht angeklickt werden:
4981cdf0e10cSrcweir 
4982cdf0e10cSrcweir     if (pPattern->GetCellOrientation() != SVX_ORIENTATION_STANDARD)
4983cdf0e10cSrcweir 		return sal_False;
4984cdf0e10cSrcweir 
4985cdf0e10cSrcweir 	sal_Bool bBreak = ((SfxBoolItem&)pPattern->GetItem(ATTR_LINEBREAK)).GetValue() ||
4986cdf0e10cSrcweir 					((SvxCellHorJustify)((const SvxHorJustifyItem&)pPattern->
4987cdf0e10cSrcweir 						GetItem( ATTR_HOR_JUSTIFY )).GetValue() == SVX_HOR_JUSTIFY_BLOCK);
4988cdf0e10cSrcweir 	SvxCellHorJustify eHorJust = (SvxCellHorJustify)((SvxHorJustifyItem&)pPattern->
4989cdf0e10cSrcweir 						GetItem(ATTR_HOR_JUSTIFY)).GetValue();
4990cdf0e10cSrcweir 
4991cdf0e10cSrcweir 		//	EditEngine
4992cdf0e10cSrcweir 
4993cdf0e10cSrcweir 	ScFieldEditEngine aEngine( pDoc->GetEditPool() );
4994cdf0e10cSrcweir 	ScSizeDeviceProvider aProv(pDocSh);
4995cdf0e10cSrcweir 	aEngine.SetRefDevice( aProv.GetDevice() );
4996cdf0e10cSrcweir 	aEngine.SetRefMapMode( MAP_100TH_MM );
4997cdf0e10cSrcweir 	SfxItemSet aDefault( aEngine.GetEmptyItemSet() );
4998cdf0e10cSrcweir 	pPattern->FillEditItemSet( &aDefault );
4999cdf0e10cSrcweir 	SvxAdjust eSvxAdjust = SVX_ADJUST_LEFT;
5000cdf0e10cSrcweir 	switch (eHorJust)
5001cdf0e10cSrcweir 	{
5002cdf0e10cSrcweir 		case SVX_HOR_JUSTIFY_LEFT:
5003cdf0e10cSrcweir 		case SVX_HOR_JUSTIFY_REPEAT:			// nicht implementiert
5004cdf0e10cSrcweir 		case SVX_HOR_JUSTIFY_STANDARD:			// always Text if an EditCell type
5005cdf0e10cSrcweir                 eSvxAdjust = SVX_ADJUST_LEFT;
5006cdf0e10cSrcweir 				break;
5007cdf0e10cSrcweir 		case SVX_HOR_JUSTIFY_RIGHT:
5008cdf0e10cSrcweir 				eSvxAdjust = SVX_ADJUST_RIGHT;
5009cdf0e10cSrcweir 				break;
5010cdf0e10cSrcweir 		case SVX_HOR_JUSTIFY_CENTER:
5011cdf0e10cSrcweir 				eSvxAdjust = SVX_ADJUST_CENTER;
5012cdf0e10cSrcweir 				break;
5013cdf0e10cSrcweir 		case SVX_HOR_JUSTIFY_BLOCK:
5014cdf0e10cSrcweir 				eSvxAdjust = SVX_ADJUST_BLOCK;
5015cdf0e10cSrcweir 				break;
5016cdf0e10cSrcweir 	}
5017cdf0e10cSrcweir     aDefault.Put( SvxAdjustItem( eSvxAdjust, EE_PARA_JUST ) );
5018cdf0e10cSrcweir 	aEngine.SetDefaults( aDefault );
5019cdf0e10cSrcweir 	if (bSpellErr)
5020cdf0e10cSrcweir 		aEngine.SetControlWord( aEngine.GetControlWord() | EE_CNTRL_ONLINESPELLING );
5021cdf0e10cSrcweir 
5022cdf0e10cSrcweir 	MapMode aEditMode = pViewData->GetLogicMode(eWhich);			// ohne Drawing-Skalierung
5023cdf0e10cSrcweir 	Rectangle aLogicEdit = PixelToLogic( aEditRect, aEditMode );
5024cdf0e10cSrcweir 	long nThisColLogic = aLogicEdit.Right() - aLogicEdit.Left() + 1;
5025cdf0e10cSrcweir     Size aPaperSize = Size( 1000000, 1000000 );
5026cdf0e10cSrcweir     if(pCell->GetCellType() == CELLTYPE_FORMULA)
5027cdf0e10cSrcweir     {
5028cdf0e10cSrcweir         long nSizeX  = 0;
5029cdf0e10cSrcweir         long nSizeY  = 0;
5030cdf0e10cSrcweir         pViewData->GetMergeSizePixel( nPosX, nPosY, nSizeX, nSizeY );
5031cdf0e10cSrcweir         aPaperSize = Size(nSizeX, nSizeY );
5032cdf0e10cSrcweir         aPaperSize = PixelToLogic(aPaperSize);
5033cdf0e10cSrcweir     }
5034cdf0e10cSrcweir 
5035cdf0e10cSrcweir 	if (bBreak)
5036cdf0e10cSrcweir 		aPaperSize.Width() = nThisColLogic;
5037cdf0e10cSrcweir 	aEngine.SetPaperSize( aPaperSize );
5038cdf0e10cSrcweir 
5039cdf0e10cSrcweir     ::std::auto_ptr< EditTextObject > pTextObj;
5040cdf0e10cSrcweir     const EditTextObject* pData;
5041cdf0e10cSrcweir     if(pCell->GetCellType() == CELLTYPE_EDIT)
5042cdf0e10cSrcweir     {
5043cdf0e10cSrcweir         ((ScEditCell*)pCell)->GetData(pData);
5044cdf0e10cSrcweir         if (pData)
5045cdf0e10cSrcweir             aEngine.SetText(*pData);
5046cdf0e10cSrcweir     }
5047cdf0e10cSrcweir     else  // HyperLink Formula cell
5048cdf0e10cSrcweir     {
5049cdf0e10cSrcweir         pTextObj.reset((static_cast<ScFormulaCell*>(pCell))->CreateURLObject());
5050cdf0e10cSrcweir         if (pTextObj.get())
5051cdf0e10cSrcweir             aEngine.SetText(*pTextObj);
5052cdf0e10cSrcweir     }
5053cdf0e10cSrcweir 
5054cdf0e10cSrcweir 	long nStartX = aLogicEdit.Left();
5055cdf0e10cSrcweir 
5056cdf0e10cSrcweir         long nTextWidth = aEngine.CalcTextWidth();
5057cdf0e10cSrcweir 	long nTextHeight = aEngine.GetTextHeight();
5058cdf0e10cSrcweir 	if ( nTextWidth < nThisColLogic )
5059cdf0e10cSrcweir 	{
5060cdf0e10cSrcweir 		if (eHorJust == SVX_HOR_JUSTIFY_RIGHT)
5061cdf0e10cSrcweir 			nStartX += nThisColLogic - nTextWidth;
5062cdf0e10cSrcweir 		else if (eHorJust == SVX_HOR_JUSTIFY_CENTER)
5063cdf0e10cSrcweir 			nStartX += (nThisColLogic - nTextWidth) / 2;
5064cdf0e10cSrcweir 	}
5065cdf0e10cSrcweir 
5066cdf0e10cSrcweir 	aLogicEdit.Left() = nStartX;
5067cdf0e10cSrcweir 	if (!bBreak)
5068cdf0e10cSrcweir 		aLogicEdit.Right() = nStartX + nTextWidth;
5069cdf0e10cSrcweir 
5070cdf0e10cSrcweir     // There is one glitch when dealing with a hyperlink cell and
5071cdf0e10cSrcweir     // the cell content is NUMERIC. This defaults to right aligned and
5072cdf0e10cSrcweir     // we need to adjust accordingly.
5073cdf0e10cSrcweir     if(pCell->GetCellType() == CELLTYPE_FORMULA &&
5074cdf0e10cSrcweir         static_cast<ScFormulaCell*>(pCell)->IsValue() &&
5075cdf0e10cSrcweir         eHorJust == SVX_HOR_JUSTIFY_STANDARD)
5076cdf0e10cSrcweir     {
5077cdf0e10cSrcweir         aLogicEdit.Right() = aLogicEdit.Left() + nThisColLogic - 1;
5078cdf0e10cSrcweir         aLogicEdit.Left() =  aLogicEdit.Right() - nTextWidth;
5079cdf0e10cSrcweir     }
5080cdf0e10cSrcweir     aLogicEdit.Bottom() = aLogicEdit.Top() + nTextHeight;
5081cdf0e10cSrcweir 
5082cdf0e10cSrcweir 
5083cdf0e10cSrcweir 	Point aLogicClick = PixelToLogic(rPos,aEditMode);
5084cdf0e10cSrcweir 	if ( aLogicEdit.IsInside(aLogicClick) )
5085cdf0e10cSrcweir 	{
5086cdf0e10cSrcweir //		aEngine.SetUpdateMode(sal_False);
5087cdf0e10cSrcweir 		EditView aTempView( &aEngine, this );
5088cdf0e10cSrcweir 		aTempView.SetOutputArea( aLogicEdit );
5089cdf0e10cSrcweir 
5090cdf0e10cSrcweir 		sal_Bool bRet = sal_False;
5091cdf0e10cSrcweir 		MapMode aOld = GetMapMode();
5092cdf0e10cSrcweir 		SetMapMode(aEditMode);					// kein return mehr
5093cdf0e10cSrcweir 
5094cdf0e10cSrcweir 		if (bSpellErr)							// Spelling-Fehler suchen
5095cdf0e10cSrcweir 		{
5096cdf0e10cSrcweir 			bRet = aTempView.IsWrongSpelledWordAtPos( rPos );
5097cdf0e10cSrcweir 			if ( bRet )
5098cdf0e10cSrcweir 				pViewData->GetView()->SetCursor( nPosX, nPosY );		// Cursor setzen
5099cdf0e10cSrcweir 		}
5100cdf0e10cSrcweir 		else									// URL suchen
5101cdf0e10cSrcweir 		{
5102cdf0e10cSrcweir 			const SvxFieldItem*	pFieldItem = aTempView.GetFieldUnderMousePointer();
5103cdf0e10cSrcweir 
5104cdf0e10cSrcweir 			if (pFieldItem)
5105cdf0e10cSrcweir 			{
5106cdf0e10cSrcweir 				const SvxFieldData* pField = pFieldItem->GetField();
5107cdf0e10cSrcweir 				if ( pField && pField->ISA(SvxURLField) )
5108cdf0e10cSrcweir 				{
5109cdf0e10cSrcweir 					if ( pName || pUrl || pTarget )
5110cdf0e10cSrcweir 					{
5111cdf0e10cSrcweir 						const SvxURLField* pURLField = (const SvxURLField*)pField;
5112cdf0e10cSrcweir 						if (pName)
5113cdf0e10cSrcweir 							*pName = pURLField->GetRepresentation();
5114cdf0e10cSrcweir 						if (pUrl)
5115cdf0e10cSrcweir 							*pUrl = pURLField->GetURL();
5116cdf0e10cSrcweir 						if (pTarget)
5117cdf0e10cSrcweir 							*pTarget = pURLField->GetTargetFrame();
5118cdf0e10cSrcweir 					}
5119cdf0e10cSrcweir 					bRet = sal_True;
5120cdf0e10cSrcweir 				}
5121cdf0e10cSrcweir 			}
5122cdf0e10cSrcweir 		}
5123cdf0e10cSrcweir 
5124cdf0e10cSrcweir 		SetMapMode(aOld);
5125cdf0e10cSrcweir 
5126cdf0e10cSrcweir 		//	text cursor is restored in ScHideTextCursor dtor
5127cdf0e10cSrcweir 
5128cdf0e10cSrcweir 		return bRet;
5129cdf0e10cSrcweir 	}
5130cdf0e10cSrcweir 	return sal_False;
5131cdf0e10cSrcweir }
5132cdf0e10cSrcweir 
5133cdf0e10cSrcweir sal_Bool ScGridWindow::HasScenarioButton( const Point& rPosPixel, ScRange& rScenRange )
5134cdf0e10cSrcweir {
5135cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
5136cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
5137cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
5138cdf0e10cSrcweir 	if ( nTab+1<nTabCount && pDoc->IsScenario(nTab+1) && !pDoc->IsScenario(nTab) )
5139cdf0e10cSrcweir 	{
5140cdf0e10cSrcweir 		sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
5141cdf0e10cSrcweir 
5142cdf0e10cSrcweir 		Size aButSize = pViewData->GetScenButSize();
5143cdf0e10cSrcweir 		long nBWidth  = aButSize.Width();
5144cdf0e10cSrcweir 		if (!nBWidth)
5145cdf0e10cSrcweir 			return sal_False;					// noch kein Button gezeichnet -> da ist auch keiner
5146cdf0e10cSrcweir 		long nBHeight = aButSize.Height();
5147cdf0e10cSrcweir 		long nHSpace  = (long)( SC_SCENARIO_HSPACE * pViewData->GetPPTX() );
5148cdf0e10cSrcweir 
5149cdf0e10cSrcweir 		//!	Ranges an der Table cachen!!!!
5150cdf0e10cSrcweir 
5151cdf0e10cSrcweir 		ScMarkData aMarks;
5152cdf0e10cSrcweir 		for (SCTAB i=nTab+1; i<nTabCount && pDoc->IsScenario(i); i++)
5153cdf0e10cSrcweir 			pDoc->MarkScenario( i, nTab, aMarks, sal_False, SC_SCENARIO_SHOWFRAME );
5154cdf0e10cSrcweir 		ScRangeList aRanges;
5155cdf0e10cSrcweir 		aMarks.FillRangeListWithMarks( &aRanges, sal_False );
5156cdf0e10cSrcweir 
5157cdf0e10cSrcweir 
5158cdf0e10cSrcweir 		sal_uLong nRangeCount = aRanges.Count();
5159cdf0e10cSrcweir 		for (sal_uLong j=0; j<nRangeCount; j++)
5160cdf0e10cSrcweir 		{
5161cdf0e10cSrcweir 			ScRange aRange = *aRanges.GetObject(j);
5162cdf0e10cSrcweir 			//	Szenario-Rahmen immer dann auf zusammengefasste Zellen erweitern, wenn
5163cdf0e10cSrcweir 			//	dadurch keine neuen nicht-ueberdeckten Zellen mit umrandet werden
5164cdf0e10cSrcweir 			pDoc->ExtendTotalMerge( aRange );
5165cdf0e10cSrcweir 
5166cdf0e10cSrcweir 			sal_Bool bTextBelow = ( aRange.aStart.Row() == 0 );
5167cdf0e10cSrcweir 
5168cdf0e10cSrcweir 			Point aButtonPos;
5169cdf0e10cSrcweir 			if ( bTextBelow )
5170cdf0e10cSrcweir 			{
5171cdf0e10cSrcweir 				aButtonPos = pViewData->GetScrPos( aRange.aEnd.Col()+1, aRange.aEnd.Row()+1,
5172cdf0e10cSrcweir 													eWhich, sal_True );
5173cdf0e10cSrcweir 			}
5174cdf0e10cSrcweir 			else
5175cdf0e10cSrcweir 			{
5176cdf0e10cSrcweir 				aButtonPos = pViewData->GetScrPos( aRange.aEnd.Col()+1, aRange.aStart.Row(),
5177cdf0e10cSrcweir 													eWhich, sal_True );
5178cdf0e10cSrcweir 				aButtonPos.Y() -= nBHeight;
5179cdf0e10cSrcweir 			}
5180cdf0e10cSrcweir 			if ( bLayoutRTL )
5181cdf0e10cSrcweir 				aButtonPos.X() -= nHSpace - 1;
5182cdf0e10cSrcweir 			else
5183cdf0e10cSrcweir 				aButtonPos.X() -= nBWidth - nHSpace;	// same for top or bottom
5184cdf0e10cSrcweir 
5185cdf0e10cSrcweir 			Rectangle aButRect( aButtonPos, Size(nBWidth,nBHeight) );
5186cdf0e10cSrcweir 			if ( aButRect.IsInside( rPosPixel ) )
5187cdf0e10cSrcweir 			{
5188cdf0e10cSrcweir 				rScenRange = aRange;
5189cdf0e10cSrcweir 				return sal_True;
5190cdf0e10cSrcweir 			}
5191cdf0e10cSrcweir 		}
5192cdf0e10cSrcweir 	}
5193cdf0e10cSrcweir 
5194cdf0e10cSrcweir 	return sal_False;
5195cdf0e10cSrcweir }
5196cdf0e10cSrcweir 
5197cdf0e10cSrcweir void ScGridWindow::UpdateVisibleRange()
5198cdf0e10cSrcweir {
5199cdf0e10cSrcweir     // #163911# Update the visible range outside of paint (called when switching sheets).
5200cdf0e10cSrcweir     // Use the same logic here as in ScGridWindow::Draw.
5201cdf0e10cSrcweir 
5202cdf0e10cSrcweir     SCCOL nPosX = pViewData->GetPosX( eHWhich );
5203cdf0e10cSrcweir     SCROW nPosY = pViewData->GetPosY( eVWhich );
5204cdf0e10cSrcweir 
5205cdf0e10cSrcweir     SCCOL nXRight = nPosX + pViewData->VisibleCellsX(eHWhich);
5206cdf0e10cSrcweir     if (nXRight > MAXCOL) nXRight = MAXCOL;
5207cdf0e10cSrcweir     SCROW nYBottom = nPosY + pViewData->VisibleCellsY(eVWhich);
5208cdf0e10cSrcweir     if (nYBottom > MAXROW) nYBottom = MAXROW;
5209cdf0e10cSrcweir 
5210cdf0e10cSrcweir     // Store the current visible range.
5211cdf0e10cSrcweir     maVisibleRange.mnCol1 = nPosX;
5212cdf0e10cSrcweir     maVisibleRange.mnCol2 = nXRight;
5213cdf0e10cSrcweir     maVisibleRange.mnRow1 = nPosY;
5214cdf0e10cSrcweir     maVisibleRange.mnRow2 = nYBottom;
5215cdf0e10cSrcweir }
5216cdf0e10cSrcweir 
5217cdf0e10cSrcweir // #114409#
5218cdf0e10cSrcweir void ScGridWindow::DrawLayerCreated()
5219cdf0e10cSrcweir {
5220cdf0e10cSrcweir     SetMapMode( GetDrawMapMode() );
5221cdf0e10cSrcweir 
5222cdf0e10cSrcweir 	// initially create overlay objects
5223cdf0e10cSrcweir 	ImpCreateOverlayObjects();
5224cdf0e10cSrcweir }
5225cdf0e10cSrcweir 
5226cdf0e10cSrcweir // #114409#
5227cdf0e10cSrcweir void ScGridWindow::CursorChanged()
5228cdf0e10cSrcweir {
5229cdf0e10cSrcweir 	// here the created OverlayObjects may be transformed in later versions. For
5230cdf0e10cSrcweir 	// now, just re-create them
5231cdf0e10cSrcweir 
5232cdf0e10cSrcweir 	UpdateCursorOverlay();
5233cdf0e10cSrcweir }
5234cdf0e10cSrcweir 
5235cdf0e10cSrcweir // #114409#
5236cdf0e10cSrcweir void ScGridWindow::ImpCreateOverlayObjects()
5237cdf0e10cSrcweir {
5238cdf0e10cSrcweir     UpdateCursorOverlay();
5239cdf0e10cSrcweir     UpdateSelectionOverlay();
5240cdf0e10cSrcweir     UpdateAutoFillOverlay();
5241cdf0e10cSrcweir     UpdateDragRectOverlay();
5242cdf0e10cSrcweir     UpdateHeaderOverlay();
5243cdf0e10cSrcweir     UpdateShrinkOverlay();
5244cdf0e10cSrcweir }
5245cdf0e10cSrcweir 
5246cdf0e10cSrcweir // #114409#
5247cdf0e10cSrcweir void ScGridWindow::ImpDestroyOverlayObjects()
5248cdf0e10cSrcweir {
5249cdf0e10cSrcweir     DeleteCursorOverlay();
5250cdf0e10cSrcweir     DeleteSelectionOverlay();
5251cdf0e10cSrcweir     DeleteAutoFillOverlay();
5252cdf0e10cSrcweir     DeleteDragRectOverlay();
5253cdf0e10cSrcweir     DeleteHeaderOverlay();
5254cdf0e10cSrcweir     DeleteShrinkOverlay();
5255cdf0e10cSrcweir }
5256cdf0e10cSrcweir 
5257cdf0e10cSrcweir void ScGridWindow::UpdateAllOverlays()
5258cdf0e10cSrcweir {
5259cdf0e10cSrcweir     // delete and re-allocate all overlay objects
5260cdf0e10cSrcweir 
5261cdf0e10cSrcweir     ImpDestroyOverlayObjects();
5262cdf0e10cSrcweir     ImpCreateOverlayObjects();
5263cdf0e10cSrcweir }
5264cdf0e10cSrcweir 
5265cdf0e10cSrcweir void ScGridWindow::DeleteCursorOverlay()
5266cdf0e10cSrcweir {
5267cdf0e10cSrcweir     DELETEZ( mpOOCursors );
5268cdf0e10cSrcweir }
5269cdf0e10cSrcweir 
5270cdf0e10cSrcweir void ScGridWindow::UpdateCursorOverlay()
5271cdf0e10cSrcweir {
5272cdf0e10cSrcweir     MapMode aDrawMode = GetDrawMapMode();
5273cdf0e10cSrcweir     MapMode aOldMode = GetMapMode();
5274cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5275cdf0e10cSrcweir         SetMapMode( aDrawMode );
5276cdf0e10cSrcweir 
5277cdf0e10cSrcweir     // Existing OverlayObjects may be transformed in later versions.
5278cdf0e10cSrcweir     // For now, just re-create them.
5279cdf0e10cSrcweir 
5280cdf0e10cSrcweir     DeleteCursorOverlay();
5281cdf0e10cSrcweir 
5282cdf0e10cSrcweir     std::vector<Rectangle> aPixelRects;
5283cdf0e10cSrcweir 
5284cdf0e10cSrcweir     //
5285cdf0e10cSrcweir     //  determine the cursor rectangles in pixels (moved from ScGridWindow::DrawCursor)
5286cdf0e10cSrcweir     //
5287cdf0e10cSrcweir 
5288cdf0e10cSrcweir     SCTAB nTab = pViewData->GetTabNo();
5289cdf0e10cSrcweir     SCCOL nX = pViewData->GetCurX();
5290cdf0e10cSrcweir     SCROW nY = pViewData->GetCurY();
5291cdf0e10cSrcweir 
5292cdf0e10cSrcweir     if (!maVisibleRange.isInside(nX, nY))
5293cdf0e10cSrcweir         return;
5294cdf0e10cSrcweir 
5295cdf0e10cSrcweir     //  don't show the cursor in overlapped cells
5296cdf0e10cSrcweir 
5297cdf0e10cSrcweir     ScDocument* pDoc = pViewData->GetDocument();
5298cdf0e10cSrcweir     const ScPatternAttr* pPattern = pDoc->GetPattern(nX,nY,nTab);
5299cdf0e10cSrcweir     const ScMergeFlagAttr& rMergeFlag = (const ScMergeFlagAttr&) pPattern->GetItem(ATTR_MERGE_FLAG);
5300cdf0e10cSrcweir     sal_Bool bOverlapped = rMergeFlag.IsOverlapped();
5301cdf0e10cSrcweir 
5302cdf0e10cSrcweir     //  left or above of the screen?
5303cdf0e10cSrcweir 
5304cdf0e10cSrcweir     sal_Bool bVis = ( nX>=pViewData->GetPosX(eHWhich) && nY>=pViewData->GetPosY(eVWhich) );
5305cdf0e10cSrcweir     if (!bVis)
5306cdf0e10cSrcweir     {
5307cdf0e10cSrcweir         SCCOL nEndX = nX;
5308cdf0e10cSrcweir         SCROW nEndY = nY;
5309cdf0e10cSrcweir         const ScMergeAttr& rMerge = (const ScMergeAttr&) pPattern->GetItem(ATTR_MERGE);
5310cdf0e10cSrcweir         if (rMerge.GetColMerge() > 1)
5311cdf0e10cSrcweir             nEndX += rMerge.GetColMerge()-1;
5312cdf0e10cSrcweir         if (rMerge.GetRowMerge() > 1)
5313cdf0e10cSrcweir             nEndY += rMerge.GetRowMerge()-1;
5314cdf0e10cSrcweir         bVis = ( nEndX>=pViewData->GetPosX(eHWhich) && nEndY>=pViewData->GetPosY(eVWhich) );
5315cdf0e10cSrcweir     }
5316cdf0e10cSrcweir 
5317cdf0e10cSrcweir     if ( bVis && !bOverlapped && !pViewData->HasEditView(eWhich) && pViewData->IsActive() )
5318cdf0e10cSrcweir     {
5319cdf0e10cSrcweir         Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, sal_True );
5320cdf0e10cSrcweir         sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
5321cdf0e10cSrcweir 
5322cdf0e10cSrcweir         //  completely right of/below the screen?
5323cdf0e10cSrcweir         //  (test with logical start position in aScrPos)
5324cdf0e10cSrcweir         sal_Bool bMaybeVisible;
5325cdf0e10cSrcweir         if ( bLayoutRTL )
5326cdf0e10cSrcweir             bMaybeVisible = ( aScrPos.X() >= -2 && aScrPos.Y() >= -2 );
5327cdf0e10cSrcweir         else
5328cdf0e10cSrcweir         {
5329cdf0e10cSrcweir             Size aOutSize = GetOutputSizePixel();
5330cdf0e10cSrcweir             bMaybeVisible = ( aScrPos.X() <= aOutSize.Width() + 2 && aScrPos.Y() <= aOutSize.Height() + 2 );
5331cdf0e10cSrcweir         }
5332cdf0e10cSrcweir         if ( bMaybeVisible )
5333cdf0e10cSrcweir         {
5334cdf0e10cSrcweir             long nSizeXPix;
5335cdf0e10cSrcweir             long nSizeYPix;
5336cdf0e10cSrcweir             pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
5337cdf0e10cSrcweir 
5338cdf0e10cSrcweir             if ( bLayoutRTL )
5339cdf0e10cSrcweir                 aScrPos.X() -= nSizeXPix - 2;       // move instead of mirroring
5340cdf0e10cSrcweir 
5341cdf0e10cSrcweir             sal_Bool bFix = ( pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
5342cdf0e10cSrcweir                             pViewData->GetVSplitMode() == SC_SPLIT_FIX );
5343cdf0e10cSrcweir             if ( pViewData->GetActivePart()==eWhich || bFix )
5344cdf0e10cSrcweir             {
5345cdf0e10cSrcweir                 aScrPos.X() -= 2;
5346cdf0e10cSrcweir                 aScrPos.Y() -= 2;
5347cdf0e10cSrcweir                 Rectangle aRect( aScrPos, Size( nSizeXPix + 3, nSizeYPix + 3 ) );
5348cdf0e10cSrcweir 
5349cdf0e10cSrcweir                 aPixelRects.push_back(Rectangle( aRect.Left(), aRect.Top(), aRect.Left()+2, aRect.Bottom() ));
5350cdf0e10cSrcweir                 aPixelRects.push_back(Rectangle( aRect.Right()-2, aRect.Top(), aRect.Right(), aRect.Bottom() ));
5351cdf0e10cSrcweir                 aPixelRects.push_back(Rectangle( aRect.Left()+3, aRect.Top(), aRect.Right()-3, aRect.Top()+2 ));
5352cdf0e10cSrcweir                 aPixelRects.push_back(Rectangle( aRect.Left()+3, aRect.Bottom()-2, aRect.Right()-3, aRect.Bottom() ));
5353cdf0e10cSrcweir             }
5354cdf0e10cSrcweir             else
5355cdf0e10cSrcweir             {
5356cdf0e10cSrcweir                 Rectangle aRect( aScrPos, Size( nSizeXPix - 1, nSizeYPix - 1 ) );
5357cdf0e10cSrcweir                 aPixelRects.push_back( aRect );
5358cdf0e10cSrcweir             }
5359cdf0e10cSrcweir         }
5360cdf0e10cSrcweir     }
5361cdf0e10cSrcweir 
5362cdf0e10cSrcweir     if ( aPixelRects.size() )
5363cdf0e10cSrcweir     {
5364cdf0e10cSrcweir 		// #i70788# get the OverlayManager safely
5365cdf0e10cSrcweir 		::sdr::overlay::OverlayManager* pOverlayManager = getOverlayManager();
5366cdf0e10cSrcweir 
5367cdf0e10cSrcweir 		if(pOverlayManager)
5368cdf0e10cSrcweir         {
5369cdf0e10cSrcweir             const Color aCursorColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
5370cdf0e10cSrcweir 			std::vector< basegfx::B2DRange > aRanges;
5371cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
5372cdf0e10cSrcweir 
5373cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < aPixelRects.size(); a++)
5374cdf0e10cSrcweir 			{
5375cdf0e10cSrcweir 				const Rectangle aRA(aPixelRects[a]);
5376cdf0e10cSrcweir 				basegfx::B2DRange aRB(aRA.Left(), aRA.Top(), aRA.Right() + 1, aRA.Bottom() + 1);
5377cdf0e10cSrcweir 				aRB.transform(aTransform);
5378cdf0e10cSrcweir 				aRanges.push_back(aRB);
5379cdf0e10cSrcweir 			}
5380cdf0e10cSrcweir 
5381cdf0e10cSrcweir 			sdr::overlay::OverlayObject* pOverlay = new sdr::overlay::OverlaySelection(
5382cdf0e10cSrcweir 				sdr::overlay::OVERLAY_SOLID,
5383cdf0e10cSrcweir 				aCursorColor,
5384cdf0e10cSrcweir 				aRanges,
5385cdf0e10cSrcweir                 false);
5386cdf0e10cSrcweir 
5387cdf0e10cSrcweir 			pOverlayManager->add(*pOverlay);
5388cdf0e10cSrcweir 			mpOOCursors = new ::sdr::overlay::OverlayObjectList;
5389cdf0e10cSrcweir 			mpOOCursors->append(*pOverlay);
5390cdf0e10cSrcweir         }
5391cdf0e10cSrcweir     }
5392cdf0e10cSrcweir 
5393cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5394cdf0e10cSrcweir         SetMapMode( aOldMode );
5395cdf0e10cSrcweir }
5396cdf0e10cSrcweir 
5397cdf0e10cSrcweir void ScGridWindow::DeleteSelectionOverlay()
5398cdf0e10cSrcweir {
5399cdf0e10cSrcweir     DELETEZ( mpOOSelection );
5400cdf0e10cSrcweir }
5401cdf0e10cSrcweir 
5402cdf0e10cSrcweir void ScGridWindow::UpdateSelectionOverlay()
5403cdf0e10cSrcweir {
5404cdf0e10cSrcweir     MapMode aDrawMode = GetDrawMapMode();
5405cdf0e10cSrcweir     MapMode aOldMode = GetMapMode();
5406cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5407cdf0e10cSrcweir         SetMapMode( aDrawMode );
5408cdf0e10cSrcweir 
5409cdf0e10cSrcweir     DeleteSelectionOverlay();
5410cdf0e10cSrcweir     std::vector<Rectangle> aPixelRects;
5411cdf0e10cSrcweir     GetSelectionRects( aPixelRects );
5412cdf0e10cSrcweir 
5413cdf0e10cSrcweir     if ( aPixelRects.size() && pViewData->IsActive() )
5414cdf0e10cSrcweir     {
5415cdf0e10cSrcweir 		// #i70788# get the OverlayManager safely
5416cdf0e10cSrcweir 		::sdr::overlay::OverlayManager* pOverlayManager = getOverlayManager();
5417cdf0e10cSrcweir 
5418cdf0e10cSrcweir 		if(pOverlayManager)
5419cdf0e10cSrcweir 		{
5420cdf0e10cSrcweir 			std::vector< basegfx::B2DRange > aRanges;
5421cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
5422cdf0e10cSrcweir 
5423cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < aPixelRects.size(); a++)
5424cdf0e10cSrcweir 			{
5425cdf0e10cSrcweir 				const Rectangle aRA(aPixelRects[a]);
5426cdf0e10cSrcweir 				basegfx::B2DRange aRB(aRA.Left() - 1, aRA.Top() - 1, aRA.Right(), aRA.Bottom());
5427cdf0e10cSrcweir 				aRB.transform(aTransform);
5428cdf0e10cSrcweir 				aRanges.push_back(aRB);
5429cdf0e10cSrcweir 			}
5430cdf0e10cSrcweir 
54316043ac9bSArmin Le Grand             // get the system's hilight color
5432cdf0e10cSrcweir             const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
54336043ac9bSArmin Le Grand             const Color aHighlight(aSvtOptionsDrawinglayer.getHilightColor());
5434cdf0e10cSrcweir 
5435cdf0e10cSrcweir 			sdr::overlay::OverlayObject* pOverlay = new sdr::overlay::OverlaySelection(
5436cdf0e10cSrcweir 				sdr::overlay::OVERLAY_TRANSPARENT,
5437cdf0e10cSrcweir 				aHighlight,
5438cdf0e10cSrcweir 				aRanges,
5439cdf0e10cSrcweir                 true);
5440cdf0e10cSrcweir 
5441cdf0e10cSrcweir             pOverlayManager->add(*pOverlay);
5442cdf0e10cSrcweir 	        mpOOSelection = new ::sdr::overlay::OverlayObjectList;
5443cdf0e10cSrcweir 		    mpOOSelection->append(*pOverlay);
5444cdf0e10cSrcweir 		}
5445cdf0e10cSrcweir     }
5446cdf0e10cSrcweir 
5447cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5448cdf0e10cSrcweir         SetMapMode( aOldMode );
5449cdf0e10cSrcweir }
5450cdf0e10cSrcweir 
5451cdf0e10cSrcweir void ScGridWindow::DeleteAutoFillOverlay()
5452cdf0e10cSrcweir {
5453cdf0e10cSrcweir     DELETEZ( mpOOAutoFill );
5454cdf0e10cSrcweir     mpAutoFillRect.reset();
5455cdf0e10cSrcweir }
5456cdf0e10cSrcweir 
5457cdf0e10cSrcweir void ScGridWindow::UpdateAutoFillOverlay()
5458cdf0e10cSrcweir {
5459cdf0e10cSrcweir     MapMode aDrawMode = GetDrawMapMode();
5460cdf0e10cSrcweir     MapMode aOldMode = GetMapMode();
5461cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5462cdf0e10cSrcweir         SetMapMode( aDrawMode );
5463cdf0e10cSrcweir 
5464cdf0e10cSrcweir     DeleteAutoFillOverlay();
5465cdf0e10cSrcweir 
5466cdf0e10cSrcweir     //
5467cdf0e10cSrcweir     //  get the AutoFill handle rectangle in pixels (moved from ScGridWindow::DrawAutoFillMark)
5468cdf0e10cSrcweir     //
5469cdf0e10cSrcweir 
5470cdf0e10cSrcweir     if ( bAutoMarkVisible && aAutoMarkPos.Tab() == pViewData->GetTabNo() &&
5471cdf0e10cSrcweir          !pViewData->HasEditView(eWhich) && pViewData->IsActive() )
5472cdf0e10cSrcweir     {
5473cdf0e10cSrcweir         SCCOL nX = aAutoMarkPos.Col();
5474cdf0e10cSrcweir         SCROW nY = aAutoMarkPos.Row();
5475cdf0e10cSrcweir 
5476cdf0e10cSrcweir         if (!maVisibleRange.isInside(nX, nY))
5477cdf0e10cSrcweir             // Autofill mark is not visible.  Bail out.
5478cdf0e10cSrcweir             return;
5479cdf0e10cSrcweir 
5480cdf0e10cSrcweir         SCTAB nTab = pViewData->GetTabNo();
5481cdf0e10cSrcweir         ScDocument* pDoc = pViewData->GetDocument();
5482cdf0e10cSrcweir         sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
5483cdf0e10cSrcweir 
5484cdf0e10cSrcweir         Point aFillPos = pViewData->GetScrPos( nX, nY, eWhich, sal_True );
5485cdf0e10cSrcweir         long nSizeXPix;
5486cdf0e10cSrcweir         long nSizeYPix;
5487cdf0e10cSrcweir         pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
5488cdf0e10cSrcweir         if ( bLayoutRTL )
5489cdf0e10cSrcweir             aFillPos.X() -= nSizeXPix + 3;
5490cdf0e10cSrcweir         else
5491cdf0e10cSrcweir             aFillPos.X() += nSizeXPix - 2;
5492cdf0e10cSrcweir 
5493cdf0e10cSrcweir         aFillPos.Y() += nSizeYPix;
5494cdf0e10cSrcweir         aFillPos.Y() -= 2;
5495cdf0e10cSrcweir         mpAutoFillRect.reset(new Rectangle(aFillPos, Size(6, 6)));
5496cdf0e10cSrcweir 
5497cdf0e10cSrcweir 		// #i70788# get the OverlayManager safely
5498cdf0e10cSrcweir 		::sdr::overlay::OverlayManager* pOverlayManager = getOverlayManager();
5499cdf0e10cSrcweir 
5500cdf0e10cSrcweir 		if(pOverlayManager)
5501cdf0e10cSrcweir 		{
5502cdf0e10cSrcweir             const Color aHandleColor( SC_MOD()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor );
5503cdf0e10cSrcweir 			std::vector< basegfx::B2DRange > aRanges;
5504cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
5505cdf0e10cSrcweir             basegfx::B2DRange aRB(mpAutoFillRect->Left(), mpAutoFillRect->Top(), mpAutoFillRect->Right() + 1, mpAutoFillRect->Bottom() + 1);
5506cdf0e10cSrcweir 
5507cdf0e10cSrcweir 			aRB.transform(aTransform);
5508cdf0e10cSrcweir 			aRanges.push_back(aRB);
5509cdf0e10cSrcweir 
5510cdf0e10cSrcweir 			sdr::overlay::OverlayObject* pOverlay = new sdr::overlay::OverlaySelection(
5511cdf0e10cSrcweir 				sdr::overlay::OVERLAY_SOLID,
5512cdf0e10cSrcweir 				aHandleColor,
5513cdf0e10cSrcweir 				aRanges,
5514cdf0e10cSrcweir                 false);
5515cdf0e10cSrcweir 
5516cdf0e10cSrcweir 		    pOverlayManager->add(*pOverlay);
5517cdf0e10cSrcweir 			mpOOAutoFill = new ::sdr::overlay::OverlayObjectList;
5518cdf0e10cSrcweir 			mpOOAutoFill->append(*pOverlay);
5519cdf0e10cSrcweir 		}
5520cdf0e10cSrcweir 
5521cdf0e10cSrcweir         if ( aOldMode != aDrawMode )
5522cdf0e10cSrcweir             SetMapMode( aOldMode );
5523cdf0e10cSrcweir     }
5524cdf0e10cSrcweir }
5525cdf0e10cSrcweir 
5526cdf0e10cSrcweir void ScGridWindow::DeleteDragRectOverlay()
5527cdf0e10cSrcweir {
5528cdf0e10cSrcweir     DELETEZ( mpOODragRect );
5529cdf0e10cSrcweir }
5530cdf0e10cSrcweir 
5531cdf0e10cSrcweir void ScGridWindow::UpdateDragRectOverlay()
5532cdf0e10cSrcweir {
5533cdf0e10cSrcweir     MapMode aDrawMode = GetDrawMapMode();
5534cdf0e10cSrcweir     MapMode aOldMode = GetMapMode();
5535cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5536cdf0e10cSrcweir         SetMapMode( aDrawMode );
5537cdf0e10cSrcweir 
5538cdf0e10cSrcweir     DeleteDragRectOverlay();
5539cdf0e10cSrcweir 
5540cdf0e10cSrcweir     //
5541cdf0e10cSrcweir     //  get the rectangles in pixels (moved from DrawDragRect)
5542cdf0e10cSrcweir     //
5543cdf0e10cSrcweir 
5544cdf0e10cSrcweir     if ( bDragRect || bPagebreakDrawn )
5545cdf0e10cSrcweir     {
5546cdf0e10cSrcweir         std::vector<Rectangle> aPixelRects;
5547cdf0e10cSrcweir 
5548cdf0e10cSrcweir         SCCOL nX1 = bDragRect ? nDragStartX : aPagebreakDrag.aStart.Col();
5549cdf0e10cSrcweir         SCROW nY1 = bDragRect ? nDragStartY : aPagebreakDrag.aStart.Row();
5550cdf0e10cSrcweir         SCCOL nX2 = bDragRect ? nDragEndX : aPagebreakDrag.aEnd.Col();
5551cdf0e10cSrcweir         SCROW nY2 = bDragRect ? nDragEndY : aPagebreakDrag.aEnd.Row();
5552cdf0e10cSrcweir 
5553cdf0e10cSrcweir         SCTAB nTab = pViewData->GetTabNo();
5554cdf0e10cSrcweir 
5555cdf0e10cSrcweir         SCCOL nPosX = pViewData->GetPosX(WhichH(eWhich));
5556cdf0e10cSrcweir         SCROW nPosY = pViewData->GetPosY(WhichV(eWhich));
5557cdf0e10cSrcweir         if (nX1 < nPosX) nX1 = nPosX;
5558cdf0e10cSrcweir         if (nX2 < nPosX) nX2 = nPosX;
5559cdf0e10cSrcweir         if (nY1 < nPosY) nY1 = nPosY;
5560cdf0e10cSrcweir         if (nY2 < nPosY) nY2 = nPosY;
5561cdf0e10cSrcweir 
5562cdf0e10cSrcweir         Point aScrPos( pViewData->GetScrPos( nX1, nY1, eWhich ) );
5563cdf0e10cSrcweir 
5564cdf0e10cSrcweir         long nSizeXPix=0;
5565cdf0e10cSrcweir         long nSizeYPix=0;
5566cdf0e10cSrcweir         ScDocument* pDoc = pViewData->GetDocument();
5567cdf0e10cSrcweir         double nPPTX = pViewData->GetPPTX();
5568cdf0e10cSrcweir         double nPPTY = pViewData->GetPPTY();
5569cdf0e10cSrcweir         SCCOLROW i;
5570cdf0e10cSrcweir 
5571cdf0e10cSrcweir         sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
5572cdf0e10cSrcweir         long nLayoutSign = bLayoutRTL ? -1 : 1;
5573cdf0e10cSrcweir 
5574cdf0e10cSrcweir         if (ValidCol(nX2) && nX2>=nX1)
5575cdf0e10cSrcweir             for (i=nX1; i<=nX2; i++)
5576cdf0e10cSrcweir                 nSizeXPix += ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(i), nTab ), nPPTX );
5577cdf0e10cSrcweir         else
5578cdf0e10cSrcweir         {
5579cdf0e10cSrcweir             aScrPos.X() -= nLayoutSign;
5580cdf0e10cSrcweir             nSizeXPix   += 2;
5581cdf0e10cSrcweir         }
5582cdf0e10cSrcweir 
5583cdf0e10cSrcweir         if (ValidRow(nY2) && nY2>=nY1)
5584cdf0e10cSrcweir             for (i=nY1; i<=nY2; i++)
5585cdf0e10cSrcweir                 nSizeYPix += ScViewData::ToPixel( pDoc->GetRowHeight( i, nTab ), nPPTY );
5586cdf0e10cSrcweir         else
5587cdf0e10cSrcweir         {
5588cdf0e10cSrcweir             aScrPos.Y() -= 1;
5589cdf0e10cSrcweir             nSizeYPix   += 2;
5590cdf0e10cSrcweir         }
5591cdf0e10cSrcweir 
5592cdf0e10cSrcweir         aScrPos.X() -= 2 * nLayoutSign;
5593cdf0e10cSrcweir         aScrPos.Y() -= 2;
5594cdf0e10cSrcweir //      Rectangle aRect( aScrPos, Size( nSizeXPix + 3, nSizeYPix + 3 ) );
5595cdf0e10cSrcweir         Rectangle aRect( aScrPos.X(), aScrPos.Y(),
5596cdf0e10cSrcweir                          aScrPos.X() + ( nSizeXPix + 2 ) * nLayoutSign, aScrPos.Y() + nSizeYPix + 2 );
5597cdf0e10cSrcweir         if ( bLayoutRTL )
5598cdf0e10cSrcweir         {
5599cdf0e10cSrcweir             aRect.Left() = aRect.Right();   // end position is left
5600cdf0e10cSrcweir             aRect.Right() = aScrPos.X();
5601cdf0e10cSrcweir         }
5602cdf0e10cSrcweir 
5603cdf0e10cSrcweir         if ( meDragInsertMode == INS_CELLSDOWN )
5604cdf0e10cSrcweir         {
5605cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left()+1, aRect.Top()+3, aRect.Left()+1, aRect.Bottom()-2 ) );
5606cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Right()-1, aRect.Top()+3, aRect.Right()-1, aRect.Bottom()-2 ) );
5607cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left()+1, aRect.Top(), aRect.Right()-1, aRect.Top()+2 ) );
5608cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left()+1, aRect.Bottom()-1, aRect.Right()-1, aRect.Bottom()-1 ) );
5609cdf0e10cSrcweir         }
5610cdf0e10cSrcweir         else if ( meDragInsertMode == INS_CELLSRIGHT )
5611cdf0e10cSrcweir         {
5612cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left(), aRect.Top()+1, aRect.Left()+2, aRect.Bottom()-1 ) );
5613cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Right()-1, aRect.Top()+1, aRect.Right()-1, aRect.Bottom()-1 ) );
5614cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left()+3, aRect.Top()+1, aRect.Right()-2, aRect.Top()+1 ) );
5615cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left()+3, aRect.Bottom()-1, aRect.Right()-2, aRect.Bottom()-1 ) );
5616cdf0e10cSrcweir         }
5617cdf0e10cSrcweir         else
5618cdf0e10cSrcweir         {
5619cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left(), aRect.Top(), aRect.Left()+2, aRect.Bottom() ) );
5620cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Right()-2, aRect.Top(), aRect.Right(), aRect.Bottom() ) );
5621cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left()+3, aRect.Top(), aRect.Right()-3, aRect.Top()+2 ) );
5622cdf0e10cSrcweir             aPixelRects.push_back( Rectangle( aRect.Left()+3, aRect.Bottom()-2, aRect.Right()-3, aRect.Bottom() ) );
5623cdf0e10cSrcweir         }
5624cdf0e10cSrcweir 
5625cdf0e10cSrcweir 		// #i70788# get the OverlayManager safely
5626cdf0e10cSrcweir 		::sdr::overlay::OverlayManager* pOverlayManager = getOverlayManager();
5627cdf0e10cSrcweir 
5628cdf0e10cSrcweir 		if(pOverlayManager)
5629cdf0e10cSrcweir 		{
5630cdf0e10cSrcweir 			// Color aHighlight = GetSettings().GetStyleSettings().GetHighlightColor();
5631cdf0e10cSrcweir 			std::vector< basegfx::B2DRange > aRanges;
5632cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
5633cdf0e10cSrcweir 
5634cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < aPixelRects.size(); a++)
5635cdf0e10cSrcweir 			{
5636cdf0e10cSrcweir 				const Rectangle aRA(aPixelRects[a]);
5637cdf0e10cSrcweir 				basegfx::B2DRange aRB(aRA.Left(), aRA.Top(), aRA.Right() + 1, aRA.Bottom() + 1);
5638cdf0e10cSrcweir 				aRB.transform(aTransform);
5639cdf0e10cSrcweir 				aRanges.push_back(aRB);
5640cdf0e10cSrcweir 			}
5641cdf0e10cSrcweir 
5642cdf0e10cSrcweir 			sdr::overlay::OverlayObject* pOverlay = new sdr::overlay::OverlaySelection(
5643cdf0e10cSrcweir 				sdr::overlay::OVERLAY_INVERT,
5644cdf0e10cSrcweir 				Color(COL_BLACK),
5645cdf0e10cSrcweir 				aRanges,
5646cdf0e10cSrcweir                 false);
5647cdf0e10cSrcweir 
5648cdf0e10cSrcweir 		    pOverlayManager->add(*pOverlay);
5649cdf0e10cSrcweir 			mpOODragRect = new ::sdr::overlay::OverlayObjectList;
5650cdf0e10cSrcweir 			mpOODragRect->append(*pOverlay);
5651cdf0e10cSrcweir 		}
5652cdf0e10cSrcweir     }
5653cdf0e10cSrcweir 
5654cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5655cdf0e10cSrcweir         SetMapMode( aOldMode );
5656cdf0e10cSrcweir }
5657cdf0e10cSrcweir 
5658cdf0e10cSrcweir void ScGridWindow::DeleteHeaderOverlay()
5659cdf0e10cSrcweir {
5660cdf0e10cSrcweir     DELETEZ( mpOOHeader );
5661cdf0e10cSrcweir }
5662cdf0e10cSrcweir 
5663cdf0e10cSrcweir void ScGridWindow::UpdateHeaderOverlay()
5664cdf0e10cSrcweir {
5665cdf0e10cSrcweir     MapMode aDrawMode = GetDrawMapMode();
5666cdf0e10cSrcweir     MapMode aOldMode = GetMapMode();
5667cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5668cdf0e10cSrcweir         SetMapMode( aDrawMode );
5669cdf0e10cSrcweir 
5670cdf0e10cSrcweir     DeleteHeaderOverlay();
5671cdf0e10cSrcweir 
5672cdf0e10cSrcweir     //  Pixel rectangle is in aInvertRect
5673cdf0e10cSrcweir     if ( !aInvertRect.IsEmpty() )
5674cdf0e10cSrcweir     {
5675cdf0e10cSrcweir 		// #i70788# get the OverlayManager safely
5676cdf0e10cSrcweir 		::sdr::overlay::OverlayManager* pOverlayManager = getOverlayManager();
5677cdf0e10cSrcweir 
5678cdf0e10cSrcweir 		if(pOverlayManager)
5679cdf0e10cSrcweir 		{
5680cdf0e10cSrcweir             // Color aHighlight = GetSettings().GetStyleSettings().GetHighlightColor();
5681cdf0e10cSrcweir 			std::vector< basegfx::B2DRange > aRanges;
5682cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
5683cdf0e10cSrcweir 			basegfx::B2DRange aRB(aInvertRect.Left(), aInvertRect.Top(), aInvertRect.Right() + 1, aInvertRect.Bottom() + 1);
5684cdf0e10cSrcweir 
5685cdf0e10cSrcweir 			aRB.transform(aTransform);
5686cdf0e10cSrcweir 			aRanges.push_back(aRB);
5687cdf0e10cSrcweir 
5688cdf0e10cSrcweir 			sdr::overlay::OverlayObject* pOverlay = new sdr::overlay::OverlaySelection(
5689cdf0e10cSrcweir 				sdr::overlay::OVERLAY_INVERT,
5690cdf0e10cSrcweir 				Color(COL_BLACK),
5691cdf0e10cSrcweir 				aRanges,
5692cdf0e10cSrcweir                 false);
5693cdf0e10cSrcweir 
5694cdf0e10cSrcweir             pOverlayManager->add(*pOverlay);
5695cdf0e10cSrcweir 	        mpOOHeader = new ::sdr::overlay::OverlayObjectList;
5696cdf0e10cSrcweir 		    mpOOHeader->append(*pOverlay);
5697cdf0e10cSrcweir 		}
5698cdf0e10cSrcweir     }
5699cdf0e10cSrcweir 
5700cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5701cdf0e10cSrcweir         SetMapMode( aOldMode );
5702cdf0e10cSrcweir }
5703cdf0e10cSrcweir 
5704cdf0e10cSrcweir void ScGridWindow::DeleteShrinkOverlay()
5705cdf0e10cSrcweir {
5706cdf0e10cSrcweir     DELETEZ( mpOOShrink );
5707cdf0e10cSrcweir }
5708cdf0e10cSrcweir 
5709cdf0e10cSrcweir void ScGridWindow::UpdateShrinkOverlay()
5710cdf0e10cSrcweir {
5711cdf0e10cSrcweir     MapMode aDrawMode = GetDrawMapMode();
5712cdf0e10cSrcweir     MapMode aOldMode = GetMapMode();
5713cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5714cdf0e10cSrcweir         SetMapMode( aDrawMode );
5715cdf0e10cSrcweir 
5716cdf0e10cSrcweir     DeleteShrinkOverlay();
5717cdf0e10cSrcweir 
5718cdf0e10cSrcweir     //
5719cdf0e10cSrcweir     //  get the rectangle in pixels
5720cdf0e10cSrcweir     //
5721cdf0e10cSrcweir 
5722cdf0e10cSrcweir     Rectangle aPixRect;
5723cdf0e10cSrcweir     ScRange aRange;
5724cdf0e10cSrcweir     SCTAB nTab = pViewData->GetTabNo();
5725cdf0e10cSrcweir     if ( pViewData->IsRefMode() && nTab >= pViewData->GetRefStartZ() && nTab <= pViewData->GetRefEndZ() &&
5726cdf0e10cSrcweir          pViewData->GetDelMark( aRange ) )
5727cdf0e10cSrcweir     {
5728cdf0e10cSrcweir         //! limit to visible area
5729cdf0e10cSrcweir         if ( aRange.aStart.Col() <= aRange.aEnd.Col() &&
5730cdf0e10cSrcweir              aRange.aStart.Row() <= aRange.aEnd.Row() )
5731cdf0e10cSrcweir         {
5732cdf0e10cSrcweir             Point aStart = pViewData->GetScrPos( aRange.aStart.Col(),
5733cdf0e10cSrcweir                                                  aRange.aStart.Row(), eWhich );
5734cdf0e10cSrcweir             Point aEnd = pViewData->GetScrPos( aRange.aEnd.Col()+1,
5735cdf0e10cSrcweir                                                aRange.aEnd.Row()+1, eWhich );
5736cdf0e10cSrcweir             aEnd.X() -= 1;
5737cdf0e10cSrcweir             aEnd.Y() -= 1;
5738cdf0e10cSrcweir 
5739cdf0e10cSrcweir             aPixRect = Rectangle( aStart,aEnd );
5740cdf0e10cSrcweir         }
5741cdf0e10cSrcweir     }
5742cdf0e10cSrcweir 
5743cdf0e10cSrcweir     if ( !aPixRect.IsEmpty() )
5744cdf0e10cSrcweir     {
5745cdf0e10cSrcweir 		// #i70788# get the OverlayManager safely
5746cdf0e10cSrcweir 		::sdr::overlay::OverlayManager* pOverlayManager = getOverlayManager();
5747cdf0e10cSrcweir 
5748cdf0e10cSrcweir 		if(pOverlayManager)
5749cdf0e10cSrcweir 		{
5750cdf0e10cSrcweir             // Color aHighlight = GetSettings().GetStyleSettings().GetHighlightColor();
5751cdf0e10cSrcweir 			std::vector< basegfx::B2DRange > aRanges;
5752cdf0e10cSrcweir 			const basegfx::B2DHomMatrix aTransform(GetInverseViewTransformation());
5753cdf0e10cSrcweir 			basegfx::B2DRange aRB(aPixRect.Left(), aPixRect.Top(), aPixRect.Right() + 1, aPixRect.Bottom() + 1);
5754cdf0e10cSrcweir 
5755cdf0e10cSrcweir 			aRB.transform(aTransform);
5756cdf0e10cSrcweir 			aRanges.push_back(aRB);
5757cdf0e10cSrcweir 
5758cdf0e10cSrcweir 			sdr::overlay::OverlayObject* pOverlay = new sdr::overlay::OverlaySelection(
5759cdf0e10cSrcweir 				sdr::overlay::OVERLAY_INVERT,
5760cdf0e10cSrcweir 				Color(COL_BLACK),
5761cdf0e10cSrcweir 				aRanges,
5762cdf0e10cSrcweir                 false);
5763cdf0e10cSrcweir 
5764cdf0e10cSrcweir             pOverlayManager->add(*pOverlay);
5765cdf0e10cSrcweir 	        mpOOShrink = new ::sdr::overlay::OverlayObjectList;
5766cdf0e10cSrcweir 		    mpOOShrink->append(*pOverlay);
5767cdf0e10cSrcweir 		}
5768cdf0e10cSrcweir     }
5769cdf0e10cSrcweir 
5770cdf0e10cSrcweir     if ( aOldMode != aDrawMode )
5771cdf0e10cSrcweir         SetMapMode( aOldMode );
5772cdf0e10cSrcweir }
5773cdf0e10cSrcweir 
5774cdf0e10cSrcweir // #i70788# central method to get the OverlayManager safely
5775cdf0e10cSrcweir ::sdr::overlay::OverlayManager* ScGridWindow::getOverlayManager()
5776cdf0e10cSrcweir {
5777cdf0e10cSrcweir 	SdrPageView* pPV = pViewData->GetView()->GetScDrawView()->GetSdrPageView();
5778cdf0e10cSrcweir 
5779cdf0e10cSrcweir 	if(pPV)
5780cdf0e10cSrcweir 	{
5781cdf0e10cSrcweir 		SdrPageWindow* pPageWin = pPV->FindPageWindow( *this );
5782cdf0e10cSrcweir 
5783cdf0e10cSrcweir 		if ( pPageWin )
5784cdf0e10cSrcweir 		{
5785cdf0e10cSrcweir 			return (pPageWin->GetOverlayManager());
5786cdf0e10cSrcweir 		}
5787cdf0e10cSrcweir 	}
5788cdf0e10cSrcweir 
5789cdf0e10cSrcweir 	return 0L;
5790cdf0e10cSrcweir }
5791cdf0e10cSrcweir 
5792cdf0e10cSrcweir void ScGridWindow::flushOverlayManager()
5793cdf0e10cSrcweir {
5794cdf0e10cSrcweir 	// #i70788# get the OverlayManager safely
5795cdf0e10cSrcweir 	::sdr::overlay::OverlayManager* pOverlayManager = getOverlayManager();
5796cdf0e10cSrcweir 
5797cdf0e10cSrcweir 	if(pOverlayManager)
5798cdf0e10cSrcweir 	{
5799cdf0e10cSrcweir 		pOverlayManager->flush();
5800cdf0e10cSrcweir 	}
5801cdf0e10cSrcweir }
5802cdf0e10cSrcweir 
5803cdf0e10cSrcweir // ---------------------------------------------------------------------------
5804cdf0e10cSrcweir // eof
5805