xref: /trunk/main/svtools/source/brwbox/datwin.cxx (revision 5900e8ec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include "datwin.hxx"
28 
29 #ifndef GCC
30 #endif
31 
32 #ifndef _APP_HXX //autogen
33 #include <vcl/svapp.hxx>
34 #endif
35 
36 #ifndef _HELP_HXX
37 #include <vcl/help.hxx>
38 #endif
39 #ifndef _IMAGE_HXX
40 #include <vcl/image.hxx>
41 #endif
42 
43 #include <tools/debug.hxx>
44 
DECLARE_LIST(BrowserColumns,BrowserColumn *)45 DECLARE_LIST( BrowserColumns, BrowserColumn* )
46 
47 //===================================================================
48 void ButtonFrame::Draw( OutputDevice& rDev )
49 {
50 	Color aOldFillColor = rDev.GetFillColor();
51 	Color aOldLineColor = rDev.GetLineColor();
52 
53 	const StyleSettings &rSettings = rDev.GetSettings().GetStyleSettings();
54 	Color aColLight( rSettings.GetLightColor() );
55 	Color aColShadow( rSettings.GetShadowColor() );
56 	Color aColFace( rSettings.GetFaceColor() );
57 
58 	rDev.SetLineColor( aColFace );
59 	rDev.SetFillColor( aColFace );
60 	rDev.DrawRect( aRect );
61 
62     if( rDev.GetOutDevType() == OUTDEV_WINDOW )
63     {
64         Window *pWin = (Window*) &rDev;
65         if( bPressed )
66             pWin->DrawSelectionBackground( aRect, 0, sal_True, sal_False, sal_False );
67     }
68     else
69     {
70 	    rDev.SetLineColor( bPressed ? aColShadow : aColLight );
71 	    rDev.DrawLine( aRect.TopLeft(), Point( aRect.Right(), aRect.Top() ) );
72 	    rDev.DrawLine( aRect.TopLeft(), Point( aRect.Left(), aRect.Bottom() - 1 ) );
73 	    rDev.SetLineColor( bPressed ? aColLight : aColShadow );
74 	    rDev.DrawLine( aRect.BottomRight(), Point( aRect.Right(), aRect.Top() ) );
75 	    rDev.DrawLine( aRect.BottomRight(), Point( aRect.Left(), aRect.Bottom() ) );
76     }
77 
78 	if ( aText.Len() )
79 	{
80 		String aVal = rDev.GetEllipsisString(aText,aInnerRect.GetWidth() - 2*MIN_COLUMNWIDTH);
81 
82 		Font aFont( rDev.GetFont() );
83 		sal_Bool bOldTransp = aFont.IsTransparent();
84 		if ( !bOldTransp )
85 		{
86 			aFont.SetTransparent( sal_True );
87 			rDev.SetFont( aFont );
88 		}
89 
90 		Color aOldColor = rDev.GetTextColor();
91 		if (m_bDrawDisabled)
92 			rDev.SetTextColor(rSettings.GetDisableColor());
93 
94 		rDev.DrawText( Point(
95 			( aInnerRect.Left() + aInnerRect.Right() ) / 2 - ( rDev.GetTextWidth(aVal) / 2 ),
96 			aInnerRect.Top() ), aVal );
97 
98 		// restore settings
99 		if ( !bOldTransp )
100 		{
101 			aFont.SetTransparent(sal_False);
102 			rDev.SetFont( aFont );
103 		}
104 		if (m_bDrawDisabled)
105 			rDev.SetTextColor(aOldColor);
106 	}
107 
108 	if ( bCurs )
109 	{
110 		rDev.SetLineColor( Color( COL_BLACK ) );
111 		rDev.SetFillColor();
112 		rDev.DrawRect( Rectangle(
113 			Point( aRect.Left(), aRect.Top() ), Point( aRect.Right(), aRect.Bottom() ) ) );
114 	}
115 
116 	rDev.SetLineColor( aOldLineColor );
117 	rDev.SetFillColor( aOldFillColor );
118 }
119 
120 //-------------------------------------------------------------------
121 
BrowserColumn(sal_uInt16 nItemId,const class Image & rImage,const String & rTitle,sal_uLong nWidthPixel,const Fraction & rCurrentZoom,HeaderBarItemBits nFlags)122 BrowserColumn::BrowserColumn( sal_uInt16 nItemId, const class Image &rImage,
123 							  const String& rTitle, sal_uLong nWidthPixel, const Fraction& rCurrentZoom,
124 							  HeaderBarItemBits nFlags )
125 :	_nId( nItemId ),
126 	_nWidth( nWidthPixel ),
127 	_aImage( rImage ),
128 	_aTitle( rTitle ),
129 	_bFrozen( sal_False ),
130 	_nFlags( nFlags )
131 {
132 	double n = (double)_nWidth;
133 	n *= (double)rCurrentZoom.GetDenominator();
134 	n /= (double)rCurrentZoom.GetNumerator();
135 	_nOriginalWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5);
136 }
137 
~BrowserColumn()138 BrowserColumn::~BrowserColumn()
139 {
140 }
141 
142 //-------------------------------------------------------------------
143 
SetWidth(sal_uLong nNewWidthPixel,const Fraction & rCurrentZoom)144 void BrowserColumn::SetWidth(sal_uLong nNewWidthPixel, const Fraction& rCurrentZoom)
145 {
146 	_nWidth = nNewWidthPixel;
147 	double n = (double)_nWidth;
148 	n *= (double)rCurrentZoom.GetDenominator();
149 	n /= (double)rCurrentZoom.GetNumerator();
150 	_nOriginalWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5);
151 }
152 
153 //-------------------------------------------------------------------
154 
Draw(BrowseBox & rBox,OutputDevice & rDev,const Point & rPos,sal_Bool bCurs)155 void BrowserColumn::Draw( BrowseBox& rBox, OutputDevice& rDev, const Point& rPos, sal_Bool bCurs  )
156 {
157 	if ( _nId == 0 )
158 	{
159 		// paint handle column
160 		ButtonFrame( rPos, Size( Width()-1, rBox.GetDataRowHeight()-1 ),
161 					 String(), sal_False, bCurs,
162 					 0 != (BROWSER_COLUMN_TITLEABBREVATION&_nFlags) ).Draw( rDev );
163 		Color aOldLineColor = rDev.GetLineColor();
164 		rDev.SetLineColor( Color( COL_BLACK ) );
165 		rDev.DrawLine(
166 			Point( rPos.X(), rPos.Y()+rBox.GetDataRowHeight()-1 ),
167 			Point( rPos.X() + Width() - 1, rPos.Y()+rBox.GetDataRowHeight()-1 ) );
168 		rDev.DrawLine(
169 			Point( rPos.X() + Width() - 1, rPos.Y() ),
170 			Point( rPos.X() + Width() - 1, rPos.Y()+rBox.GetDataRowHeight()-1 ) );
171 		rDev.SetLineColor( aOldLineColor );
172 
173 		rBox.DoPaintField( rDev,
174 			Rectangle(
175 				Point( rPos.X() + 2, rPos.Y() + 2 ),
176 				Size( Width()-1, rBox.GetDataRowHeight()-1 ) ),
177 			GetId(),
178             BrowseBox::BrowserColumnAccess() );
179 	}
180 	else
181 	{
182 		// paint data column
183 		long nWidth = Width() == LONG_MAX ? rBox.GetDataWindow().GetSizePixel().Width() : Width();
184 
185 		rBox.DoPaintField( rDev,
186 			Rectangle(
187 				Point( rPos.X() + MIN_COLUMNWIDTH, rPos.Y() ),
188 				Size( nWidth-2*MIN_COLUMNWIDTH, rBox.GetDataRowHeight()-1 ) ),
189 			GetId(),
190             BrowseBox::BrowserColumnAccess() );
191 	}
192 }
193 
194 //-------------------------------------------------------------------
195 
ZoomChanged(const Fraction & rNewZoom)196 void BrowserColumn::ZoomChanged(const Fraction& rNewZoom)
197 {
198 	double n = (double)_nOriginalWidth;
199 	n *= (double)rNewZoom.GetNumerator();
200 	n /= (double)rNewZoom.GetDenominator();
201 
202 	_nWidth = n>0 ? (long)(n+0.5) : -(long)(-n+0.5);
203 }
204 
205 //-------------------------------------------------------------------
206 
BrowserDataWin(BrowseBox * pParent)207 BrowserDataWin::BrowserDataWin( BrowseBox* pParent )
208     :Control( pParent, WinBits(WB_CLIPCHILDREN) )
209 	,DragSourceHelper( this )
210 	,DropTargetHelper( this )
211 	,pHeaderBar( 0 )
212 	,pEventWin( pParent )
213 	,pCornerWin( 0 )
214 	,pDtorNotify( 0 )
215 	,bInPaint( sal_False )
216 	,bInCommand( sal_False )
217 	,bNoScrollBack( sal_False )
218     ,bNoHScroll( sal_False )
219     ,bNoVScroll( sal_False )
220 	,bUpdateMode( sal_True )
221 	,bResizeOnPaint( sal_False )
222 	,bUpdateOnUnlock( sal_False )
223 	,bInUpdateScrollbars( sal_False )
224 	,bHadRecursion( sal_False )
225 	,bOwnDataChangedHdl( sal_False )
226 	,bCallingDropCallback( sal_False )
227 	,nUpdateLock( 0 )
228 	,nCursorHidden( 0 )
229     ,m_nDragRowDividerLimit( 0 )
230     ,m_nDragRowDividerOffset( 0 )
231 {
232 	aMouseTimer.SetTimeoutHdl( LINK( this, BrowserDataWin, RepeatedMouseMove ) );
233 	aMouseTimer.SetTimeout( 100 );
234 }
235 
236 //-------------------------------------------------------------------
~BrowserDataWin()237 BrowserDataWin::~BrowserDataWin()
238 {
239 	if( pDtorNotify )
240 		*pDtorNotify = sal_True;
241 }
242 
243 //-------------------------------------------------------------------
LeaveUpdateLock()244 void BrowserDataWin::LeaveUpdateLock()
245 {
246 	if ( !--nUpdateLock )
247 	{
248 		DoOutstandingInvalidations();
249 		if (bUpdateOnUnlock )
250 		{
251 			Control::Update();
252 			bUpdateOnUnlock = sal_False;
253 		}
254 	}
255 }
256 
257 //-------------------------------------------------------------------
InitSettings_Impl(Window * pWin,sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)258 void InitSettings_Impl( Window *pWin,
259 					 sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
260 {
261 	const StyleSettings& rStyleSettings =
262 			pWin->GetSettings().GetStyleSettings();
263 
264 	if ( bFont )
265 	{
266 		Font aFont = rStyleSettings.GetFieldFont();
267 		if ( pWin->IsControlFont() )
268 			aFont.Merge( pWin->GetControlFont() );
269 		pWin->SetZoomedPointFont( aFont );
270 	}
271 
272 	if ( bFont || bForeground )
273 	{
274 		Color aTextColor = rStyleSettings.GetWindowTextColor();
275 		if ( pWin->IsControlForeground() )
276 			aTextColor = pWin->GetControlForeground();
277 		pWin->SetTextColor( aTextColor );
278 	}
279 
280 	if ( bBackground )
281 	{
282 		if( pWin->IsControlBackground() )
283 			pWin->SetBackground( pWin->GetControlBackground() );
284 		else
285 			pWin->SetBackground( rStyleSettings.GetWindowColor() );
286 	}
287 }
288 
289 //-------------------------------------------------------------------
Update()290 void BrowserDataWin::Update()
291 {
292 	if ( !nUpdateLock )
293 		Control::Update();
294 	else
295 		bUpdateOnUnlock = sal_True;
296 }
297 
298 //-------------------------------------------------------------------
DataChanged(const DataChangedEvent & rDCEvt)299 void BrowserDataWin::DataChanged( const DataChangedEvent& rDCEvt )
300 {
301 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
302 		 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
303 	{
304 		if( !bOwnDataChangedHdl )
305 		{
306 			InitSettings_Impl( this, sal_True, sal_True, sal_True );
307 			Invalidate();
308 			InitSettings_Impl( GetParent(), sal_True, sal_True, sal_True );
309 			GetParent()->Invalidate();
310 			GetParent()->Resize();
311 		}
312 	}
313 	else
314 		Control::DataChanged( rDCEvt );
315 }
316 
317 //-------------------------------------------------------------------
Paint(const Rectangle & rRect)318 void BrowserDataWin::Paint( const Rectangle& rRect )
319 {
320 	if ( !nUpdateLock && GetUpdateMode() )
321 	{
322 		if ( bInPaint )
323 		{
324 			aInvalidRegion.Insert( new Rectangle( rRect ) );
325 			return;
326 		}
327 		bInPaint = sal_True;
328 		( (BrowseBox*) GetParent() )->PaintData( *this, rRect );
329 		bInPaint = sal_False;
330 		DoOutstandingInvalidations();
331 	}
332 	else
333 		aInvalidRegion.Insert( new Rectangle( rRect ) );
334 }
335 
336 //-------------------------------------------------------------------
337 
CreateBrowseEvent(const Point & rPosPixel)338 BrowseEvent BrowserDataWin::CreateBrowseEvent( const Point& rPosPixel )
339 {
340 	BrowseBox *pBox = GetParent();
341 
342 	// seek to row under mouse
343 	long nRelRow = rPosPixel.Y() < 0
344 			? -1
345 			: rPosPixel.Y() / pBox->GetDataRowHeight();
346 	long nRow = nRelRow < 0 ? -1 : nRelRow + pBox->nTopRow;
347 
348 	// find column under mouse
349 	long nMouseX = rPosPixel.X();
350 	long nColX = 0;
351 	sal_uInt16 nCol;
352 	for ( nCol = 0;
353 		  nCol < pBox->pCols->Count() && nColX < GetSizePixel().Width();
354 		  ++nCol )
355 		if ( pBox->pCols->GetObject(nCol)->IsFrozen() || nCol >= pBox->nFirstCol )
356 		{
357 			nColX += pBox->pCols->GetObject(nCol)->Width();
358 			if ( nMouseX < nColX )
359 				break;
360 		}
361 	sal_uInt16 nColId = BROWSER_INVALIDID;
362 	if ( nCol < pBox->pCols->Count() )
363 		nColId = pBox->pCols->GetObject(nCol)->GetId();
364 
365 	// compute the field rectangle and field relative MouseEvent
366 	Rectangle aFieldRect;
367 	if ( nCol < pBox->pCols->Count() )
368 	{
369 		nColX -= pBox->pCols->GetObject(nCol)->Width();
370 		aFieldRect = Rectangle(
371 			Point( nColX, nRelRow * pBox->GetDataRowHeight() ),
372 			Size( pBox->pCols->GetObject(nCol)->Width(),
373 				  pBox->GetDataRowHeight() ) );
374 	}
375 
376 	// assemble and return the BrowseEvent
377 	return BrowseEvent( this, nRow, nCol, nColId, aFieldRect );
378 }
379 
380 //-------------------------------------------------------------------
AcceptDrop(const AcceptDropEvent & _rEvt)381 sal_Int8 BrowserDataWin::AcceptDrop( const AcceptDropEvent& _rEvt )
382 {
383 	bCallingDropCallback = sal_True;
384 	sal_Int8 nReturn = DND_ACTION_NONE;
385 	nReturn = GetParent()->AcceptDrop( BrowserAcceptDropEvent( this, _rEvt ) );
386 	bCallingDropCallback = sal_False;
387 	return nReturn;
388 }
389 
390 //-------------------------------------------------------------------
ExecuteDrop(const ExecuteDropEvent & _rEvt)391 sal_Int8 BrowserDataWin::ExecuteDrop( const ExecuteDropEvent& _rEvt )
392 {
393 	bCallingDropCallback = sal_True;
394 	sal_Int8 nReturn = DND_ACTION_NONE;
395 	nReturn = GetParent()->ExecuteDrop( BrowserExecuteDropEvent( this, _rEvt ) );
396 	bCallingDropCallback = sal_False;
397 	return nReturn;
398 }
399 
400 //-------------------------------------------------------------------
StartDrag(sal_Int8 _nAction,const Point & _rPosPixel)401 void BrowserDataWin::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
402 {
403     if ( !GetParent()->bRowDividerDrag )
404     {
405 	    Point aEventPos( _rPosPixel );
406 	    aEventPos.Y() += GetParent()->GetTitleHeight();
407 	    GetParent()->StartDrag( _nAction, aEventPos );
408     }
409 }
410 
411 //-------------------------------------------------------------------
Command(const CommandEvent & rEvt)412 void BrowserDataWin::Command( const CommandEvent& rEvt )
413 {
414 	// Scrollmaus-Event?
415 	BrowseBox *pBox = GetParent();
416 	if ( ( (rEvt.GetCommand() == COMMAND_WHEEL) ||
417 		   (rEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
418 		   (rEvt.GetCommand() == COMMAND_AUTOSCROLL) ) &&
419 		 ( HandleScrollCommand( rEvt, &pBox->aHScroll, pBox->pVScroll ) ) )
420 	  return;
421 
422 	Point aEventPos( rEvt.GetMousePosPixel() );
423 	long nRow = pBox->GetRowAtYPosPixel( aEventPos.Y(), sal_False);
424 	MouseEvent aMouseEvt( aEventPos, 1, MOUSE_SELECT, MOUSE_LEFT );
425 	if ( COMMAND_CONTEXTMENU == rEvt.GetCommand() && rEvt.IsMouseEvent() &&
426 		 nRow < pBox->GetRowCount() && !pBox->IsRowSelected(nRow) )
427 	{
428 		sal_Bool bDeleted = sal_False;
429 		pDtorNotify = &bDeleted;
430 		bInCommand = sal_True;
431 		MouseButtonDown( aMouseEvt );
432 		if( bDeleted )
433 			return;
434 		MouseButtonUp( aMouseEvt );
435 		if( bDeleted )
436 			return;
437 		pDtorNotify = 0;
438 		bInCommand = sal_False;
439 	}
440 
441 	aEventPos.Y() += GetParent()->GetTitleHeight();
442 	CommandEvent aEvt( aEventPos, rEvt.GetCommand(),
443 						rEvt.IsMouseEvent(), rEvt.GetData() );
444 	bInCommand = sal_True;
445 	sal_Bool bDeleted = sal_False;
446 	pDtorNotify = &bDeleted;
447 	GetParent()->Command( aEvt );
448 	if( bDeleted )
449 		return;
450 	pDtorNotify = 0;
451 	bInCommand = sal_False;
452 
453 	if ( COMMAND_STARTDRAG == rEvt.GetCommand() )
454 		MouseButtonUp( aMouseEvt );
455 
456 	Control::Command( rEvt );
457 }
458 
459 //-------------------------------------------------------------------
460 
ImplRowDividerHitTest(const BrowserMouseEvent & _rEvent)461 sal_Bool BrowserDataWin::ImplRowDividerHitTest( const BrowserMouseEvent& _rEvent )
462 {
463     if ( ! (  GetParent()->IsInteractiveRowHeightEnabled()
464            && ( _rEvent.GetRow() >= 0 )
465            && ( _rEvent.GetRow() < GetParent()->GetRowCount() )
466            && ( _rEvent.GetColumnId() == 0 )
467            )
468        )
469        return sal_False;
470 
471     long nDividerDistance = GetParent()->GetDataRowHeight() - ( _rEvent.GetPosPixel().Y() % GetParent()->GetDataRowHeight() );
472     return ( nDividerDistance <= 4 );
473 }
474 
475 //-------------------------------------------------------------------
476 
MouseButtonDown(const MouseEvent & rEvt)477 void BrowserDataWin::MouseButtonDown( const MouseEvent& rEvt )
478 {
479 	aLastMousePos = OutputToScreenPixel( rEvt.GetPosPixel() );
480 
481     BrowserMouseEvent aBrowserEvent( this, rEvt );
482     if ( ( aBrowserEvent.GetClicks() == 1 ) && ImplRowDividerHitTest( aBrowserEvent ) )
483     {
484         StartRowDividerDrag( aBrowserEvent.GetPosPixel() );
485         return;
486     }
487 
488     GetParent()->MouseButtonDown( BrowserMouseEvent( this, rEvt ) );
489 }
490 
491 //-------------------------------------------------------------------
492 
MouseMove(const MouseEvent & rEvt)493 void BrowserDataWin::MouseMove( const MouseEvent& rEvt )
494 {
495 	// Pseudo MouseMoves verhindern
496 	Point aNewPos = OutputToScreenPixel( rEvt.GetPosPixel() );
497 	if ( ( aNewPos == aLastMousePos ) )
498 		return;
499 	aLastMousePos = aNewPos;
500 
501 	// transform to a BrowseEvent
502     BrowserMouseEvent aBrowserEvent( this, rEvt );
503 	GetParent()->MouseMove( aBrowserEvent );
504 
505     // pointer shape
506 	PointerStyle ePointerStyle = POINTER_ARROW;
507     if ( ImplRowDividerHitTest( aBrowserEvent ) )
508         ePointerStyle = POINTER_VSIZEBAR;
509 	SetPointer( Pointer( ePointerStyle ) );
510 
511     // dragging out of the visible area?
512 	if ( rEvt.IsLeft() &&
513 		 ( rEvt.GetPosPixel().Y() > GetSizePixel().Height() ||
514 		   rEvt.GetPosPixel().Y() < 0 ) )
515 	{
516 		// repeat the event
517 		aRepeatEvt = rEvt;
518 		aMouseTimer.Start();
519 	}
520 	else
521 		// killing old repeat-event
522 		if ( aMouseTimer.IsActive() )
523 			aMouseTimer.Stop();
524 }
525 
526 //-------------------------------------------------------------------
527 
IMPL_LINK_INLINE_START(BrowserDataWin,RepeatedMouseMove,void *,EMPTYARG)528 IMPL_LINK_INLINE_START( BrowserDataWin, RepeatedMouseMove, void *, EMPTYARG )
529 {
530 	GetParent()->MouseMove( BrowserMouseEvent( this, aRepeatEvt ) );
531 	return 0;
532 }
IMPL_LINK_INLINE_END(BrowserDataWin,RepeatedMouseMove,void *,EMPTYARG)533 IMPL_LINK_INLINE_END( BrowserDataWin, RepeatedMouseMove, void *, EMPTYARG )
534 
535 //-------------------------------------------------------------------
536 
537 void BrowserDataWin::MouseButtonUp( const MouseEvent& rEvt )
538 {
539 	// Pseudo MouseMoves verhindern
540 	Point aNewPos = OutputToScreenPixel( rEvt.GetPosPixel() );
541 	aLastMousePos = aNewPos;
542 
543 	// Move an die aktuelle Position simulieren
544 	MouseMove( rEvt );
545 
546 	// eigentliches Up-Handling
547 	ReleaseMouse();
548 	if ( aMouseTimer.IsActive() )
549 		aMouseTimer.Stop();
550 	GetParent()->MouseButtonUp( BrowserMouseEvent( this, rEvt ) );
551 }
552 
553 //-------------------------------------------------------------------
554 
StartRowDividerDrag(const Point & _rStartPos)555 void BrowserDataWin::StartRowDividerDrag( const Point& _rStartPos )
556 {
557     long nDataRowHeight = GetParent()->GetDataRowHeight();
558     // the exact separation pos of the two rows
559     long nDragRowDividerCurrentPos = _rStartPos.Y();
560     if ( ( nDragRowDividerCurrentPos % nDataRowHeight ) > nDataRowHeight / 2 )
561         nDragRowDividerCurrentPos += nDataRowHeight;
562     nDragRowDividerCurrentPos /= nDataRowHeight;
563     nDragRowDividerCurrentPos *= nDataRowHeight;
564 
565     m_nDragRowDividerOffset = nDragRowDividerCurrentPos - _rStartPos.Y();
566 
567     m_nDragRowDividerLimit = nDragRowDividerCurrentPos - nDataRowHeight;
568 
569     GetParent()->bRowDividerDrag = sal_True;
570     GetParent()->ImplStartTracking();
571 
572 	Rectangle aDragSplitRect( 0, m_nDragRowDividerLimit, GetOutputSizePixel().Width(), nDragRowDividerCurrentPos );
573 	ShowTracking( aDragSplitRect, SHOWTRACK_SMALL );
574 
575     StartTracking();
576 }
577 
578 //-------------------------------------------------------------------
579 
Tracking(const TrackingEvent & rTEvt)580 void BrowserDataWin::Tracking( const TrackingEvent& rTEvt )
581 {
582     if ( !GetParent()->bRowDividerDrag )
583         return;
584 
585 	Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
586     // stop resizing at our bottom line
587     if ( aMousePos.Y() > GetOutputSizePixel().Height() )
588         aMousePos.Y() = GetOutputSizePixel().Height();
589 
590 	if ( rTEvt.IsTrackingEnded() )
591     {
592     	HideTracking();
593         GetParent()->bRowDividerDrag = sal_False;
594         GetParent()->ImplEndTracking();
595 
596         if ( !rTEvt.IsTrackingCanceled() )
597         {
598             long nNewRowHeight = aMousePos.Y() + m_nDragRowDividerOffset - m_nDragRowDividerLimit;
599 
600             // care for minimum row height
601             if ( nNewRowHeight < GetParent()->QueryMinimumRowHeight() )
602                 nNewRowHeight = GetParent()->QueryMinimumRowHeight();
603 
604             GetParent()->SetDataRowHeight( nNewRowHeight );
605             GetParent()->RowHeightChanged();
606         }
607     }
608 	else
609     {
610         GetParent()->ImplTracking();
611 
612         long nDragRowDividerCurrentPos = aMousePos.Y() + m_nDragRowDividerOffset;
613 
614         // care for minimum row height
615         if ( nDragRowDividerCurrentPos < m_nDragRowDividerLimit + GetParent()->QueryMinimumRowHeight() )
616             nDragRowDividerCurrentPos = m_nDragRowDividerLimit + GetParent()->QueryMinimumRowHeight();
617 
618         Rectangle aDragSplitRect( 0, m_nDragRowDividerLimit, GetOutputSizePixel().Width(), nDragRowDividerCurrentPos );
619         ShowTracking( aDragSplitRect, SHOWTRACK_SMALL );
620     }
621 }
622 
623 //-------------------------------------------------------------------
624 
KeyInput(const KeyEvent & rEvt)625 void BrowserDataWin::KeyInput( const KeyEvent& rEvt )
626 {
627 	// pass to parent window
628 	if ( !GetParent()->ProcessKey( rEvt ) )
629 		Control::KeyInput( rEvt );
630 }
631 
632 //-------------------------------------------------------------------
633 
RequestHelp(const HelpEvent & rHEvt)634 void BrowserDataWin::RequestHelp( const HelpEvent& rHEvt )
635 {
636 	pEventWin = this;
637 	GetParent()->RequestHelp( rHEvt );
638 	pEventWin = GetParent();
639 }
640 
641 //===================================================================
642 
BrowseEvent(Window * pWindow,long nAbsRow,sal_uInt16 nColumn,sal_uInt16 nColumnId,const Rectangle & rRect)643 BrowseEvent::BrowseEvent( Window* pWindow,
644 						  long nAbsRow, sal_uInt16 nColumn, sal_uInt16 nColumnId,
645 						  const Rectangle& rRect ):
646 	pWin(pWindow),
647 	nRow(nAbsRow),
648 	aRect(rRect),
649 	nCol(nColumn),
650 	nColId(nColumnId)
651 {
652 }
653 
654 //===================================================================
BrowserMouseEvent(BrowserDataWin * pWindow,const MouseEvent & rEvt)655 BrowserMouseEvent::BrowserMouseEvent( BrowserDataWin *pWindow,
656 						  const MouseEvent& rEvt ):
657 	MouseEvent(rEvt),
658 	BrowseEvent( pWindow->CreateBrowseEvent( rEvt.GetPosPixel() ) )
659 {
660 }
661 
662 //-------------------------------------------------------------------
663 
BrowserMouseEvent(Window * pWindow,const MouseEvent & rEvt,long nAbsRow,sal_uInt16 nColumn,sal_uInt16 nColumnId,const Rectangle & rRect)664 BrowserMouseEvent::BrowserMouseEvent( Window *pWindow, const MouseEvent& rEvt,
665 						  long nAbsRow, sal_uInt16 nColumn, sal_uInt16 nColumnId,
666 						  const Rectangle& rRect ):
667 	MouseEvent(rEvt),
668 	BrowseEvent( pWindow, nAbsRow, nColumn, nColumnId, rRect )
669 {
670 }
671 
672 //===================================================================
673 
BrowserAcceptDropEvent(BrowserDataWin * pWindow,const AcceptDropEvent & rEvt)674 BrowserAcceptDropEvent::BrowserAcceptDropEvent( BrowserDataWin *pWindow, const AcceptDropEvent& rEvt )
675 	:AcceptDropEvent(rEvt)
676 	,BrowseEvent( pWindow->CreateBrowseEvent( rEvt.maPosPixel ) )
677 {
678 }
679 
680 //===================================================================
681 
BrowserExecuteDropEvent(BrowserDataWin * pWindow,const ExecuteDropEvent & rEvt)682 BrowserExecuteDropEvent::BrowserExecuteDropEvent( BrowserDataWin *pWindow, const ExecuteDropEvent& rEvt )
683 	:ExecuteDropEvent(rEvt)
684 	,BrowseEvent( pWindow->CreateBrowseEvent( rEvt.maPosPixel ) )
685 {
686 }
687 
688 //===================================================================
689 
690 //-------------------------------------------------------------------
691 
SetUpdateMode(sal_Bool bMode)692 void BrowserDataWin::SetUpdateMode( sal_Bool bMode )
693 {
694 	DBG_ASSERT( !bUpdateMode || aInvalidRegion.Count() == 0,
695 				"invalid region not empty" );
696 	if ( bMode == bUpdateMode )
697 		return;
698 
699 	bUpdateMode = bMode;
700 	if ( bMode )
701 		DoOutstandingInvalidations();
702 }
703 
704 //-------------------------------------------------------------------
DoOutstandingInvalidations()705 void BrowserDataWin::DoOutstandingInvalidations()
706 {
707 	for ( Rectangle* pRect = aInvalidRegion.First();
708 		  pRect;
709 		  pRect = aInvalidRegion.Next() )
710 	{
711 		Control::Invalidate( *pRect );
712 		delete pRect;
713 	}
714 	aInvalidRegion.Clear();
715 }
716 
717 //-------------------------------------------------------------------
718 
Invalidate(sal_uInt16 nFlags)719 void BrowserDataWin::Invalidate( sal_uInt16 nFlags )
720 {
721 	if ( !GetUpdateMode() )
722 	{
723 		for ( Rectangle* pRect = aInvalidRegion.First();
724 			  pRect;
725 			  pRect = aInvalidRegion.Next() )
726 			delete pRect;
727 		aInvalidRegion.Clear();
728 		aInvalidRegion.Insert( new Rectangle( Point( 0, 0 ), GetOutputSizePixel() ) );
729 	}
730 	else
731 		Window::Invalidate( nFlags );
732 }
733 
734 //-------------------------------------------------------------------
735 
Invalidate(const Rectangle & rRect,sal_uInt16 nFlags)736 void BrowserDataWin::Invalidate( const Rectangle& rRect, sal_uInt16 nFlags )
737 {
738 	if ( !GetUpdateMode() )
739 		aInvalidRegion.Insert( new Rectangle( rRect ) );
740 	else
741 		Window::Invalidate( rRect, nFlags );
742 }
743 
744 //===================================================================
745 
Tracking(const TrackingEvent & rTEvt)746 void BrowserScrollBar::Tracking( const TrackingEvent& rTEvt )
747 {
748 	sal_uLong nPos = GetThumbPos();
749 	if ( nPos != _nLastPos )
750 	{
751 		String aTip( String::CreateFromInt32(nPos) );
752 		aTip += '/';
753 		if ( _pDataWin->GetRealRowCount().Len() )
754 			aTip += _pDataWin->GetRealRowCount();
755 		else
756 			aTip += String::CreateFromInt32(GetRangeMax());
757 
758         Rectangle aRect( GetPointerPosPixel(), Size( GetTextHeight(), GetTextWidth( aTip ) ) );
759         if ( _nTip )
760             Help::UpdateTip( _nTip, this, aRect, aTip );
761 		else
762             _nTip = Help::ShowTip( this, aRect, aTip );
763 		_nLastPos = nPos;
764 	}
765 
766 	ScrollBar::Tracking( rTEvt );
767 }
768 
769 //-------------------------------------------------------------------
770 
EndScroll()771 void BrowserScrollBar::EndScroll()
772 {
773 	if ( _nTip )
774 		Help::HideTip( _nTip );
775 	_nTip = 0;
776 	ScrollBar::EndScroll();
777 }
778 
779 
780