update dev300-m58
[ooovba.git] / svtools / source / brwbox / brwbox2.cxx
blobf1e5fa6ef8db2ad936929c9bd0552184f8bec05f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: brwbox2.cxx,v $
10 * $Revision: 1.39 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <tools/debug.hxx>
34 #include <svtools/brwbox.hxx>
35 #include "datwin.hxx"
36 #include <svtools/colorcfg.hxx>
37 #include <vcl/salgtype.hxx>
39 #ifndef GCC
40 #endif
41 #include <tools/multisel.hxx>
42 #include <algorithm>
44 using namespace ::com::sun::star::datatransfer;
46 #define getDataWindow() ((BrowserDataWin*)pDataWin)
49 //===================================================================
51 DBG_NAMEEX(BrowseBox)
53 //===================================================================
55 extern const char* BrowseBoxCheckInvariants( const void * pVoid );
57 DECLARE_LIST( BrowserColumns, BrowserColumn* )
59 //===================================================================
61 void BrowseBox::StartDrag( sal_Int8 /* _nAction */, const Point& /* _rPosPixel */ )
63 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
64 // not interested in this event
67 //===================================================================
69 sal_Int8 BrowseBox::AcceptDrop( const AcceptDropEvent& _rEvt )
71 BrowserDataWin* pDataWindow = static_cast<BrowserDataWin*>(pDataWin);
72 AcceptDropEvent aTransformed( _rEvt );
73 aTransformed.maPosPixel = pDataWindow->ScreenToOutputPixel( OutputToScreenPixel( _rEvt.maPosPixel ) );
74 return pDataWindow->AcceptDrop( aTransformed );
77 //===================================================================
79 sal_Int8 BrowseBox::ExecuteDrop( const ExecuteDropEvent& _rEvt )
81 BrowserDataWin* pDataWindow = static_cast<BrowserDataWin*>(pDataWin);
82 ExecuteDropEvent aTransformed( _rEvt );
83 aTransformed.maPosPixel = pDataWindow->ScreenToOutputPixel( OutputToScreenPixel( _rEvt.maPosPixel ) );
84 return pDataWindow->ExecuteDrop( aTransformed );
87 //===================================================================
89 sal_Int8 BrowseBox::AcceptDrop( const BrowserAcceptDropEvent& )
91 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
92 // not interested in this event
93 return DND_ACTION_NONE;
96 //===================================================================
98 sal_Int8 BrowseBox::ExecuteDrop( const BrowserExecuteDropEvent& )
100 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
101 // not interested in this event
102 return DND_ACTION_NONE;
105 //===================================================================
107 void* BrowseBox::implGetDataFlavors() const
109 if (static_cast<BrowserDataWin*>(pDataWin)->bCallingDropCallback)
110 return &static_cast<BrowserDataWin*>(pDataWin)->GetDataFlavorExVector();
111 return &GetDataFlavorExVector();
114 //===================================================================
116 sal_Bool BrowseBox::IsDropFormatSupported( SotFormatStringId _nFormat )
118 if ( static_cast< BrowserDataWin* >( pDataWin )->bCallingDropCallback )
119 return static_cast< BrowserDataWin* >( pDataWin )->IsDropFormatSupported( _nFormat );
121 return DropTargetHelper::IsDropFormatSupported( _nFormat );
124 //===================================================================
126 sal_Bool BrowseBox::IsDropFormatSupported( SotFormatStringId _nFormat ) const
128 return const_cast< BrowseBox* >( this )->IsDropFormatSupported( _nFormat );
131 //===================================================================
133 sal_Bool BrowseBox::IsDropFormatSupported( const DataFlavor& _rFlavor )
135 if ( static_cast< BrowserDataWin* >( pDataWin )->bCallingDropCallback )
136 return static_cast< BrowserDataWin* >( pDataWin )->IsDropFormatSupported( _rFlavor );
138 return DropTargetHelper::IsDropFormatSupported( _rFlavor );
141 //===================================================================
143 sal_Bool BrowseBox::IsDropFormatSupported( const DataFlavor& _rFlavor ) const
145 return const_cast< BrowseBox* >( this )->IsDropFormatSupported( _rFlavor );
148 //===================================================================
150 void BrowseBox::Command( const CommandEvent& rEvt )
152 if ( !getDataWindow()->bInCommand )
153 Control::Command( rEvt );
156 //===================================================================
158 bool BrowseBox::IsInCommandEvent() const
160 return getDataWindow()->bInCommand;
163 //===================================================================
165 void BrowseBox::StateChanged( StateChangedType nStateChange )
167 Control::StateChanged( nStateChange );
169 if ( STATE_CHANGE_MIRRORING == nStateChange )
171 getDataWindow()->EnableRTL( IsRTLEnabled() );
173 HeaderBar* pHeaderBar = getDataWindow()->pHeaderBar;
174 if ( pHeaderBar )
175 pHeaderBar->EnableRTL( IsRTLEnabled() );
176 aHScroll.EnableRTL( IsRTLEnabled() );
177 if( pVScroll )
178 pVScroll->EnableRTL( IsRTLEnabled() );
179 Resize();
181 else if ( STATE_CHANGE_INITSHOW == nStateChange )
183 bBootstrapped = TRUE; // muss zuerst gesetzt werden!
185 Resize();
186 if ( bMultiSelection )
187 uRow.pSel->SetTotalRange( Range( 0, nRowCount - 1 ) );
188 if ( nRowCount == 0 )
189 nCurRow = BROWSER_ENDOFSELECTION;
190 else if ( nCurRow == BROWSER_ENDOFSELECTION )
191 nCurRow = 0;
194 if ( HasFocus() )
196 bSelectionIsVisible = TRUE;
197 bHasFocus = TRUE;
199 UpdateScrollbars();
200 AutoSizeLastColumn();
201 CursorMoved();
203 else if (STATE_CHANGE_ZOOM == nStateChange)
205 pDataWin->SetZoom(GetZoom());
206 HeaderBar* pHeaderBar = getDataWindow()->pHeaderBar;
207 if (pHeaderBar)
208 pHeaderBar->SetZoom(GetZoom());
210 // let the cols calc their new widths and adjust the header bar
211 for ( USHORT nPos = 0; nPos < pCols->Count(); ++nPos )
213 pCols->GetObject(nPos)->ZoomChanged(GetZoom());
214 if ( pHeaderBar )
215 pHeaderBar->SetItemSize( pCols->GetObject(nPos)->GetId(), pCols->GetObject(nPos)->Width() );
218 // all our controls have to be repositioned
219 Resize();
221 else if (STATE_CHANGE_ENABLE == nStateChange)
223 // do we have a handle column?
224 sal_Bool bHandleCol = pCols->Count() && (0 == pCols->GetObject(0)->GetId());
225 // do we have a header bar
226 sal_Bool bHeaderBar = (NULL != static_cast<BrowserDataWin&>(GetDataWindow()).pHeaderBar);
228 if ( nTitleLines
229 && ( !bHeaderBar
230 || bHandleCol
233 // we draw the text in our header bar in a color dependent on the enabled state. So if this state changed
234 // -> redraw
235 Invalidate(Rectangle(Point(0, 0), Size(GetOutputSizePixel().Width(), GetTitleHeight() - 1)));
239 //===================================================================
241 void BrowseBox::Select()
243 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
246 //-------------------------------------------------------------------
248 void BrowseBox::DoubleClick( const BrowserMouseEvent & )
250 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
253 //-------------------------------------------------------------------
255 long BrowseBox::QueryMinimumRowHeight()
257 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
258 return CalcZoom( 5 );
261 //-------------------------------------------------------------------
263 void BrowseBox::ImplStartTracking()
265 DBG_CHKTHIS( BrowseBox, BrowseBoxCheckInvariants );
268 //-------------------------------------------------------------------
270 void BrowseBox::ImplTracking()
272 DBG_CHKTHIS( BrowseBox, BrowseBoxCheckInvariants );
275 //-------------------------------------------------------------------
277 void BrowseBox::ImplEndTracking()
279 DBG_CHKTHIS( BrowseBox, BrowseBoxCheckInvariants );
282 //-------------------------------------------------------------------
284 void BrowseBox::RowHeightChanged()
286 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
289 //-------------------------------------------------------------------
291 long BrowseBox::QueryColumnResize( USHORT, long nWidth )
293 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
294 return nWidth;
297 //-------------------------------------------------------------------
299 void BrowseBox::ColumnResized( USHORT )
301 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
304 //-------------------------------------------------------------------
306 void BrowseBox::ColumnMoved( USHORT )
308 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
311 //-------------------------------------------------------------------
313 void BrowseBox::StartScroll()
315 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
316 //((Control*)pDataWin)->HideFocus();
317 DoHideCursor( "StartScroll" );
320 //-------------------------------------------------------------------
322 void BrowseBox::EndScroll()
324 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
325 UpdateScrollbars();
326 AutoSizeLastColumn();
327 DoShowCursor( "EndScroll" );
330 //-------------------------------------------------------------------
332 #ifdef _MSC_VER
333 #pragma optimize( "", off )
334 #endif
336 void BrowseBox::ToggleSelection( BOOL bForce )
338 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
340 // selection highlight-toggling allowed?
341 if ( bHideSelect )
342 return;
343 if ( !bForce &&
344 ( bNotToggleSel || !IsUpdateMode() || !bSelectionIsVisible ) )
345 return;
346 //MI, 28.01.98
347 // if ( !getDataWindow()->bHighlightToggle &&
348 // !getDataWindow()->bHighlightAuto )
349 // return;
351 // only highlight painted areas!
352 bNotToggleSel = TRUE;
353 if ( FALSE && !getDataWindow()->bInPaint )
354 pDataWin->Update();
356 // accumulate areas of rows to highlight
357 RectangleList aHighlightList;
358 long nLastRowInRect = 0; // fuer den CFront
360 // Handle-Column nicht highlighten
361 BrowserColumn *pFirstCol = pCols->GetObject(0);
362 long nOfsX = (!pFirstCol || pFirstCol->GetId()) ? 0 : pFirstCol->Width();
364 // accumulate old row selection
365 long nBottomRow = nTopRow +
366 pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight();
367 if ( nBottomRow > GetRowCount() && GetRowCount() )
368 nBottomRow = GetRowCount();
369 for ( long nRow = bMultiSelection ? uRow.pSel->FirstSelected() : uRow.nSel;
370 nRow != BROWSER_ENDOFSELECTION && nRow <= nBottomRow;
371 nRow = bMultiSelection ? uRow.pSel->NextSelected() : BROWSER_ENDOFSELECTION )
373 if ( nRow < nTopRow )
374 continue;
376 Rectangle aAddRect(
377 Point( nOfsX, (nRow-nTopRow)*GetDataRowHeight() ),
378 Size( pDataWin->GetSizePixel().Width(), GetDataRowHeight() ) );
379 if ( aHighlightList.Count() && nLastRowInRect == ( nRow - 1 ) )
380 aHighlightList.First()->Union( aAddRect );
381 else
382 aHighlightList.Insert( new Rectangle( aAddRect ), (ULONG) 0 );
383 nLastRowInRect = nRow;
386 // unhighlight the old selection (if any)
387 while ( aHighlightList.Count() )
389 Rectangle *pRect = aHighlightList.Remove( aHighlightList.Count() - 1 );
390 pDataWin->Invalidate( *pRect );
391 delete pRect;
394 // unhighlight old column selection (if any)
395 for ( long nColId = pColSel ? pColSel->FirstSelected() : BROWSER_ENDOFSELECTION;
396 nColId != BROWSER_ENDOFSELECTION;
397 nColId = pColSel->NextSelected() )
399 Rectangle aRect( GetFieldRectPixel(nCurRow,
400 pCols->GetObject(nColId)->GetId(),
401 FALSE ) );
402 aRect.Left() -= MIN_COLUMNWIDTH;
403 aRect.Right() += MIN_COLUMNWIDTH;
404 aRect.Top() = 0;
405 aRect.Bottom() = pDataWin->GetOutputSizePixel().Height();
406 pDataWin->Invalidate( aRect );
409 bNotToggleSel = FALSE;
412 #ifdef _MSC_VER
413 #pragma optimize( "", on )
414 #endif
416 //-------------------------------------------------------------------
418 void BrowseBox::DrawCursor()
420 BOOL bReallyHide = FALSE;
421 if ( SMART_CURSOR_HIDE == bHideCursor )
423 if ( !GetSelectRowCount() && !GetSelectColumnCount() )
424 bReallyHide = TRUE;
426 else if ( HARD_CURSOR_HIDE == bHideCursor )
428 bReallyHide = TRUE;
431 bReallyHide |= !bSelectionIsVisible || !IsUpdateMode() || bScrolling || nCurRow < 0;
433 if (PaintCursorIfHiddenOnce())
434 bReallyHide |= ( GetCursorHideCount() > 1 );
435 else
436 bReallyHide |= ( GetCursorHideCount() > 0 );
438 // keine Cursor auf Handle-Column
439 if ( nCurColId == 0 )
440 nCurColId = GetColumnId(1);
442 // Cursor-Rechteck berechnen
443 Rectangle aCursor;
444 if ( bColumnCursor )
446 aCursor = GetFieldRectPixel( nCurRow, nCurColId, FALSE );
447 //! --aCursor.Bottom();
448 aCursor.Left() -= MIN_COLUMNWIDTH;
449 aCursor.Right() += 1;
450 aCursor.Bottom() += 1;
452 else
453 aCursor = Rectangle(
454 Point( ( pCols->Count() && pCols->GetObject(0)->GetId() == 0 ) ?
455 pCols->GetObject(0)->Width() : 0,
456 (nCurRow - nTopRow) * GetDataRowHeight() + 1 ),
457 Size( pDataWin->GetOutputSizePixel().Width() + 1,
458 GetDataRowHeight() - 2 ) );
459 if ( bHLines )
461 if ( !bMultiSelection )
462 --aCursor.Top();
463 --aCursor.Bottom();
466 //!mi_mac pDataWin->Update();
468 if (m_aCursorColor == COL_TRANSPARENT)
470 // auf diesem Plattformen funktioniert der StarView-Focus richtig
471 if ( bReallyHide )
472 ((Control*)pDataWin)->HideFocus();
473 else
474 ((Control*)pDataWin)->ShowFocus( aCursor );
476 else
478 Color rCol = bReallyHide ? pDataWin->GetFillColor() : m_aCursorColor;
479 Color aOldFillColor = pDataWin->GetFillColor();
480 Color aOldLineColor = pDataWin->GetLineColor();
481 pDataWin->SetFillColor();
482 pDataWin->SetLineColor( rCol );
483 pDataWin->DrawRect( aCursor );
484 pDataWin->SetLineColor( aOldLineColor );
485 pDataWin->SetFillColor( aOldFillColor );
489 //-------------------------------------------------------------------
491 ULONG BrowseBox::GetColumnWidth( USHORT nId ) const
493 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
495 USHORT nItemPos = GetColumnPos( nId );
496 if ( nItemPos >= pCols->Count() )
497 return 0;
498 return pCols->GetObject(nItemPos)->Width();
501 //-------------------------------------------------------------------
503 USHORT BrowseBox::GetColumnId( USHORT nPos ) const
505 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
507 if ( nPos >= pCols->Count() )
508 return 0;
509 return pCols->GetObject(nPos)->GetId();
512 //-------------------------------------------------------------------
514 USHORT BrowseBox::GetColumnPos( USHORT nId ) const
516 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
518 for ( USHORT nPos = 0; nPos < pCols->Count(); ++nPos )
519 if ( pCols->GetObject(nPos)->GetId() == nId )
520 return nPos;
521 return BROWSER_INVALIDID;
524 //-------------------------------------------------------------------
526 BOOL BrowseBox::IsFrozen( USHORT nColumnId ) const
528 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
530 for ( USHORT nPos = 0; nPos < pCols->Count(); ++nPos )
531 if ( pCols->GetObject(nPos)->GetId() == nColumnId )
532 return pCols->GetObject(nPos)->IsFrozen();
533 return FALSE;
536 //-------------------------------------------------------------------
538 void BrowseBox::ExpandRowSelection( const BrowserMouseEvent& rEvt )
540 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
542 DoHideCursor( "ExpandRowSelection" );
544 // expand the last selection
545 if ( bMultiSelection )
547 Range aJustifiedRange( aSelRange );
548 aJustifiedRange.Justify();
550 BOOL bSelectThis = ( bSelect != aJustifiedRange.IsInside( rEvt.GetRow() ) );
552 if ( aJustifiedRange.IsInside( rEvt.GetRow() ) )
554 // down and up
555 while ( rEvt.GetRow() < aSelRange.Max() )
556 { // ZTC/Mac bug - dont put these statemants together!
557 SelectRow( aSelRange.Max(), bSelectThis, TRUE );
558 --aSelRange.Max();
560 while ( rEvt.GetRow() > aSelRange.Max() )
561 { // ZTC/Mac bug - dont put these statemants together!
562 SelectRow( aSelRange.Max(), bSelectThis, TRUE );
563 ++aSelRange.Max();
566 else
568 // up and down
569 BOOL bOldSelecting = bSelecting;
570 bSelecting = TRUE;
571 while ( rEvt.GetRow() < aSelRange.Max() )
572 { // ZTC/Mac bug - dont put these statemants together!
573 --aSelRange.Max();
574 if ( !IsRowSelected( aSelRange.Max() ) )
576 SelectRow( aSelRange.Max(), bSelectThis, TRUE );
577 bSelect = TRUE;
580 while ( rEvt.GetRow() > aSelRange.Max() )
581 { // ZTC/Mac bug - dont put these statemants together!
582 ++aSelRange.Max();
583 if ( !IsRowSelected( aSelRange.Max() ) )
585 SelectRow( aSelRange.Max(), bSelectThis, TRUE );
586 bSelect = TRUE;
589 bSelecting = bOldSelecting;
590 if ( bSelect )
591 Select();
594 else
595 if ( !bMultiSelection || !IsRowSelected( rEvt.GetRow() ) )
596 SelectRow( rEvt.GetRow(), TRUE );
598 GoToRow( rEvt.GetRow(), FALSE );
599 DoShowCursor( "ExpandRowSelection" );
602 //-------------------------------------------------------------------
604 void BrowseBox::Resize()
606 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
607 if ( !bBootstrapped && IsReallyVisible() )
608 BrowseBox::StateChanged( STATE_CHANGE_INITSHOW );
609 if ( !pCols->Count() )
611 getDataWindow()->bResizeOnPaint = TRUE;
612 return;
614 getDataWindow()->bResizeOnPaint = FALSE;
616 // calc the size of the scrollbars
617 // (we can't ask the scrollbars for their widths cause if we're zoomed they still have to be
618 // resized - which is done in UpdateScrollbars)
619 ULONG nSBSize = GetSettings().GetStyleSettings().GetScrollBarSize();
620 if (IsZoom())
621 nSBSize = (ULONG)(nSBSize * (double)GetZoom());
623 long nSize = pDataWin->GetPosPixel().Y();
624 if( !getDataWindow()->bNoHScroll )
625 nSize += aHScroll.GetSizePixel().Height();
627 if ( GetOutputSizePixel().Height() < nSize )
628 return;
630 DoHideCursor( "Resize" );
631 USHORT nOldVisibleRows =
632 (USHORT)(pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight() + 1);
634 // did we need a horiz. scroll bar oder gibt es eine Control Area?
635 if ( !getDataWindow()->bNoHScroll &&
636 ( ( pCols->Count() - FrozenColCount() ) > 1 ) )
637 aHScroll.Show();
638 else
639 aHScroll.Hide();
641 // calculate the size of the data window
642 long nDataHeight = GetOutputSizePixel().Height() - GetTitleHeight();
643 if ( aHScroll.IsVisible() || ( nControlAreaWidth != USHRT_MAX ) )
644 nDataHeight -= nSBSize;
646 long nDataWidth = GetOutputSizePixel().Width();
647 if ( pVScroll->IsVisible() )
648 nDataWidth -= nSBSize;
650 // adjust position and size of data window
651 pDataWin->SetPosSizePixel(
652 Point( 0, GetTitleHeight() ),
653 Size( nDataWidth, nDataHeight ) );
655 USHORT nVisibleRows =
656 (USHORT)(pDataWin->GetOutputSizePixel().Height() / GetDataRowHeight() + 1);
658 // TopRow ist unveraendert, aber die Anzahl sichtbarer Zeilen hat sich
659 // geaendert
660 if ( nVisibleRows != nOldVisibleRows )
661 VisibleRowsChanged(nTopRow, nVisibleRows);
663 UpdateScrollbars();
665 // Control-Area
666 Rectangle aInvalidArea( GetControlArea() );
667 aInvalidArea.Right() = GetOutputSizePixel().Width();
668 aInvalidArea.Left() = 0;
669 Invalidate( aInvalidArea );
671 // external header-bar
672 HeaderBar* pHeaderBar = getDataWindow()->pHeaderBar;
673 if ( pHeaderBar )
675 // Handle-Column beruecksichtigen
676 BrowserColumn *pFirstCol = pCols->GetObject(0);
677 long nOfsX = pFirstCol->GetId() ? 0 : pFirstCol->Width();
678 pHeaderBar->SetPosSizePixel( Point( nOfsX, 0 ), Size( GetOutputSizePixel().Width() - nOfsX, GetTitleHeight() ) );
681 AutoSizeLastColumn(); // adjust last column width
682 DoShowCursor( "Resize" );
685 //-------------------------------------------------------------------
687 void BrowseBox::Paint( const Rectangle& rRect )
689 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
691 // initializations
692 if ( !bBootstrapped && IsReallyVisible() )
693 BrowseBox::StateChanged( STATE_CHANGE_INITSHOW );
694 if ( !pCols->Count() )
695 return;
697 BrowserColumn *pFirstCol = pCols->GetObject(0);
698 BOOL bHandleCol = pFirstCol && pFirstCol->GetId() == 0;
699 BOOL bHeaderBar = getDataWindow()->pHeaderBar != NULL;
701 // draw delimitational lines
702 if ( !getDataWindow()->bNoHScroll )
703 DrawLine( Point( 0, aHScroll.GetPosPixel().Y() ),
704 Point( GetOutputSizePixel().Width(),
705 aHScroll.GetPosPixel().Y() ) );
707 if ( nTitleLines )
709 if ( !bHeaderBar )
710 DrawLine( Point( 0, GetTitleHeight() - 1 ),
711 Point( GetOutputSizePixel().Width(),
712 GetTitleHeight() - 1 ) );
713 else if ( bHandleCol )
714 DrawLine( Point( 0, GetTitleHeight() - 1 ),
715 Point( pFirstCol->Width(), GetTitleHeight() - 1 ) );
718 // Title Bar
719 // Wenn es eine Handle Column gibt und die Headerbar verfuegbar ist, dann nur
720 // die HandleColumn
721 // Handle-Column beruecksichtigen
722 if ( nTitleLines && (!bHeaderBar || bHandleCol) )
724 // iterate through columns to redraw
725 long nX = 0;
726 USHORT nCol;
727 for ( nCol = 0;
728 nCol < pCols->Count() && nX < rRect.Right();
729 ++nCol )
731 // skip invisible colums between frozen and scrollable area
732 if ( nCol < nFirstCol && !pCols->GetObject(nCol)->IsFrozen() )
733 nCol = nFirstCol;
735 // nur die HandleCol ?
736 if (bHeaderBar && bHandleCol && nCol > 0)
737 break;
739 BrowserColumn *pCol = pCols->GetObject(nCol);
741 // draw the column and increment position
742 if ( pCol->Width() > 4 )
744 ButtonFrame aButtonFrame( Point( nX, 0 ),
745 Size( pCol->Width()-1, GetTitleHeight()-1 ),
746 pCol->Title(), FALSE, FALSE,
747 0 != (BROWSER_COLUMN_TITLEABBREVATION&pCol->Flags()),
748 !IsEnabled());
749 aButtonFrame.Draw( *this );
750 DrawLine( Point( nX + pCol->Width() - 1, 0 ),
751 Point( nX + pCol->Width() - 1, GetTitleHeight()-1 ) );
753 else
755 Color aOldFillColor = GetFillColor();
756 SetFillColor( Color( COL_BLACK ) );
757 DrawRect( Rectangle( Point( nX, 0 ), Size( pCol->Width(), GetTitleHeight() - 1 ) ) );
758 SetFillColor( aOldFillColor );
761 // skip column
762 nX += pCol->Width();
765 // retouching
766 if ( !bHeaderBar && nCol == pCols->Count() )
768 const StyleSettings &rSettings = GetSettings().GetStyleSettings();
769 Color aColFace( rSettings.GetFaceColor() );
770 Color aOldFillColor = GetFillColor();
771 Color aOldLineColor = GetLineColor();
772 SetFillColor( aColFace );
773 SetLineColor( aColFace );
774 DrawRect( Rectangle(
775 Point( nX, 0 ),
776 Point( rRect.Right(), GetTitleHeight() - 2 ) ) );
777 SetFillColor( aOldFillColor); // aOldLineColor ); oj 09.02.00 seems to be a copy&paste bug
778 SetLineColor( aOldLineColor); // aOldFillColor );
783 //-------------------------------------------------------------------
785 void BrowseBox::PaintRow( OutputDevice&, const Rectangle& )
789 //-------------------------------------------------------------------
791 void BrowseBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, ULONG nFlags )
793 BOOL bDrawSelection = (nFlags & WINDOW_DRAW_NOSELECTION) == 0;
795 // we need pixel coordinates
796 Size aRealSize = pDev->LogicToPixel(rSize);
797 Point aRealPos = pDev->LogicToPixel(rPos);
799 if ((rSize.Width() < 3) || (rSize.Height() < 3))
800 // we want to have two pixels frame ...
801 return;
803 Font aFont = GetDataWindow().GetDrawPixelFont( pDev );
804 // the 'normal' painting uses always the data window as device to output to, so we have to calc the new font
805 // relative to the data wins current settings
807 pDev->Push();
808 pDev->SetMapMode();
809 pDev->SetFont( aFont );
811 // draw a frame
812 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
813 pDev->SetLineColor(rStyleSettings.GetDarkShadowColor());
814 pDev->DrawLine(Point(aRealPos.X(), aRealPos.Y()),
815 Point(aRealPos.X(), aRealPos.Y() + aRealSize.Height() - 1));
816 pDev->DrawLine(Point(aRealPos.X(), aRealPos.Y()),
817 Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y()));
818 pDev->SetLineColor(rStyleSettings.GetShadowColor());
819 pDev->DrawLine(Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y() + 1),
820 Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y() + aRealSize.Height() - 1));
821 pDev->DrawLine(Point(aRealPos.X() + aRealSize.Width() - 1, aRealPos.Y() + aRealSize.Height() - 1),
822 Point(aRealPos.X() + 1, aRealPos.Y() + aRealSize.Height() - 1));
824 HeaderBar* pBar = getDataWindow()->pHeaderBar;
826 // we're drawing onto a foreign device, so we have to fake the DataRowHeight for the subsequent ImplPaintData
827 // (as it is based on the settings of our data window, not the foreign device)
828 if (!nDataRowHeight)
829 ImpGetDataRowHeight();
830 long nHeightLogic = PixelToLogic(Size(0, nDataRowHeight), MAP_10TH_MM).Height();
831 long nForeignHeightPixel = pDev->LogicToPixel(Size(0, nHeightLogic), MAP_10TH_MM).Height();
833 long nOriginalHeight = nDataRowHeight;
834 nDataRowHeight = nForeignHeightPixel;
836 // this counts for the column widths, too
837 USHORT nPos;
838 for ( nPos = 0; nPos < pCols->Count(); ++nPos )
840 BrowserColumn* pCurrent = pCols->GetObject(nPos);
842 long nWidthLogic = PixelToLogic(Size(pCurrent->Width(), 0), MAP_10TH_MM).Width();
843 long nForeignWidthPixel = pDev->LogicToPixel(Size(nWidthLogic, 0), MAP_10TH_MM).Width();
845 pCurrent->SetWidth(nForeignWidthPixel, GetZoom());
846 if ( pBar )
847 pBar->SetItemSize( pCurrent->GetId(), pCurrent->Width() );
850 // a smaller area for the content
851 ++aRealPos.X();
852 ++aRealPos.Y();
853 aRealSize.Width() -= 2;
854 aRealSize.Height() -= 2;
856 // let the header bar draw itself
857 if ( pBar )
859 // the title height with respect to the font set for the given device
860 long nTitleHeight = PixelToLogic(Size(0, GetTitleHeight()), MAP_10TH_MM).Height();
861 nTitleHeight = pDev->LogicToPixel(Size(0, nTitleHeight), MAP_10TH_MM).Height();
863 BrowserColumn* pFirstCol = pCols->Count() ? pCols->GetObject(0) : NULL;
865 Point aHeaderPos(pFirstCol && (pFirstCol->GetId() == 0) ? pFirstCol->Width() : 0, 0);
866 Size aHeaderSize(aRealSize.Width() - aHeaderPos.X(), nTitleHeight);
868 aHeaderPos += aRealPos;
869 // do this before converting to logics !
871 // the header's draw expects logic coordinates, again
872 aHeaderPos = pDev->PixelToLogic(aHeaderPos);
873 aHeaderSize = pDev->PixelToLogic(aHeaderSize);
875 pBar->Draw(pDev, aHeaderPos, aHeaderSize, nFlags);
877 // draw the "upper left cell" (the intersection between the header bar and the handle column)
878 if (( pFirstCol->GetId() == 0 ) && ( pFirstCol->Width() > 4 ))
880 ButtonFrame aButtonFrame( aRealPos,
881 Size( pFirstCol->Width()-1, nTitleHeight-1 ),
882 pFirstCol->Title(), FALSE, FALSE, FALSE, !IsEnabled());
883 aButtonFrame.Draw( *pDev );
885 pDev->Push( PUSH_LINECOLOR );
886 pDev->SetLineColor( Color( COL_BLACK ) );
888 pDev->DrawLine( Point( aRealPos.X(), aRealPos.Y() + nTitleHeight-1 ),
889 Point( aRealPos.X() + pFirstCol->Width() - 1, aRealPos.Y() + nTitleHeight-1 ) );
890 pDev->DrawLine( Point( aRealPos.X() + pFirstCol->Width() - 1, aRealPos.Y() ),
891 Point( aRealPos.X() + pFirstCol->Width() - 1, aRealPos.Y() + nTitleHeight-1 ) );
893 pDev->Pop();
896 aRealPos.Y() += aHeaderSize.Height();
897 aRealSize.Height() -= aHeaderSize.Height();
900 // draw our own content (with clipping)
901 Region aRegion(Rectangle(aRealPos, aRealSize));
902 pDev->SetClipRegion( pDev->PixelToLogic( aRegion ) );
904 // do we have to paint the background
905 BOOL bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && GetDataWindow().IsControlBackground();
906 if ( bBackground )
908 Rectangle aRect( aRealPos, aRealSize );
909 pDev->SetFillColor( GetDataWindow().GetControlBackground() );
910 pDev->DrawRect( aRect );
913 ImplPaintData( *pDev, Rectangle( aRealPos, aRealSize ), TRUE, bDrawSelection );
915 // restore the column widths/data row height
916 nDataRowHeight = nOriginalHeight;
917 for ( nPos = 0; nPos < pCols->Count(); ++nPos )
919 BrowserColumn* pCurrent = pCols->GetObject(nPos);
921 long nForeignWidthLogic = pDev->PixelToLogic(Size(pCurrent->Width(), 0), MAP_10TH_MM).Width();
922 long nWidthPixel = LogicToPixel(Size(nForeignWidthLogic, 0), MAP_10TH_MM).Width();
924 pCurrent->SetWidth(nWidthPixel, GetZoom());
925 if ( pBar )
926 pBar->SetItemSize( pCurrent->GetId(), pCurrent->Width() );
929 pDev->Pop();
932 //-------------------------------------------------------------------
934 void BrowseBox::ImplPaintData(OutputDevice& _rOut, const Rectangle& _rRect, BOOL _bForeignDevice, BOOL _bDrawSelections)
936 Point aOverallAreaPos = _bForeignDevice ? _rRect.TopLeft() : Point(0,0);
937 Size aOverallAreaSize = _bForeignDevice ? _rRect.GetSize() : GetDataWindow().GetOutputSizePixel();
938 Point aOverallAreaBRPos = _bForeignDevice ? _rRect.BottomRight() : Point( aOverallAreaSize.Width(), aOverallAreaSize.Height() );
940 long nDataRowHeigt = GetDataRowHeight();
942 // compute relative rows to redraw
943 ULONG nRelTopRow = _bForeignDevice ? 0 : ((ULONG)_rRect.Top() / nDataRowHeigt);
944 ULONG nRelBottomRow = (ULONG)(_bForeignDevice ? aOverallAreaSize.Height() : _rRect.Bottom()) / nDataRowHeigt;
946 // cache frequently used values
947 Point aPos( aOverallAreaPos.X(), nRelTopRow * nDataRowHeigt + aOverallAreaPos.Y() );
948 _rOut.SetLineColor( Color( COL_WHITE ) );
949 const AllSettings& rAllSets = _rOut.GetSettings();
950 const StyleSettings &rSettings = rAllSets.GetStyleSettings();
951 const Color &rHighlightTextColor = rSettings.GetHighlightTextColor();
952 const Color &rHighlightFillColor = rSettings.GetHighlightColor();
953 Color aOldTextColor = _rOut.GetTextColor();
954 Color aOldFillColor = _rOut.GetFillColor();
955 Color aOldLineColor = _rOut.GetLineColor();
956 long nHLineX = 0 == pCols->GetObject(0)->GetId()
957 ? pCols->GetObject(0)->Width()
958 : 0;
959 nHLineX += aOverallAreaPos.X();
961 Color aDelimiterLineColor( ::svtools::ColorConfig().GetColorValue( ::svtools::CALCGRID ).nColor );
963 // redraw the invalid fields
964 BOOL bRetouching = FALSE;
965 for ( ULONG nRelRow = nRelTopRow;
966 nRelRow <= nRelBottomRow && (ULONG)nTopRow+nRelRow < (ULONG)nRowCount;
967 ++nRelRow, aPos.Y() += nDataRowHeigt )
969 // get row
970 // Zur Sicherheit auf zul"assigen Bereich abfragen:
971 DBG_ASSERT( (USHORT)(nTopRow+nRelRow) < nRowCount, "BrowseBox::ImplPaintData: invalid seek" );
972 if ( (nTopRow+long(nRelRow)) < 0 || (USHORT)(nTopRow+nRelRow) >= nRowCount )
973 continue;
975 // prepare row
976 ULONG nRow = nTopRow+nRelRow;
977 if ( !SeekRow( nRow) ) {
978 DBG_ERROR("BrowseBox::ImplPaintData: SeekRow gescheitert");
980 _rOut.SetClipRegion();
981 aPos.X() = aOverallAreaPos.X();
984 // #73325# don't paint the row outside the painting rectangle (DG)
985 // prepare auto-highlight
986 Rectangle aRowRect( Point( _rRect.TopLeft().X(), aPos.Y() ),
987 Size( _rRect.GetSize().Width(), nDataRowHeigt ) );
988 PaintRow( _rOut, aRowRect );
990 BOOL bRowAutoHighlight = _bDrawSelections
991 && !bHideSelect
992 && ((BrowserDataWin&)GetDataWindow()).bHighlightAuto
993 && IsRowSelected( nRow );
994 if ( bRowAutoHighlight )
996 _rOut.SetTextColor( rHighlightTextColor );
997 _rOut.SetFillColor( rHighlightFillColor );
998 _rOut.SetLineColor();
999 _rOut.DrawRect( aRowRect );
1002 // iterate through columns to redraw
1003 USHORT nCol;
1004 for ( nCol = 0; nCol < pCols->Count(); ++nCol )
1006 // get column
1007 BrowserColumn *pCol = pCols->GetObject(nCol);
1009 // at end of invalid area
1010 if ( aPos.X() >= _rRect.Right() )
1011 break;
1013 // skip invisible colums between frozen and scrollable area
1014 if ( nCol < nFirstCol && !pCol->IsFrozen() )
1016 nCol = nFirstCol;
1017 pCol = pCols->GetObject(nCol);
1018 if (!pCol)
1019 { // FS - 21.05.99 - 66325
1020 // ist zwar eigentlich woanders (an der richtigen Stelle) gefixt, aber sicher ist sicher ...
1021 DBG_ERROR("BrowseBox::PaintData : nFirstCol is probably invalid !");
1022 break;
1026 // prepare Column-AutoHighlight
1027 BOOL bColAutoHighlight = _bDrawSelections
1028 && bColumnCursor
1029 && IsColumnSelected( pCol->GetId() );
1030 if ( bColAutoHighlight )
1032 _rOut.SetClipRegion();
1033 _rOut.SetTextColor( rHighlightTextColor );
1034 _rOut.SetFillColor( rHighlightFillColor );
1035 _rOut.SetLineColor();
1036 Rectangle aFieldRect( aPos,
1037 Size( pCol->Width(), nDataRowHeigt ) );
1038 _rOut.DrawRect( aFieldRect );
1041 if (!m_bFocusOnlyCursor && (pCol->GetId() == GetCurColumnId()) && (nRow == (ULONG)GetCurRow()))
1042 DrawCursor();
1044 // draw a single field
1045 // #63864#, Sonst wird auch etwas gezeichnet, bsp Handle Column
1046 if (pCol->Width())
1048 // clip the column's output to the field area
1049 if (_bForeignDevice)
1050 { // (not neccessary if painting onto the data window)
1051 Size aFieldSize(pCol->Width(), nDataRowHeigt);
1053 if (aPos.X() + aFieldSize.Width() > aOverallAreaBRPos.X())
1054 aFieldSize.Width() = aOverallAreaBRPos.X() - aPos.X();
1056 if (aPos.Y() + aFieldSize.Height() > aOverallAreaBRPos.Y() + 1)
1058 // for non-handle cols we don't clip vertically : we just don't draw the cell if the line isn't completely visible
1059 if (pCol->GetId() != 0)
1060 continue;
1061 aFieldSize.Height() = aOverallAreaBRPos.Y() + 1 - aPos.Y();
1064 Region aClipToField(Rectangle(aPos, aFieldSize));
1065 _rOut.SetClipRegion(aClipToField);
1067 pCol->Draw( *this, _rOut, aPos, FALSE );
1068 if (_bForeignDevice)
1069 _rOut.SetClipRegion();
1072 // reset Column-auto-highlight
1073 if ( bColAutoHighlight )
1075 _rOut.SetTextColor( aOldTextColor );
1076 _rOut.SetFillColor( aOldFillColor );
1077 _rOut.SetLineColor( aOldLineColor );
1080 // skip column
1081 aPos.X() += pCol->Width();
1084 if ( nCol == pCols->Count() )
1085 bRetouching = TRUE;
1087 // reset auto-highlight
1088 if ( bRowAutoHighlight )
1090 _rOut.SetTextColor( aOldTextColor );
1091 _rOut.SetFillColor( aOldFillColor );
1092 _rOut.SetLineColor( aOldLineColor );
1095 if ( bHLines )
1097 // draw horizontal delimitation lines
1098 _rOut.SetClipRegion();
1099 _rOut.Push( PUSH_LINECOLOR );
1100 _rOut.SetLineColor( aDelimiterLineColor );
1101 long nY = aPos.Y() + nDataRowHeigt - 1;
1102 if (nY <= aOverallAreaBRPos.Y())
1103 _rOut.DrawLine( Point( nHLineX, nY ),
1104 Point( bVLines
1105 ? std::min(long(long(aPos.X()) - 1), aOverallAreaBRPos.X())
1106 : aOverallAreaBRPos.X(),
1107 nY ) );
1108 _rOut.Pop();
1112 if (aPos.Y() > aOverallAreaBRPos.Y() + 1)
1113 aPos.Y() = aOverallAreaBRPos.Y() + 1;
1114 // needed for some of the following drawing
1116 // retouching
1117 _rOut.SetClipRegion();
1118 aOldLineColor = _rOut.GetLineColor();
1119 aOldFillColor = _rOut.GetFillColor();
1120 _rOut.SetFillColor( rSettings.GetFaceColor() );
1121 if ( pCols->Count() && ( pCols->GetObject(0)->GetId() == 0 ) && ( aPos.Y() <= _rRect.Bottom() ) )
1123 // fill rectangle gray below handle column
1124 // DG: fill it only until the end of the drawing rect and not to the end, as this may overpaint handle columns
1125 _rOut.SetLineColor( Color( COL_BLACK ) );
1126 _rOut.DrawRect( Rectangle(
1127 Point( aOverallAreaPos.X() - 1, aPos.Y() - 1 ),
1128 Point( aOverallAreaPos.X() + pCols->GetObject(0)->Width() - 1,
1129 _rRect.Bottom() + 1) ) );
1131 _rOut.SetFillColor( aOldFillColor );
1133 // draw vertical delimitational line between frozen and scrollable cols
1134 _rOut.SetLineColor( COL_BLACK );
1135 long nFrozenWidth = GetFrozenWidth()-1;
1136 _rOut.DrawLine( Point( aOverallAreaPos.X() + nFrozenWidth, aPos.Y() ),
1137 Point( aOverallAreaPos.X() + nFrozenWidth, bHLines
1138 ? aPos.Y() - 1
1139 : aOverallAreaBRPos.Y() ) );
1141 // draw vertical delimitational lines?
1142 if ( bVLines )
1144 _rOut.SetLineColor( aDelimiterLineColor );
1145 Point aVertPos( aOverallAreaPos.X() - 1, aOverallAreaPos.Y() );
1146 long nDeltaY = aOverallAreaBRPos.Y();
1147 for ( USHORT nCol = 0; nCol < pCols->Count(); ++nCol )
1149 // get column
1150 BrowserColumn *pCol = pCols->GetObject(nCol);
1152 // skip invisible colums between frozen and scrollable area
1153 if ( nCol < nFirstCol && !pCol->IsFrozen() )
1155 nCol = nFirstCol;
1156 pCol = pCols->GetObject(nCol);
1159 // skip column
1160 aVertPos.X() += pCol->Width();
1162 // at end of invalid area
1163 // invalid area is first reached when X > Right
1164 // and not >=
1165 if ( aVertPos.X() > _rRect.Right() )
1166 break;
1168 // draw a single line
1169 if ( pCol->GetId() != 0 )
1170 _rOut.DrawLine( aVertPos, Point( aVertPos.X(),
1171 bHLines
1172 ? aPos.Y() - 1
1173 : aPos.Y() + nDeltaY ) );
1177 _rOut.SetLineColor( aOldLineColor );
1180 //-------------------------------------------------------------------
1182 void BrowseBox::PaintData( Window& rWin, const Rectangle& rRect )
1184 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1185 if ( !bBootstrapped && IsReallyVisible() )
1186 BrowseBox::StateChanged( STATE_CHANGE_INITSHOW );
1188 // initializations
1189 if ( !pCols || !pCols->Count() || !rWin.IsUpdateMode() )
1190 return;
1191 if ( getDataWindow()->bResizeOnPaint )
1192 Resize();
1193 // MI: wer war das denn? Window::Update();
1195 ImplPaintData(rWin, rRect, FALSE, TRUE);
1198 //-------------------------------------------------------------------
1200 void BrowseBox::UpdateScrollbars()
1202 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1204 if ( !bBootstrapped || !IsUpdateMode() )
1205 return;
1207 // Rekursionsschutz
1208 BrowserDataWin *pBDW = (BrowserDataWin*) pDataWin;
1209 if ( pBDW->bInUpdateScrollbars )
1211 pBDW->bHadRecursion = TRUE;
1212 return;
1214 pBDW->bInUpdateScrollbars = TRUE;
1216 // the size of the corner window (and the width of the VSB/height of the HSB)
1217 ULONG nCornerSize = GetSettings().GetStyleSettings().GetScrollBarSize();
1218 if (IsZoom())
1219 nCornerSize = (ULONG)(nCornerSize * (double)GetZoom());
1221 // needs VScroll?
1222 long nMaxRows = (pDataWin->GetSizePixel().Height()) / GetDataRowHeight();
1223 BOOL bNeedsVScroll = getDataWindow()->bAutoVScroll
1224 ? nTopRow || ( nRowCount > nMaxRows )
1225 : !getDataWindow()->bNoVScroll;
1226 Size aDataWinSize = pDataWin->GetSizePixel();
1227 if ( !bNeedsVScroll )
1229 if ( pVScroll->IsVisible() )
1231 pVScroll->Hide();
1232 Size aNewSize( aDataWinSize );
1233 aNewSize.Width() = GetOutputSizePixel().Width();
1234 aDataWinSize = aNewSize;
1237 else if ( !pVScroll->IsVisible() )
1239 Size aNewSize( aDataWinSize );
1240 aNewSize.Width() = GetOutputSizePixel().Width() - nCornerSize;
1241 aDataWinSize = aNewSize;
1244 // needs HScroll?
1245 ULONG nLastCol = GetColumnAtXPosPixel( aDataWinSize.Width() - 1 );
1247 USHORT nFrozenCols = FrozenColCount();
1248 BOOL bNeedsHScroll = getDataWindow()->bAutoHScroll
1249 ? ( nFirstCol > nFrozenCols ) || ( nLastCol <= pCols->Count() )
1250 : !getDataWindow()->bNoHScroll;
1251 if ( !bNeedsHScroll )
1253 if ( aHScroll.IsVisible() )
1255 aHScroll.Hide();
1257 aDataWinSize.Height() = GetOutputSizePixel().Height() - GetTitleHeight();
1258 if ( nControlAreaWidth != USHRT_MAX )
1259 aDataWinSize.Height() -= nCornerSize;
1261 else if ( !aHScroll.IsVisible() )
1263 Size aNewSize( aDataWinSize );
1264 aNewSize.Height() = GetOutputSizePixel().Height() - GetTitleHeight() - nCornerSize;
1265 aDataWinSize = aNewSize;
1268 // adjust position and Width of horizontal scrollbar
1269 ULONG nHScrX = nControlAreaWidth == USHRT_MAX
1271 : nControlAreaWidth;
1273 aHScroll.SetPosSizePixel(
1274 Point( nHScrX, GetOutputSizePixel().Height() - nCornerSize ),
1275 Size( aDataWinSize.Width() - nHScrX, nCornerSize ) );
1277 // Scrollable Columns insgesamt
1278 short nScrollCols = short(pCols->Count()) - (short)nFrozenCols;
1279 /*short nVisibleHSize= std::max(nLastCol == BROWSER_INVALIDID
1280 ? pCols->Count() - nFirstCol -1
1281 : nLastCol - nFirstCol - 1, 0);
1283 aHScroll.SetVisibleSize( nVisibleHSize );
1284 aHScroll.SetRange( Range( 0, Max( std::min(nScrollCols, nVisibleHSize), (short)0 ) ) );
1285 if ( bNeedsHScroll && !aHScroll.IsVisible() )
1286 aHScroll.Show();*/
1288 // Sichtbare Columns
1289 short nVisibleHSize = nLastCol == BROWSER_INVALIDID
1290 ? (short)( pCols->Count() - nFirstCol )
1291 : (short)( nLastCol - nFirstCol );
1293 short nRange = Max( nScrollCols, (short)0 );
1294 aHScroll.SetVisibleSize( nVisibleHSize );
1295 aHScroll.SetRange( Range( 0, nRange ));
1296 if ( bNeedsHScroll && !aHScroll.IsVisible() )
1297 aHScroll.Show();
1299 // adjust position and height of vertical scrollbar
1300 pVScroll->SetPageSize( nMaxRows );
1302 if ( nTopRow > nRowCount )
1304 nTopRow = nRowCount - 1;
1305 DBG_ERROR("BrowseBox: nTopRow > nRowCount");
1308 if ( pVScroll->GetThumbPos() != nTopRow )
1309 pVScroll->SetThumbPos( nTopRow );
1310 long nVisibleSize = Min( Min( nRowCount, nMaxRows ), long(nRowCount-nTopRow) );
1311 pVScroll->SetVisibleSize( nVisibleSize ? nVisibleSize : 1 );
1312 pVScroll->SetRange( Range( 0, nRowCount ) );
1313 pVScroll->SetPosSizePixel(
1314 Point( aDataWinSize.Width(), GetTitleHeight() ),
1315 Size( nCornerSize, aDataWinSize.Height()) );
1316 if ( nRowCount <
1317 long( aDataWinSize.Height() / GetDataRowHeight() ) )
1318 ScrollRows( -nTopRow );
1319 if ( bNeedsVScroll && !pVScroll->IsVisible() )
1320 pVScroll->Show();
1322 pDataWin->SetPosSizePixel(
1323 Point( 0, GetTitleHeight() ),
1324 aDataWinSize );
1326 // needs corner-window?
1327 // (do that AFTER positioning BOTH scrollbars)
1328 ULONG nActualCorderWidth = 0;
1329 if (aHScroll.IsVisible() && pVScroll && pVScroll->IsVisible() )
1331 // if we have both scrollbars, the corner window fills the point of intersection of these two
1332 nActualCorderWidth = nCornerSize;
1334 else if ( !aHScroll.IsVisible() && ( nControlAreaWidth != USHRT_MAX ) )
1336 // if we have no horizontal scrollbar, but a control area, we need the corner window to
1337 // fill the space between the control are and the right border
1338 nActualCorderWidth = GetOutputSizePixel().Width() - nControlAreaWidth;
1340 if ( nActualCorderWidth )
1342 if ( !getDataWindow()->pCornerWin )
1343 getDataWindow()->pCornerWin = new ScrollBarBox( this, 0 );
1344 getDataWindow()->pCornerWin->SetPosSizePixel(
1345 Point( GetOutputSizePixel().Width() - nActualCorderWidth, aHScroll.GetPosPixel().Y() ),
1346 Size( nActualCorderWidth, nCornerSize ) );
1347 getDataWindow()->pCornerWin->Show();
1349 else
1350 DELETEZ( getDataWindow()->pCornerWin );
1352 // ggf. Headerbar mitscrollen
1353 if ( getDataWindow()->pHeaderBar )
1355 long nWidth = 0;
1356 for ( USHORT nCol = 0;
1357 nCol < pCols->Count() && nCol < nFirstCol;
1358 ++nCol )
1360 // HandleColumn nicht
1361 if ( pCols->GetObject(nCol)->GetId() )
1362 nWidth += pCols->GetObject(nCol)->Width();
1365 getDataWindow()->pHeaderBar->SetOffset( nWidth );
1368 pBDW->bInUpdateScrollbars = FALSE;
1369 if ( pBDW->bHadRecursion )
1371 pBDW->bHadRecursion = FALSE;
1372 UpdateScrollbars();
1376 //-------------------------------------------------------------------
1378 void BrowseBox::SetUpdateMode( BOOL bUpdate )
1380 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1382 BOOL bWasUpdate = IsUpdateMode();
1383 if ( bWasUpdate == bUpdate )
1384 return;
1386 Control::SetUpdateMode( bUpdate );
1387 // OV
1388 // Wenn an der BrowseBox WB_CLIPCHILDREN gesetzt ist (wg. Flackerminimierung),
1389 // wird das Datenfenster nicht von SetUpdateMode invalidiert.
1390 if( bUpdate )
1391 getDataWindow()->Invalidate();
1392 getDataWindow()->SetUpdateMode( bUpdate );
1395 if ( bUpdate )
1397 if ( bBootstrapped )
1399 UpdateScrollbars();
1400 AutoSizeLastColumn();
1402 DoShowCursor( "SetUpdateMode" );
1404 else
1405 DoHideCursor( "SetUpdateMode" );
1408 //-------------------------------------------------------------------
1410 BOOL BrowseBox::GetUpdateMode() const
1412 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1414 return getDataWindow()->IsUpdateMode();
1417 //-------------------------------------------------------------------
1419 long BrowseBox::GetFrozenWidth() const
1421 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1423 long nWidth = 0;
1424 for ( USHORT nCol = 0;
1425 nCol < pCols->Count() && pCols->GetObject(nCol)->IsFrozen();
1426 ++nCol )
1427 nWidth += pCols->GetObject(nCol)->Width();
1428 return nWidth;
1431 //-------------------------------------------------------------------
1433 void BrowseBox::ColumnInserted( USHORT nPos )
1435 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1437 if ( pColSel )
1438 pColSel->Insert( nPos );
1439 UpdateScrollbars();
1442 //-------------------------------------------------------------------
1444 USHORT BrowseBox::FrozenColCount() const
1446 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1447 USHORT nCol;
1448 for ( nCol = 0;
1449 nCol < pCols->Count() && pCols->GetObject(nCol)->IsFrozen();
1450 ++nCol )
1451 /* empty loop */;
1452 return nCol;
1455 //-------------------------------------------------------------------
1457 IMPL_LINK(BrowseBox,ScrollHdl,ScrollBar*,pBar)
1459 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1461 if ( pBar->GetDelta() == 0 )
1462 return 0;
1464 if ( pBar->GetDelta() < 0 && getDataWindow()->bNoScrollBack )
1466 UpdateScrollbars();
1467 return 0;
1470 if ( pBar == &aHScroll )
1471 ScrollColumns( aHScroll.GetDelta() );
1472 if ( pBar == pVScroll )
1473 ScrollRows( pVScroll->GetDelta() );
1475 return 0;
1478 //-------------------------------------------------------------------
1480 IMPL_LINK( BrowseBox,EndScrollHdl,ScrollBar*, EMPTYARG )
1482 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1484 // kein Focus grabben!
1485 /// GrabFocus();
1487 if ( /*pBar->GetDelta() <= 0 &&*/ getDataWindow()->bNoScrollBack )
1489 // UpdateScrollbars();
1490 EndScroll();
1491 return 0;
1494 return 0;
1497 //-------------------------------------------------------------------
1499 IMPL_LINK( BrowseBox, StartDragHdl, HeaderBar*, pBar )
1501 pBar->SetDragSize( pDataWin->GetOutputSizePixel().Height() );
1502 return 0;
1505 //-------------------------------------------------------------------
1506 // MI: es wurde immer nur die 1. Spalte resized
1507 #ifdef _MSC_VER
1508 #pragma optimize("",off)
1509 #endif
1511 void BrowseBox::MouseButtonDown( const MouseEvent& rEvt )
1513 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1515 GrabFocus();
1517 // onl< mouse events in the title-line are supported
1518 const Point &rEvtPos = rEvt.GetPosPixel();
1519 if ( rEvtPos.Y() >= GetTitleHeight() )
1520 return;
1522 long nX = 0;
1523 long nWidth = GetOutputSizePixel().Width();
1524 for ( USHORT nCol = 0; nCol < pCols->Count() && nX < nWidth; ++nCol )
1526 // is this column visible?
1527 BrowserColumn *pCol = pCols->GetObject(nCol);
1528 if ( pCol->IsFrozen() || nCol >= nFirstCol )
1530 // compute right end of column
1531 long nR = nX + pCol->Width() - 1;
1533 // at the end of a column (and not handle column)?
1534 if ( pCol->GetId() && Abs( nR - rEvtPos.X() ) < 2 )
1536 // start resizing the column
1537 bResizing = TRUE;
1538 nResizeCol = nCol;
1539 nDragX = nResizeX = rEvtPos.X();
1540 SetPointer( Pointer( POINTER_HSPLIT ) );
1541 CaptureMouse();
1542 pDataWin->DrawLine( Point( nDragX, 0 ),
1543 Point( nDragX, pDataWin->GetSizePixel().Height() ) );
1544 nMinResizeX = nX + MIN_COLUMNWIDTH;
1545 return;
1547 else if ( nX < rEvtPos.X() && nR > rEvtPos.X() )
1549 MouseButtonDown( BrowserMouseEvent(
1550 this, rEvt, -1, nCol, pCol->GetId(), Rectangle() ) );
1551 return;
1553 nX = nR + 1;
1557 // event occured out of data area
1558 if ( rEvt.IsRight() )
1559 pDataWin->Command(
1560 CommandEvent( Point( 1, LONG_MAX ), COMMAND_CONTEXTMENU, TRUE ) );
1561 else
1562 SetNoSelection();
1565 #ifdef _MSC_VER
1566 #pragma optimize("",on)
1567 #endif
1569 //-------------------------------------------------------------------
1571 void BrowseBox::MouseMove( const MouseEvent& rEvt )
1573 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1574 DBG_TRACE( "BrowseBox::MouseMove( MouseEvent )" );
1576 Pointer aNewPointer;
1578 USHORT nX = 0;
1579 for ( USHORT nCol = 0;
1580 nCol < USHORT(pCols->Count()) &&
1581 ( nX + pCols->GetObject(nCol)->Width() ) < USHORT(GetOutputSizePixel().Width());
1582 ++nCol )
1583 // is this column visible?
1584 if ( pCols->GetObject(nCol)->IsFrozen() || nCol >= nFirstCol )
1586 // compute right end of column
1587 BrowserColumn *pCol = pCols->GetObject(nCol);
1588 USHORT nR = (USHORT)(nX + pCol->Width() - 1);
1590 // show resize-pointer?
1591 if ( bResizing || ( pCol->GetId() &&
1592 Abs( ((long) nR ) - rEvt.GetPosPixel().X() ) < MIN_COLUMNWIDTH ) )
1594 aNewPointer = Pointer( POINTER_HSPLIT );
1595 if ( bResizing )
1597 // alte Hilfslinie loeschen
1598 pDataWin->HideTracking() ;
1600 // erlaubte breite abholen und neues Delta
1601 nDragX = Max( rEvt.GetPosPixel().X(), nMinResizeX );
1602 long nDeltaX = nDragX - nResizeX;
1603 USHORT nId = GetColumnId(nResizeCol);
1604 ULONG nOldWidth = GetColumnWidth(nId);
1605 nDragX = QueryColumnResize( GetColumnId(nResizeCol),
1606 nOldWidth + nDeltaX )
1607 + nResizeX - nOldWidth;
1609 // neue Hilfslinie zeichnen
1610 pDataWin->ShowTracking( Rectangle( Point( nDragX, 0 ),
1611 Size( 1, pDataWin->GetSizePixel().Height() ) ),
1612 SHOWTRACK_SPLIT|SHOWTRACK_WINDOW );
1617 nX = nR + 1;
1620 SetPointer( aNewPointer );
1623 //-------------------------------------------------------------------
1625 void BrowseBox::MouseButtonUp( const MouseEvent & rEvt )
1627 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1629 if ( bResizing )
1631 // Hilfslinie loeschen
1632 pDataWin->HideTracking();
1634 // width changed?
1635 nDragX = Max( rEvt.GetPosPixel().X(), nMinResizeX );
1636 if ( (nDragX - nResizeX) != (long)pCols->GetObject(nResizeCol)->Width() )
1638 // resize column
1639 long nMaxX = pDataWin->GetSizePixel().Width();
1640 nDragX = Min( nDragX, nMaxX );
1641 long nDeltaX = nDragX - nResizeX;
1642 USHORT nId = GetColumnId(nResizeCol);
1643 SetColumnWidth( GetColumnId(nResizeCol), GetColumnWidth(nId) + nDeltaX );
1644 ColumnResized( nId );
1647 // end action
1648 SetPointer( Pointer() );
1649 ReleaseMouse();
1650 bResizing = FALSE;
1652 else
1653 MouseButtonUp( BrowserMouseEvent( (BrowserDataWin*)pDataWin,
1654 MouseEvent( Point( rEvt.GetPosPixel().X(),
1655 rEvt.GetPosPixel().Y() - pDataWin->GetPosPixel().Y() ),
1656 rEvt.GetClicks(), rEvt.GetMode(), rEvt.GetButtons(),
1657 rEvt.GetModifier() ) ) );
1660 //-------------------------------------------------------------------
1662 BOOL bExtendedMode = FALSE;
1663 BOOL bFieldMode = FALSE;
1665 void BrowseBox::MouseButtonDown( const BrowserMouseEvent& rEvt )
1667 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1669 GrabFocus();
1671 // adjust selection while and after double-click
1672 if ( rEvt.GetClicks() == 2 )
1674 SetNoSelection();
1675 if ( rEvt.GetRow() >= 0 )
1677 GoToRow( rEvt.GetRow() );
1678 SelectRow( rEvt.GetRow(), TRUE, FALSE );
1680 else
1682 if ( bColumnCursor && rEvt.GetColumn() != 0 )
1684 if ( rEvt.GetColumn() < pCols->Count() )
1685 SelectColumnPos( rEvt.GetColumn(), TRUE, FALSE);
1688 DoubleClick( rEvt );
1690 // selections
1691 else if ( ( rEvt.GetMode() & ( MOUSE_SELECT | MOUSE_SIMPLECLICK ) ) &&
1692 ( bColumnCursor || rEvt.GetRow() >= 0 ) )
1694 if ( rEvt.GetClicks() == 1 )
1696 // initialise flags
1697 bHit = FALSE;
1698 a1stPoint =
1699 a2ndPoint = PixelToLogic( rEvt.GetPosPixel() );
1701 // selection out of range?
1702 if ( rEvt.GetRow() >= nRowCount ||
1703 rEvt.GetColumnId() == BROWSER_INVALIDID )
1705 SetNoSelection();
1706 return;
1709 // while selecting, no cursor
1710 bSelecting = TRUE;
1711 DoHideCursor( "MouseButtonDown" );
1713 // DataRow?
1714 if ( rEvt.GetRow() >= 0 )
1716 // Zeilenselektion?
1717 if ( rEvt.GetColumnId() == 0 || !bColumnCursor )
1719 if ( bMultiSelection )
1721 // remove column-selection, if exists
1722 if ( pColSel && pColSel->GetSelectCount() )
1724 ToggleSelection();
1725 if ( bMultiSelection )
1726 uRow.pSel->SelectAll(FALSE);
1727 else
1728 uRow.nSel = BROWSER_ENDOFSELECTION;
1729 if ( pColSel )
1730 pColSel->SelectAll(FALSE);
1731 bSelect = TRUE;
1734 // expanding mode?
1735 if ( rEvt.GetMode() & MOUSE_RANGESELECT )
1737 // select the further touched rows too
1738 bSelect = TRUE;
1739 ExpandRowSelection( rEvt );
1740 return;
1743 // click in the selected area?
1744 else if ( IsRowSelected( rEvt.GetRow() ) )
1746 // auf Drag&Drop warten
1747 bHit = TRUE;
1748 bExtendedMode = MOUSE_MULTISELECT ==
1749 ( rEvt.GetMode() & MOUSE_MULTISELECT );
1750 return;
1753 // extension mode?
1754 else if ( rEvt.GetMode() & MOUSE_MULTISELECT )
1756 // determine the new selection range
1757 // and selection/deselection
1758 aSelRange = Range( rEvt.GetRow(), rEvt.GetRow() );
1759 SelectRow( rEvt.GetRow(),
1760 !uRow.pSel->IsSelected( rEvt.GetRow() ) );
1761 bSelect = TRUE;
1762 return;
1766 // select directly
1767 SetNoSelection();
1768 GoToRow( rEvt.GetRow() );
1769 SelectRow( rEvt.GetRow(), TRUE );
1770 aSelRange = Range( rEvt.GetRow(), rEvt.GetRow() );
1771 bSelect = TRUE;
1773 else // Column/Field-Selection
1775 // click in selected column
1776 if ( IsColumnSelected( rEvt.GetColumn() ) ||
1777 IsRowSelected( rEvt.GetRow() ) )
1779 bHit = TRUE;
1780 bFieldMode = TRUE;
1781 return;
1784 SetNoSelection();
1785 GoToRowColumnId( rEvt.GetRow(), rEvt.GetColumnId() );
1786 bSelect = TRUE;
1789 else
1791 if ( bMultiSelection && rEvt.GetColumnId() == 0 )
1793 // toggle all-selection
1794 if ( uRow.pSel->GetSelectCount() > ( GetRowCount() / 2 ) )
1795 SetNoSelection();
1796 else
1797 SelectAll();
1799 else
1800 SelectColumnId( rEvt.GetColumnId(), TRUE, FALSE );
1803 // ggf. Cursor wieder an
1804 bSelecting = FALSE;
1805 DoShowCursor( "MouseButtonDown" );
1806 if ( bSelect )
1807 Select();
1812 //-------------------------------------------------------------------
1814 void BrowseBox::MouseMove( const BrowserMouseEvent& )
1816 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1819 //-------------------------------------------------------------------
1821 void BrowseBox::MouseButtonUp( const BrowserMouseEvent &rEvt )
1823 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1825 // D&D was possible, but did not occur
1826 if ( bHit )
1828 aSelRange = Range( rEvt.GetRow(), rEvt.GetRow() );
1829 if ( bExtendedMode )
1830 SelectRow( rEvt.GetRow(), FALSE );
1831 else
1833 SetNoSelection();
1834 if ( bFieldMode )
1835 GoToRowColumnId( rEvt.GetRow(), rEvt.GetColumnId() );
1836 else
1838 GoToRow( rEvt.GetRow() );
1839 SelectRow( rEvt.GetRow(), TRUE );
1842 bSelect = TRUE;
1843 bExtendedMode = FALSE;
1844 bFieldMode = FALSE;
1845 bHit = FALSE;
1848 // activate cursor
1849 if ( bSelecting )
1851 bSelecting = FALSE;
1852 DoShowCursor( "MouseButtonUp" );
1853 if ( bSelect )
1854 Select();
1858 //-------------------------------------------------------------------
1860 void BrowseBox::KeyInput( const KeyEvent& rEvt )
1862 if ( !ProcessKey( rEvt ) )
1863 Control::KeyInput( rEvt );
1866 //-------------------------------------------------------------------
1868 BOOL BrowseBox::ProcessKey( const KeyEvent& rEvt )
1870 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1872 USHORT nCode = rEvt.GetKeyCode().GetCode();
1873 BOOL bShift = rEvt.GetKeyCode().IsShift();
1874 BOOL bCtrl = rEvt.GetKeyCode().IsMod1();
1875 BOOL bAlt = rEvt.GetKeyCode().IsMod2();
1877 USHORT nId = BROWSER_NONE;
1879 if ( !bAlt && !bCtrl && !bShift )
1881 switch ( nCode )
1883 case KEY_DOWN: nId = BROWSER_CURSORDOWN; break;
1884 case KEY_UP: nId = BROWSER_CURSORUP; break;
1885 case KEY_HOME: nId = BROWSER_CURSORHOME; break;
1886 case KEY_END: nId = BROWSER_CURSOREND; break;
1887 case KEY_TAB:
1888 if ( !bColumnCursor )
1889 break;
1890 case KEY_RIGHT: nId = BROWSER_CURSORRIGHT; break;
1891 case KEY_LEFT: nId = BROWSER_CURSORLEFT; break;
1892 case KEY_SPACE: nId = BROWSER_SELECT; break;
1894 if ( BROWSER_NONE != nId )
1895 SetNoSelection();
1897 switch ( nCode )
1899 case KEY_PAGEDOWN: nId = BROWSER_CURSORPAGEDOWN; break;
1900 case KEY_PAGEUP: nId = BROWSER_CURSORPAGEUP; break;
1904 if ( !bAlt && !bCtrl && bShift )
1905 switch ( nCode )
1907 case KEY_DOWN: nId = BROWSER_SELECTDOWN; break;
1908 case KEY_UP: nId = BROWSER_SELECTUP; break;
1909 case KEY_TAB:
1910 if ( !bColumnCursor )
1911 break;
1912 nId = BROWSER_CURSORLEFT; break;
1913 case KEY_HOME: nId = BROWSER_SELECTHOME; break;
1914 case KEY_END: nId = BROWSER_SELECTEND; break;
1918 if ( !bAlt && bCtrl && !bShift )
1919 switch ( nCode )
1921 case KEY_DOWN: nId = BROWSER_CURSORDOWN; break;
1922 case KEY_UP: nId = BROWSER_CURSORUP; break;
1923 case KEY_PAGEDOWN: nId = BROWSER_CURSORENDOFFILE; break;
1924 case KEY_PAGEUP: nId = BROWSER_CURSORTOPOFFILE; break;
1925 case KEY_HOME: nId = BROWSER_CURSORTOPOFSCREEN; break;
1926 case KEY_END: nId = BROWSER_CURSORENDOFSCREEN; break;
1927 case KEY_SPACE: nId = BROWSER_ENHANCESELECTION; break;
1928 case KEY_LEFT: nId = BROWSER_MOVECOLUMNLEFT; break;
1929 case KEY_RIGHT: nId = BROWSER_MOVECOLUMNRIGHT; break;
1932 if ( nId != BROWSER_NONE )
1933 Dispatch( nId );
1934 return nId != BROWSER_NONE;
1937 //-------------------------------------------------------------------
1939 void BrowseBox::Dispatch( USHORT nId )
1941 DBG_CHKTHIS(BrowseBox,BrowseBoxCheckInvariants);
1943 long nRowsOnPage = pDataWin->GetSizePixel().Height() / GetDataRowHeight();
1944 BOOL bDone = FALSE;
1946 switch ( nId )
1948 case BROWSER_SELECTCOLUMN:
1949 if ( ColCount() )
1950 SelectColumnId( GetCurColumnId() );
1951 break;
1953 case BROWSER_CURSORDOWN:
1954 if ( ( GetCurRow() + 1 ) < nRowCount )
1955 bDone = GoToRow( GetCurRow() + 1, FALSE );
1956 break;
1957 case BROWSER_CURSORUP:
1958 if ( GetCurRow() > 0 )
1959 bDone = GoToRow( GetCurRow() - 1, FALSE );
1960 break;
1961 case BROWSER_SELECTHOME:
1962 if ( GetRowCount() )
1964 DoHideCursor( "BROWSER_SELECTHOME" );
1965 for ( long nRow = GetCurRow(); nRow >= 0; --nRow )
1966 SelectRow( nRow );
1967 GoToRow( 0, TRUE );
1968 DoShowCursor( "BROWSER_SELECTHOME" );
1970 break;
1971 case BROWSER_SELECTEND:
1972 if ( GetRowCount() )
1974 DoHideCursor( "BROWSER_SELECTEND" );
1975 long nRows = GetRowCount();
1976 for ( long nRow = GetCurRow(); nRow < nRows; ++nRow )
1977 SelectRow( nRow );
1978 GoToRow( GetRowCount() - 1, TRUE );
1979 DoShowCursor( "BROWSER_SELECTEND" );
1981 break;
1982 case BROWSER_SELECTDOWN:
1984 if ( GetRowCount() && ( GetCurRow() + 1 ) < nRowCount )
1986 // deselect the current row, if it isn't the first
1987 // and there is no other selected row above
1988 long nRow = GetCurRow();
1989 BOOL bLocalSelect = ( !IsRowSelected( nRow ) ||
1990 GetSelectRowCount() == 1 || IsRowSelected( nRow - 1 ) );
1991 SelectRow( nRow, bLocalSelect, TRUE );
1992 bDone = GoToRow( GetCurRow() + 1 , FALSE );
1993 if ( bDone )
1994 SelectRow( GetCurRow(), TRUE, TRUE );
1996 else
1997 bDone = ScrollRows( 1 ) != 0;
1998 break;
2000 case BROWSER_SELECTUP:
2001 if ( GetRowCount() )
2003 // deselect the current row, if it isn't the first
2004 // and there is no other selected row under
2005 long nRow = GetCurRow();
2006 BOOL bLocalSelect = ( !IsRowSelected( nRow ) ||
2007 GetSelectRowCount() == 1 || IsRowSelected( nRow + 1 ) );
2008 SelectRow( nCurRow, bLocalSelect, TRUE );
2009 bDone = GoToRow( nRow - 1 , FALSE );
2010 if ( bDone )
2011 SelectRow( GetCurRow(), TRUE, TRUE );
2013 break;
2014 case BROWSER_CURSORPAGEDOWN:
2015 bDone = (BOOL)ScrollRows( nRowsOnPage );
2016 break;
2017 case BROWSER_CURSORPAGEUP:
2018 bDone = (BOOL)ScrollRows( -nRowsOnPage );
2019 break;
2020 case BROWSER_CURSOREND:
2021 if ( bColumnCursor )
2023 USHORT nNewId = GetColumnId(ColCount() -1);
2024 bDone = (nNewId != 0) && GoToColumnId( nNewId );
2025 break;
2027 case BROWSER_CURSORENDOFFILE:
2028 bDone = GoToRow( nRowCount - 1, FALSE );
2029 break;
2030 case BROWSER_CURSORRIGHT:
2031 if ( bColumnCursor )
2033 USHORT nNewPos = GetColumnPos( GetCurColumnId() ) + 1;
2034 USHORT nNewId = GetColumnId( nNewPos );
2035 if (nNewId != 0) // Am Zeilenende ?
2036 bDone = GoToColumnId( nNewId );
2037 else
2039 USHORT nColId = ( GetColumnId(0) == 0 ) ? GetColumnId(1) : GetColumnId(0);
2040 if ( GetRowCount() )
2041 bDone = ( nCurRow < GetRowCount() - 1 ) && GoToRowColumnId( nCurRow + 1, nColId );
2042 else if ( ColCount() )
2043 GoToColumnId( nColId );
2046 else
2047 bDone = ScrollColumns( 1 ) != 0;
2048 break;
2049 case BROWSER_CURSORHOME:
2050 if ( bColumnCursor )
2052 USHORT nNewId = GetColumnId(1);
2053 bDone = (nNewId != 0) && GoToColumnId( nNewId );
2054 break;
2056 case BROWSER_CURSORTOPOFFILE:
2057 bDone = GoToRow( 0, FALSE );
2058 break;
2059 case BROWSER_CURSORLEFT:
2060 if ( bColumnCursor )
2062 USHORT nNewPos = GetColumnPos( GetCurColumnId() ) - 1;
2063 USHORT nNewId = GetColumnId( nNewPos );
2064 if (nNewId != 0)
2065 bDone = GoToColumnId( nNewId );
2066 else
2068 if ( GetRowCount() )
2069 bDone = (nCurRow > 0) && GoToRowColumnId(nCurRow - 1, GetColumnId(ColCount() -1));
2070 else if ( ColCount() )
2071 GoToColumnId( GetColumnId(ColCount() -1) );
2074 else
2075 bDone = ScrollColumns( -1 ) != 0;
2076 break;
2077 case BROWSER_ENHANCESELECTION:
2078 if ( GetRowCount() )
2079 SelectRow( GetCurRow(), !IsRowSelected( GetCurRow() ), TRUE );
2080 bDone = TRUE;
2081 break;
2082 case BROWSER_SELECT:
2083 if ( GetRowCount() )
2084 SelectRow( GetCurRow(), !IsRowSelected( GetCurRow() ), FALSE );
2085 bDone = TRUE;
2086 break;
2087 case BROWSER_MOVECOLUMNLEFT:
2088 case BROWSER_MOVECOLUMNRIGHT:
2089 { // check if column moving is allowed
2090 BrowserHeader* pHeaderBar = getDataWindow()->pHeaderBar;
2091 if ( pHeaderBar && pHeaderBar->IsDragable() )
2093 USHORT nColId = GetCurColumnId();
2094 BOOL bColumnSelected = IsColumnSelected(nColId);
2095 USHORT nNewPos = GetColumnPos(nColId);
2096 BOOL bMoveAllowed = FALSE;
2097 if ( BROWSER_MOVECOLUMNLEFT == nId && nNewPos > 1 )
2098 --nNewPos,bMoveAllowed = TRUE;
2099 else if ( BROWSER_MOVECOLUMNRIGHT == nId && nNewPos < (ColCount()-1) )
2100 ++nNewPos,bMoveAllowed = TRUE;
2102 if ( bMoveAllowed )
2104 SetColumnPos( nColId, nNewPos );
2105 ColumnMoved( nColId );
2106 MakeFieldVisible(GetCurRow(),nColId,TRUE);
2107 if ( bColumnSelected )
2108 SelectColumnId(nColId);
2112 break;
2115 //! return bDone;
2118 //-------------------------------------------------------------------
2120 void BrowseBox::SetCursorColor(const Color& _rCol)
2122 if (_rCol == m_aCursorColor)
2123 return;
2125 // ensure the cursor is hidden
2126 DoHideCursor("SetCursorColor");
2127 if (!m_bFocusOnlyCursor)
2128 DoHideCursor("SetCursorColor - force");
2130 m_aCursorColor = _rCol;
2132 if (!m_bFocusOnlyCursor)
2133 DoShowCursor("SetCursorColor - force");
2134 DoShowCursor("SetCursorColor");
2136 // -----------------------------------------------------------------------------
2137 Rectangle BrowseBox::calcHeaderRect(sal_Bool _bIsColumnBar,BOOL _bOnScreen)
2139 Window* pParent = NULL;
2140 if ( !_bOnScreen )
2141 pParent = GetAccessibleParentWindow();
2143 Point aTopLeft;
2144 long nWidth;
2145 long nHeight;
2146 if ( _bIsColumnBar )
2148 nWidth = GetDataWindow().GetOutputSizePixel().Width();
2149 nHeight = GetDataRowHeight();
2151 else
2153 aTopLeft.Y() = GetDataRowHeight();
2154 nWidth = GetColumnWidth(0);
2155 nHeight = GetWindowExtentsRelative( pParent ).GetHeight() - aTopLeft.Y() - GetControlArea().GetSize().B();
2157 aTopLeft += GetWindowExtentsRelative( pParent ).TopLeft();
2158 return Rectangle(aTopLeft,Size(nWidth,nHeight));
2160 // -----------------------------------------------------------------------------
2161 Rectangle BrowseBox::calcTableRect(BOOL _bOnScreen)
2163 Window* pParent = NULL;
2164 if ( !_bOnScreen )
2165 pParent = GetAccessibleParentWindow();
2167 Rectangle aRect( GetWindowExtentsRelative( pParent ) );
2168 Rectangle aRowBar = calcHeaderRect(FALSE,pParent == NULL);
2170 long nX = aRowBar.Right() - aRect.Left();
2171 long nY = aRowBar.Top() - aRect.Top();
2172 Size aSize(aRect.GetSize());
2174 return Rectangle(aRowBar.TopRight(), Size(aSize.A() - nX, aSize.B() - nY - aHScroll.GetSizePixel().Height()) );
2176 // -----------------------------------------------------------------------------
2177 Rectangle BrowseBox::GetFieldRectPixelAbs( sal_Int32 _nRowId,sal_uInt16 _nColId, BOOL /*_bIsHeader*/, BOOL _bOnScreen )
2179 Window* pParent = NULL;
2180 if ( !_bOnScreen )
2181 pParent = GetAccessibleParentWindow();
2183 Rectangle aRect = GetFieldRectPixel(_nRowId,_nColId,_bOnScreen);
2185 Point aTopLeft = aRect.TopLeft();
2186 aTopLeft += GetWindowExtentsRelative( pParent ).TopLeft();
2188 return Rectangle(aTopLeft,aRect.GetSize());
2191 // ------------------------------------------------------------------------- EOF