[Libreoffice-commits] .: Branch 'feature/template-dialog' - 4 commits - svtools/inc svtools/Library_svt.mk svtools/source
Rafael Dominguez
rdominguez at kemper.freedesktop.org
Sun Jun 3 09:56:44 PDT 2012
svtools/Library_svt.mk | 2
svtools/inc/svtools/thumbnailview.hxx | 395 +++++
svtools/source/control/thumbnailview.cxx | 2080 ++++++++++++++++++++++++++++++-
svtools/source/control/thumbv_acc.cxx | 1045 +++++++++++++++
svtools/source/control/thumbv_acc.hxx | 253 +++
svtools/source/control/thumbv_itm.cxx | 65
svtools/source/control/thumbv_itm.hxx | 71 +
7 files changed, 3906 insertions(+), 5 deletions(-)
New commits:
commit 8bab2866a15ed5c8d8aa7d2dc8ee41c0ba0c9271
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jun 3 12:22:29 2012 -0430
Draw all thumbnail items in the same way.
- Remove drawing items differently depending on their type.
Change-Id: I426f63ed280d120d148f91c0d50891e67b0611e8
diff --git a/svtools/source/control/thumbnailview.cxx b/svtools/source/control/thumbnailview.cxx
index 4501118..a19da66 100644
--- a/svtools/source/control/thumbnailview.cxx
+++ b/svtools/source/control/thumbnailview.cxx
@@ -215,15 +215,13 @@ void ThumbnailView::DrawItem (ThumbnailViewItem *pItem, const Rectangle &aRect)
else
maVirDev.DrawText( aTxtPos, pItem->maText );
}
- else if ( pItem->meType == THUMBNAILITEM_COLOR )
- {
- maVirDev.SetFillColor( pItem->maColor );
- maVirDev.DrawRect( aRect );
- }
else
{
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
- if ( IsColor() )
+
+ if ( pItem->maColor.GetTransparency() == 0 )
+ maVirDev.SetFillColor( pItem->maColor );
+ else if ( IsColor() )
maVirDev.SetFillColor( maColor );
else if ( nStyle & WB_MENUSTYLEVALUESET )
maVirDev.SetFillColor( rStyleSettings.GetMenuColor() );
@@ -231,35 +229,29 @@ void ThumbnailView::DrawItem (ThumbnailViewItem *pItem, const Rectangle &aRect)
maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
else
maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
+
maVirDev.DrawRect( aRect );
- if ( pItem->meType == THUMBNAILITEM_USERDRAW )
+ // Draw thumbnail
+ Size aImageSize = pItem->maImage.GetSizePixel();
+ Size aRectSize = aRect.GetSize();
+ Point aPos( aRect.Left(), aRect.Top() );
+ aPos.X() += (aRectSize.Width()-aImageSize.Width())/2;
+ aPos.Y() += (aRectSize.Height()-aImageSize.Height())/2;
+
+ sal_uInt16 nImageStyle = 0;
+ if( !IsEnabled() )
+ nImageStyle |= IMAGE_DRAW_DISABLE;
+
+ if ( (aImageSize.Width() > aRectSize.Width()) ||
+ (aImageSize.Height() > aRectSize.Height()) )
{
- UserDrawEvent aUDEvt( &maVirDev, aRect, pItem->mnId );
- UserDraw( aUDEvt );
+ maVirDev.SetClipRegion( Region( aRect ) );
+ maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle);
+ maVirDev.SetClipRegion();
}
else
- {
- Size aImageSize = pItem->maImage.GetSizePixel();
- Size aRectSize = aRect.GetSize();
- Point aPos( aRect.Left(), aRect.Top() );
- aPos.X() += (aRectSize.Width()-aImageSize.Width())/2;
- aPos.Y() += (aRectSize.Height()-aImageSize.Height())/2;
-
- sal_uInt16 nImageStyle = 0;
- if( !IsEnabled() )
- nImageStyle |= IMAGE_DRAW_DISABLE;
-
- if ( (aImageSize.Width() > aRectSize.Width()) ||
- (aImageSize.Height() > aRectSize.Height()) )
- {
- maVirDev.SetClipRegion( Region( aRect ) );
- maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle);
- maVirDev.SetClipRegion();
- }
- else
- maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle );
- }
+ maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle );
}
}
}
commit a3fc3e665c82f7646f4a4a1237f4009ae9180b83
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jun 3 11:29:32 2012 -0430
Rename draw item related functions and allow them to be overrided.
Change-Id: I6be84d04fd09ea1dee3f5022a37a5c13f98dcefb
diff --git a/svtools/inc/svtools/thumbnailview.hxx b/svtools/inc/svtools/thumbnailview.hxx
index f1c9964..1f63ccf 100644
--- a/svtools/inc/svtools/thumbnailview.hxx
+++ b/svtools/inc/svtools/thumbnailview.hxx
@@ -335,6 +335,16 @@ protected:
virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
+protected:
+
+ // Drawing item related functions, override them to make your own custom ones.
+
+ virtual void DrawItem (ThumbnailViewItem *pItem, const Rectangle &aRect);
+
+ virtual void DrawItemText (const rtl::OUString &rStr );
+
+ virtual void DrawSelectedItem (const sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel);
+
private:
friend class ThumbnailViewAcc;
@@ -346,9 +356,6 @@ private:
SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
SVT_DLLPRIVATE void ImplInitScrollBar();
SVT_DLLPRIVATE void ImplDeleteItems();
- SVT_DLLPRIVATE void ImplFormatItem( ThumbnailViewItem* pItem, Rectangle aRect );
- SVT_DLLPRIVATE void ImplDrawItemText( const rtl::OUString &rStr );
- SVT_DLLPRIVATE void ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel );
SVT_DLLPRIVATE void ImplDrawSelect();
SVT_DLLPRIVATE void ImplHideSelect( sal_uInt16 nItemId );
SVT_DLLPRIVATE void ImplHighlightItem( sal_uInt16 nItemId, bool bIsSelection = true );
diff --git a/svtools/source/control/thumbnailview.cxx b/svtools/source/control/thumbnailview.cxx
index 38cf1ed..4501118 100644
--- a/svtools/source/control/thumbnailview.cxx
+++ b/svtools/source/control/thumbnailview.cxx
@@ -182,7 +182,7 @@ void ThumbnailView::ImplInitScrollBar()
}
}
-void ThumbnailView::ImplFormatItem( ThumbnailViewItem *pItem, Rectangle aRect )
+void ThumbnailView::DrawItem (ThumbnailViewItem *pItem, const Rectangle &aRect)
{
WinBits nStyle = GetStyle();
@@ -486,7 +486,7 @@ void ThumbnailView::Format()
maNoneItemRect.Right() = maNoneItemRect.Left()+aWinSize.Width()-x-1;
maNoneItemRect.Bottom() = y+nNoneHeight-1;
- ImplFormatItem( mpNoneItem, maNoneItemRect );
+ DrawItem( mpNoneItem, maNoneItemRect );
y += nNoneHeight+nNoneSpace;
}
@@ -524,7 +524,7 @@ void ThumbnailView::Format()
}
pItem->mbVisible = true;
- ImplFormatItem( pItem, Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ) );
+ DrawItem( pItem, Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ) );
if ( !((i+1) % mnCols) )
{
@@ -578,7 +578,7 @@ void ThumbnailView::Format()
delete pDelScrBar;
}
-void ThumbnailView::ImplDrawItemText( const rtl::OUString& rText )
+void ThumbnailView::DrawItemText( const rtl::OUString& rText )
{
if ( !(GetStyle() & WB_NAMEFIELD) )
return;
@@ -615,18 +615,18 @@ void ThumbnailView::ImplDrawSelect()
if ( !bFocus && !bDrawSel )
{
rtl::OUString aEmptyStr;
- ImplDrawItemText( aEmptyStr );
+ DrawItemText( aEmptyStr );
return;
}
- ImplDrawSelect( mnSelItemId, bFocus, bDrawSel );
+ DrawSelectedItem( mnSelItemId, bFocus, bDrawSel );
if (mbHighlight)
{
- ImplDrawSelect( mnHighItemId, bFocus, bDrawSel );
+ DrawSelectedItem( mnHighItemId, bFocus, bDrawSel );
}
}
-void ThumbnailView::ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel )
+void ThumbnailView::DrawSelectedItem( const sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel )
{
ThumbnailViewItem* pItem;
Rectangle aRect;
@@ -774,7 +774,7 @@ void ThumbnailView::ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const
ShowFocus( aRect2 );
}
- ImplDrawItemText( pItem->maText );
+ DrawItemText( pItem->maText );
}
}
@@ -1411,7 +1411,7 @@ void ThumbnailView::StateChanged( StateChangedType nType )
{
if ( mpNoneItem && !mbFormat && IsReallyVisible() && IsUpdateMode() )
{
- ImplFormatItem( mpNoneItem, maNoneItemRect );
+ DrawItem( mpNoneItem, maNoneItemRect );
Invalidate( maNoneItemRect );
}
}
@@ -1830,7 +1830,7 @@ void ThumbnailView::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
{
const Rectangle aRect = ImplGetItemRect(nPos);
- ImplFormatItem( pItem, aRect );
+ DrawItem( pItem, aRect );
Invalidate( aRect );
}
else
@@ -1861,7 +1861,7 @@ void ThumbnailView::SetItemColor( sal_uInt16 nItemId, const Color& rColor )
if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
{
const Rectangle aRect = ImplGetItemRect(nPos);
- ImplFormatItem( pItem, aRect );
+ DrawItem( pItem, aRect );
Invalidate( aRect );
}
else
@@ -1893,7 +1893,7 @@ void ThumbnailView::SetItemData( sal_uInt16 nItemId, void* pData )
if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
{
const Rectangle aRect = ImplGetItemRect(nPos);
- ImplFormatItem( pItem, aRect );
+ DrawItem( pItem, aRect );
Invalidate( aRect );
}
else
@@ -1938,7 +1938,7 @@ void ThumbnailView::SetItemText( sal_uInt16 nItemId, const rtl::OUString& rText
nTempId = mnHighItemId;
if ( nTempId == nItemId )
- ImplDrawItemText( pItem->maText );
+ DrawItemText( pItem->maText );
}
if (ImplHasAccessibleListeners())
commit 5349fcb28c40674abe7e232b10c63736c6c491b5
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sat Jun 2 23:21:43 2012 -0430
Remove support for item borders in thumbnailview.
Change-Id: I031ba912124310e5adb96a2e6f48b9cf6aaa6d54
diff --git a/svtools/inc/svtools/thumbnailview.hxx b/svtools/inc/svtools/thumbnailview.hxx
index 9c63449..f1c9964 100644
--- a/svtools/inc/svtools/thumbnailview.hxx
+++ b/svtools/inc/svtools/thumbnailview.hxx
@@ -63,15 +63,7 @@ class ThumbnailViewItemAcc;
is at least 8 pixel smaller on each side than the item
and also WB_DOUBLEBORDER is set and as color
COL_WINDOWWORKSPACE is specified.
- WB_FLATVALUESET Flat Look (if you set WB_ITEMBORDER or WB_DOUBLEBORDER,
- then you get extra border space, but the Borders
- aren't painted),
- WB_ITEMBORDER Items will be bordered
- WB_DOUBLEBORDER Items will be bordered twice. Additionally WB_ITEMBORDER
- has to be set, as otherwise this WinBit wouldn't have any
- effect. It is needed if there are items with a white
- background, since otherwise the 3D effect wouldn't be
- recognizable.
+ WB_FLATVALUESET Flat Look.
WB_NAMEFIELD There is a namefield, where the name of an item will be
shown.
WB_NONEFIELD There is a NoSelection field which can be selected if
@@ -171,8 +163,6 @@ class ThumbnailViewItemAcc;
/* ThumbnailView types */
#define WB_RADIOSEL ((WinBits)0x00008000)
-#define WB_ITEMBORDER ((WinBits)0x00010000)
-#define WB_DOUBLEBORDER ((WinBits)0x00020000)
#define WB_NAMEFIELD ((WinBits)0x00040000)
#define WB_NONEFIELD ((WinBits)0x00080000)
#define WB_FLATVALUESET ((WinBits)0x02000000)
@@ -192,7 +182,7 @@ class SVT_DLLPUBLIC ThumbnailView : public Control
{
public:
- ThumbnailView ( Window* pParent, WinBits nWinStyle = WB_ITEMBORDER, bool bDisableTransientChildren = false );
+ ThumbnailView ( Window* pParent, WinBits nWinStyle = WB_TABSTOP, bool bDisableTransientChildren = false );
ThumbnailView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false );
@@ -289,10 +279,6 @@ public:
bool IsColor() const { return maColor.GetTransparency() == 0; }
- void SetExtraSpacing( sal_uInt16 nNewSpacing );
-
- sal_uInt16 GetExtraSpacing() { return mnSpacing; }
-
void Format();
void StartSelection();
@@ -303,8 +289,6 @@ public:
sal_uInt16 nCalcCols = 0,
sal_uInt16 nCalcLines = 0 );
- Size CalcItemSizePixel( const Size& rSize, bool bOut = true ) const;
-
long GetScrollWidth() const;
void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
diff --git a/svtools/source/control/thumbnailview.cxx b/svtools/source/control/thumbnailview.cxx
index 456b3ec..38cf1ed 100644
--- a/svtools/source/control/thumbnailview.cxx
+++ b/svtools/source/control/thumbnailview.cxx
@@ -185,35 +185,6 @@ void ThumbnailView::ImplInitScrollBar()
void ThumbnailView::ImplFormatItem( ThumbnailViewItem *pItem, Rectangle aRect )
{
WinBits nStyle = GetStyle();
- if ( nStyle & WB_ITEMBORDER )
- {
- aRect.Left()++;
- aRect.Top()++;
- aRect.Right()--;
- aRect.Bottom()--;
- if ( nStyle & WB_FLATVALUESET )
- {
- if ( nStyle & WB_DOUBLEBORDER )
- {
- aRect.Left() += 2;
- aRect.Top() += 2;
- aRect.Right() -= 2;
- aRect.Bottom() -= 2;
- }
- else
- {
- aRect.Left()++;
- aRect.Top()++;
- aRect.Right()--;
- aRect.Bottom()--;
- }
- }
- else
- {
- DecorationView aView( &maVirDev );
- aRect = aView.DrawFrame( aRect, mnFrameStyle );
- }
- }
if ( pItem == mpNoneItem )
pItem->maText = GetText();
@@ -304,7 +275,7 @@ void ThumbnailView::Format()
size_t nItemCount = mItemList.size();
WinBits nStyle = GetStyle();
long nTxtHeight = GetTextHeight();
- long nOff;
+ long nOff = 0;
long nNoneHeight;
long nNoneSpace;
ScrollBar* pDelScrBar = NULL;
@@ -322,17 +293,6 @@ void ThumbnailView::Format()
}
}
- // calculate item offset
- if ( nStyle & WB_ITEMBORDER )
- {
- if ( nStyle & WB_DOUBLEBORDER )
- nOff = ITEM_OFFSET_DOUBLE;
- else
- nOff = ITEM_OFFSET;
- }
- else
- nOff = 0;
-
// consider size, if NameField does exist
if ( nStyle & WB_NAMEFIELD )
{
@@ -446,7 +406,7 @@ void ThumbnailView::Format()
// nothing is changed in case of too small items
if ( (mnItemWidth <= 0) ||
- (mnItemHeight <= (( nStyle & WB_ITEMBORDER ) ? 4 : 2)) ||
+ (mnItemHeight <= 2) ||
!nItemCount )
{
mbHasVisibleItems = false;
@@ -473,10 +433,7 @@ void ThumbnailView::Format()
mbHasVisibleItems = true;
// determine Frame-Style
- if ( nStyle & WB_DOUBLEBORDER )
- mnFrameStyle = FRAME_DRAW_DOUBLEIN;
- else
- mnFrameStyle = FRAME_DRAW_IN;
+ mnFrameStyle = FRAME_DRAW_IN;
// determine selected color and width
// if necessary change the colors, to make the selection
@@ -492,11 +449,7 @@ void ThumbnailView::Format()
mbBlackSel = false;
// draw the selection with double width if the items are bigger
- if ( (nStyle & WB_DOUBLEBORDER) &&
- ((mnItemWidth >= 25) && (mnItemHeight >= 20)) )
- mbDoubleSel = true;
- else
- mbDoubleSel = false;
+ mbDoubleSel = false;
// calculate offsets
long nStartX;
@@ -746,13 +699,6 @@ void ThumbnailView::ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const
aRect.Top() += 3;
aRect.Right() -= 3;
aRect.Bottom() -= 3;
- if ( nStyle & WB_DOUBLEBORDER )
- {
- aRect.Left()++;
- aRect.Top()++;
- aRect.Right()--;
- aRect.Bottom()--;
- }
if ( bFocus )
ShowFocus( aRect );
@@ -2024,18 +1970,6 @@ void ThumbnailView::SetColor( const Color& rColor )
ImplDraw();
}
-void ThumbnailView::SetExtraSpacing( sal_uInt16 nNewSpacing )
-{
- if ( GetStyle() & WB_ITEMBORDER )
- {
- mnSpacing = nNewSpacing;
-
- mbFormat = true;
- if ( IsReallyVisible() && IsUpdateMode() )
- Invalidate();
- }
-}
-
void ThumbnailView::StartSelection()
{
mbHighlight = true;
@@ -2129,20 +2063,7 @@ Size ThumbnailView::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesi
Size aSize( rItemSize.Width()*nCalcCols, rItemSize.Height()*nCalcLines );
WinBits nStyle = GetStyle();
long nTxtHeight = GetTextHeight();
- long n;
-
- if ( nStyle & WB_ITEMBORDER )
- {
- if ( nStyle & WB_DOUBLEBORDER )
- n = ITEM_OFFSET_DOUBLE;
- else
- n = ITEM_OFFSET;
-
- aSize.Width() += n*nCalcCols;
- aSize.Height() += n*nCalcLines;
- }
- else
- n = 0;
+ long n = 0;
if ( mnSpacing )
{
@@ -2170,35 +2091,6 @@ Size ThumbnailView::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesi
return aSize;
}
-Size ThumbnailView::CalcItemSizePixel( const Size& rItemSize, bool bOut ) const
-{
- Size aSize = rItemSize;
-
- WinBits nStyle = GetStyle();
- if ( nStyle & WB_ITEMBORDER )
- {
- long n;
-
- if ( nStyle & WB_DOUBLEBORDER )
- n = ITEM_OFFSET_DOUBLE;
- else
- n = ITEM_OFFSET;
-
- if ( bOut )
- {
- aSize.Width() += n;
- aSize.Height() += n;
- }
- else
- {
- aSize.Width() -= n;
- aSize.Height() -= n;
- }
- }
-
- return aSize;
-}
-
long ThumbnailView::GetScrollWidth() const
{
if ( GetStyle() & WB_VSCROLL )
commit f63007710a90e0a9c821b5e2f5510791987b2a44
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sat Jun 2 22:27:34 2012 -0430
Clone valueset functionality in thumbnailview.
- Make own control based on the functionality of valueset and related
classes, this is because valueset drawing functions arent very flexible
when it comes to changing the hover, selection drawing behaviour for
your custom one.
- Another reason its better to keep valueset functionality as it is
to dont break other code.
Change-Id: I322ec5a0d558d27bbc7a6c1f872befd8d6c9d81b
diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk
index dd03c38..150c5a0 100644
--- a/svtools/Library_svt.mk
+++ b/svtools/Library_svt.mk
@@ -129,6 +129,8 @@ $(eval $(call gb_Library_add_exception_objects,svt,\
svtools/source/control/stdctrl \
svtools/source/control/stdmenu \
svtools/source/control/tabbar \
+ svtools/source/control/thumbv_itm \
+ svtools/source/control/thumbv_acc \
svtools/source/control/thumbnailview \
svtools/source/control/toolbarmenu \
svtools/source/control/toolbarmenuacc \
diff --git a/svtools/inc/svtools/thumbnailview.hxx b/svtools/inc/svtools/thumbnailview.hxx
index 5e2aba7..9c63449 100644
--- a/svtools/inc/svtools/thumbnailview.hxx
+++ b/svtools/inc/svtools/thumbnailview.hxx
@@ -10,7 +10,177 @@
#ifndef THUMBNAILVIEW_HXX
#define THUMBNAILVIEW_HXX
-#include <svtools/valueset.hxx>
+#include "svtools/svtdllapi.h"
+
+#include <vector>
+
+#include <vcl/ctrl.hxx>
+#include <vcl/image.hxx>
+#include <vcl/virdev.hxx>
+#include <vcl/timer.hxx>
+
+class MouseEvent;
+class TrackingEvent;
+class HelpEvent;
+class KeyEvent;
+class DataChangedEvent;
+class ScrollBar;
+
+struct ThumbnailViewItem;
+typedef ::std::vector< ThumbnailViewItem* > ValueItemList;
+
+class ThumbnailViewAcc;
+class ThumbnailViewItemAcc;
+
+/*************************************************************************
+
+ Description
+ ============
+
+ class ThumbnailView
+
+ This class allows the selection of an item. In the process items are
+ drawn side by side. The selection of items can be more clear than in a
+ ListBox shape for example in case of colors or samples.
+ The amount of columns drawn by the control and whether the items
+ should be encircled can be specified. Optional a NoSelection or name
+ field could be shown. By default image and color items are supported.
+ Items could be drawn by oneself if InsertItem() is only called with
+ an ID. To achieve this the UserDraw handler needs to be overloaded. The
+ description text could be specified afterwards in case of UserDraw
+ and any other items.
+
+ Cross references
+
+ class ListBox
+
+ --------------------------------------------------------------------------
+
+ WinBits
+
+ WB_RADIOSEL If set the selection will be drawn like an
+ ImageRadioButton. This does only make sense if the image
+ is at least 8 pixel smaller on each side than the item
+ and also WB_DOUBLEBORDER is set and as color
+ COL_WINDOWWORKSPACE is specified.
+ WB_FLATVALUESET Flat Look (if you set WB_ITEMBORDER or WB_DOUBLEBORDER,
+ then you get extra border space, but the Borders
+ aren't painted),
+ WB_ITEMBORDER Items will be bordered
+ WB_DOUBLEBORDER Items will be bordered twice. Additionally WB_ITEMBORDER
+ has to be set, as otherwise this WinBit wouldn't have any
+ effect. It is needed if there are items with a white
+ background, since otherwise the 3D effect wouldn't be
+ recognizable.
+ WB_NAMEFIELD There is a namefield, where the name of an item will be
+ shown.
+ WB_NONEFIELD There is a NoSelection field which can be selected if
+ 0 is passed along with SelectItem. Respectively
+ GetSelectItemId() returns 0 if this field or nothing
+ is selected. This field shows the text which is specified
+ by SetText() respectively no one, if no text was set. With
+ SetNoSelection() the selection can be disabled.
+ WB_VSCROLL A scroolbar will be always shown. The visible number of
+ lines have to be specified with SetLineCount() if this
+ flag is set.
+ WB_BORDER A border will be drawn around the window.
+ WB_NOPOINTERFOCUS The focus won't be gathered, if the control was pressed by
+ the mouse.
+ WB_TABSTOP It is possible to jump into the ValueSet with the tab key.
+ WB_NOTABSTOP It is not possible to jump into the ValueSet with the
+ tab key.
+ WB_NO_DIRECTSELECT Cursor travelling doesn't call select immediately. To
+ execute the selection <RETURN> has to be pressed.
+ --------------------------------------------------------------------------
+
+ The number of columns must be either set with SetColCount() or
+ SetItemWidth(). If the number of colums is specified by SetColCount()
+ the width of the items will be calculated by the visible range.
+ If the items should have a static width, it has to be specified
+ with SetItemWidth(). In this case the number of columns will be calculated
+ by the visible range.
+
+ The number of rows is given by the number of items / number of columns. The
+ number of visible rows must either specified by SetLineCount() or
+ SetItemWidth(). If the number of visible rows is specified by SetLineCount(),
+ the height of the items will be calculated from the visible height. If the
+ items should have a fixed height it has to be specified with SetItemHeight().
+ In this case the number of visible rows is then calculated from the visible
+ height. If the number of visible rows is neither specified by SetLineCount()
+ nor by SetItemHeight() all rows will be shown. The height of the items will
+ be calculated by the visible height. If the number of visible rows is
+ specified by SetLineCount() or SetItemHeight() ValueSet does scroll
+ automatically when more lines are available, as are visible. If scrolling
+ should be also possible with a ScrollBar WB_VSCROLL needs to be set.
+
+ The distance between the items can be increased by SetExtraSpacing(). The
+ distance, which will be shown between two items (both in x and in y), is
+ measured in pixels.
+
+ The exact window size for a specific item size can be calculated by
+ CalcWindowSizePixel(). To do this all relevant data (number of columns/...)
+ have to be specified and if no number of rows was set, all items need to
+ be inserted. If the window was created with WB_BORDER/Border=sal_True the
+ size has to be specified with SetOutputSizePixel(). In other cases different
+ size-methods can be used. With CalcItemSize() the inner and outer size of
+ an item could be calculated (for this the free space defined by
+ SetExtraSpacing() will not be included).
+
+ The background color could be specified by SetColor(), with which the image
+ or UserDraw items will be underlayed. If no color is specified the the color
+ of other windows (WindowColor) will be used for the background.
+
+ --------------------------------------------------------------------------
+
+ At first all items should be inserted and only then Show() should be called
+ since the output area will be precomputed. If this is not done the first
+ Paint will appear a little bit slower. Therefore the Control, if it is loaded
+ from the resource and only supplied with items during runtime, should be
+ loaded with Hide = sal_True and then displayed with Show().
+
+ In case of a visible Control the creation of the new output area could be
+ activated before Paint by calling Format().
+
+ --------------------------------------------------------------------------
+
+ If Drag and Drop will be called from the ValueSet the Command-Handler has to
+ be overloaded. From this StartDrag needs to be called. If this method returns
+ sal_True the drag-process could be initiated by ExecuteDrag(), otherwise no
+ processing will take place. This method makes sure that ValueSet stops its
+ processing and as appropriate selects the entry. Therefore the calling of
+ Select-Handler within this function must be expected.
+
+ For dropping QueryDrop() and Drop() need to be overloaded and ShowDropPos()
+ and HideDropPos() should be called within these methods.
+ To show the insertion point ShowDropPos() has to be called within the
+ QueryDrop-Handler. ShowDropPos() also scrolls the ValueSet if the passed
+ position is located at the window border. Furthermore ShowDropPos() returns
+ the position, at which the item should be inserted respectively which
+ insertion point was shown. If no insertion point was determined
+ VALUESET_ITEM_NOTFOUND will be returned. If the window was left during dragging
+ or the drag process is terminated HideDropPos() should be called in any case.
+
+ --------------------------------------------------------------------------
+
+ This class is currently still in the SV-Tools. That's why the ValueSet needs
+ to be loaded as a Control out of the resource and the desired WinBits have
+ to be set (before Show) with SetStyle().
+
+*************************************************************************/
+
+/* ThumbnailView types */
+
+#define WB_RADIOSEL ((WinBits)0x00008000)
+#define WB_ITEMBORDER ((WinBits)0x00010000)
+#define WB_DOUBLEBORDER ((WinBits)0x00020000)
+#define WB_NAMEFIELD ((WinBits)0x00040000)
+#define WB_NONEFIELD ((WinBits)0x00080000)
+#define WB_FLATVALUESET ((WinBits)0x02000000)
+#define WB_NO_DIRECTSELECT ((WinBits)0x04000000)
+#define WB_MENUSTYLEVALUESET ((WinBits)0x08000000)
+
+#define THUMBNAILVIEW_APPEND ((sal_uInt16)-1)
+#define THUMBNAILVIEW_ITEM_NOTFOUND ((sal_uInt16)-1)
/**
*
@@ -18,7 +188,7 @@
*
**/
-class SVT_DLLPUBLIC ThumbnailView : public ValueSet
+class SVT_DLLPUBLIC ThumbnailView : public Control
{
public:
@@ -27,6 +197,234 @@ public:
ThumbnailView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false );
virtual ~ThumbnailView ();
+
+ virtual void Select();
+
+ virtual void DoubleClick();
+
+ void InsertItem( sal_uInt16 nItemId, const Image& rImage,
+ size_t nPos = THUMBNAILVIEW_APPEND );
+
+ void InsertItem( sal_uInt16 nItemId, const Color& rColor,
+ size_t nPos = THUMBNAILVIEW_APPEND );
+
+ void InsertItem( sal_uInt16 nItemId,
+ const Image& rImage, const rtl::OUString &rStr,
+ size_t nPos = THUMBNAILVIEW_APPEND );
+
+ void InsertItem( sal_uInt16 nItemId,
+ const Color& rColor, const rtl::OUString &rStr,
+ size_t nPos = THUMBNAILVIEW_APPEND );
+
+ void InsertItem( sal_uInt16 nItemId, size_t nPos = THUMBNAILVIEW_APPEND );
+
+ void RemoveItem( sal_uInt16 nItemId );
+
+ void Clear();
+
+ size_t GetItemCount() const;
+
+ size_t GetItemPos( sal_uInt16 nItemId ) const;
+
+ sal_uInt16 GetItemId( size_t nPos ) const;
+
+ sal_uInt16 GetItemId( const Point& rPos ) const;
+
+ Rectangle GetItemRect( sal_uInt16 nItemId ) const;
+
+ void EnableFullItemMode( bool bFullMode = true );
+
+ bool IsFullItemModeEnabled() const { return mbFullMode; }
+
+ void SetColCount( sal_uInt16 nNewCols = 1 );
+
+ sal_uInt16 GetColCount() const { return mnUserCols; }
+
+ void SetLineCount( sal_uInt16 nNewLines = 0 );
+
+ sal_uInt16 GetLineCount() const { return mnUserVisLines; }
+
+ void SetItemWidth( long nItemWidth = 0 );
+
+ long GetItemWidth() const { return mnUserItemWidth; }
+
+ void SetItemHeight( long nLineHeight = 0 );
+
+ long GetItemHeight() const { return mnUserItemHeight; }
+
+ sal_uInt16 GetFirstLine() const { return mnFirstLine; }
+
+ void SelectItem( sal_uInt16 nItemId );
+
+ sal_uInt16 GetSelectItemId() const { return mnSelItemId; }
+
+ bool IsItemSelected( sal_uInt16 nItemId ) const
+ { return !mbNoSelection && (nItemId == mnSelItemId); }
+
+ void SetNoSelection();
+
+ bool IsNoSelection() const { return mbNoSelection; }
+
+ void SetItemImage( sal_uInt16 nItemId, const Image& rImage );
+
+ Image GetItemImage( sal_uInt16 nItemId ) const;
+
+ void SetItemColor( sal_uInt16 nItemId, const Color& rColor );
+
+ Color GetItemColor( sal_uInt16 nItemId ) const;
+
+ void SetItemData( sal_uInt16 nItemId, void* pData );
+
+ void* GetItemData( sal_uInt16 nItemId ) const;
+
+ void SetItemText( sal_uInt16 nItemId, const rtl::OUString &rStr );
+
+ rtl::OUString GetItemText( sal_uInt16 nItemId ) const;
+
+ void SetColor( const Color& rColor );
+
+ void SetColor() { SetColor( Color( COL_TRANSPARENT ) ); }
+
+ Color GetColor() const { return maColor; }
+
+ bool IsColor() const { return maColor.GetTransparency() == 0; }
+
+ void SetExtraSpacing( sal_uInt16 nNewSpacing );
+
+ sal_uInt16 GetExtraSpacing() { return mnSpacing; }
+
+ void Format();
+
+ void StartSelection();
+
+ void EndSelection();
+
+ Size CalcWindowSizePixel( const Size& rItemSize,
+ sal_uInt16 nCalcCols = 0,
+ sal_uInt16 nCalcLines = 0 );
+
+ Size CalcItemSizePixel( const Size& rSize, bool bOut = true ) const;
+
+ long GetScrollWidth() const;
+
+ void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
+
+ const Link& GetSelectHdl() const { return maSelectHdl; }
+
+ void SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; }
+
+ const Link& GetDoubleClickHdl() const { return maDoubleClickHdl; }
+
+ void SetHighlightHdl( const Link& rLink );
+
+protected:
+
+ virtual void MouseButtonDown( const MouseEvent& rMEvt );
+
+ virtual void MouseButtonUp( const MouseEvent& rMEvt );
+
+ virtual void MouseMove( const MouseEvent& rMEvt );
+
+ virtual void Tracking( const TrackingEvent& rMEvt );
+
+ virtual void KeyInput( const KeyEvent& rKEvt );
+
+ virtual void Command( const CommandEvent& rCEvt );
+
+ virtual void Paint( const Rectangle& rRect );
+
+ virtual void GetFocus();
+
+ virtual void LoseFocus();
+
+ virtual void Resize();
+
+ virtual void RequestHelp( const HelpEvent& rHEvt );
+
+ virtual void StateChanged( StateChangedType nStateChange );
+
+ virtual void DataChanged( const DataChangedEvent& rDCEvt );
+
+ virtual void UserDraw( const UserDrawEvent& rUDEvt );
+
+ virtual bool StartDrag( const CommandEvent& rCEvt, Region& rRegion );
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
+
+private:
+
+ friend class ThumbnailViewAcc;
+ friend class ThumbnailViewItemAcc;
+ using Control::ImplInitSettings;
+ using Window::ImplInit;
+
+ SVT_DLLPRIVATE void ImplInit();
+ SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
+ SVT_DLLPRIVATE void ImplInitScrollBar();
+ SVT_DLLPRIVATE void ImplDeleteItems();
+ SVT_DLLPRIVATE void ImplFormatItem( ThumbnailViewItem* pItem, Rectangle aRect );
+ SVT_DLLPRIVATE void ImplDrawItemText( const rtl::OUString &rStr );
+ SVT_DLLPRIVATE void ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel );
+ SVT_DLLPRIVATE void ImplDrawSelect();
+ SVT_DLLPRIVATE void ImplHideSelect( sal_uInt16 nItemId );
+ SVT_DLLPRIVATE void ImplHighlightItem( sal_uInt16 nItemId, bool bIsSelection = true );
+ SVT_DLLPRIVATE void ImplDraw();
+ using Window::ImplScroll;
+ SVT_DLLPRIVATE bool ImplScroll( const Point& rPos );
+ SVT_DLLPRIVATE size_t ImplGetItem( const Point& rPoint, bool bMove = false ) const;
+ SVT_DLLPRIVATE ThumbnailViewItem* ImplGetItem( size_t nPos );
+ SVT_DLLPRIVATE ThumbnailViewItem* ImplGetFirstItem();
+ SVT_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const;
+ SVT_DLLPRIVATE ThumbnailViewItem* ImplGetVisibleItem( sal_uInt16 nVisiblePos );
+ SVT_DLLPRIVATE void ImplInsertItem( ThumbnailViewItem *const pItem, const size_t nPos );
+ SVT_DLLPRIVATE Rectangle ImplGetItemRect( size_t nPos ) const;
+ SVT_DLLPRIVATE void ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
+ SVT_DLLPRIVATE bool ImplHasAccessibleListeners();
+ SVT_DLLPRIVATE void ImplTracking( const Point& rPos, bool bRepeat );
+ SVT_DLLPRIVATE void ImplEndTracking( const Point& rPos, bool bCancel );
+ DECL_DLLPRIVATE_LINK( ImplScrollHdl, ScrollBar* );
+ DECL_DLLPRIVATE_LINK( ImplTimerHdl, void* );
+
+protected:
+
+ VirtualDevice maVirDev;
+ Timer maTimer;
+ ValueItemList mItemList;
+ ThumbnailViewItem* mpNoneItem;
+ ScrollBar* mpScrBar;
+ Rectangle maNoneItemRect;
+ Rectangle maItemListRect;
+ long mnItemWidth;
+ long mnItemHeight;
+ long mnTextOffset;
+ long mnVisLines;
+ long mnLines;
+ long mnUserItemWidth;
+ long mnUserItemHeight;
+ sal_uInt16 mnSelItemId;
+ sal_uInt16 mnHighItemId;
+ sal_uInt16 mnCols;
+ sal_uInt16 mnCurCol;
+ sal_uInt16 mnUserCols;
+ sal_uInt16 mnUserVisLines;
+ sal_uInt16 mnFirstLine;
+ sal_uInt16 mnSpacing;
+ sal_uInt16 mnFrameStyle;
+ bool mbFormat : 1;
+ bool mbHighlight : 1;
+ bool mbSelection : 1;
+ bool mbNoSelection : 1;
+ bool mbDrawSelection : 1;
+ bool mbBlackSel : 1;
+ bool mbDoubleSel : 1;
+ bool mbScroll : 1;
+ bool mbFullMode : 1;
+ bool mbIsTransientChildrenDisabled : 1;
+ bool mbHasVisibleItems : 1;
+ Color maColor;
+ Link maDoubleClickHdl;
+ Link maSelectHdl;
+ Link maHighlightHdl;
};
#endif // THUMBNAILVIEW_HXX
diff --git a/svtools/source/control/thumbnailview.cxx b/svtools/source/control/thumbnailview.cxx
index 041430d..456b3ec 100644
--- a/svtools/source/control/thumbnailview.cxx
+++ b/svtools/source/control/thumbnailview.cxx
@@ -9,18 +9,2210 @@
#include <svtools/thumbnailview.hxx>
+#include "thumbv_itm.hxx"
+#include "thumbv_acc.hxx"
+
+#include <rtl/ustring.hxx>
+#include <vcl/decoview.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/scrbar.hxx>
+#include <vcl/help.hxx>
+
+#include <com/sun/star/accessibility/AccessibleEventId.hpp>
+#include <com/sun/star/accessibility/AccessibleStateType.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+
+enum
+{
+ ITEM_OFFSET = 4,
+ ITEM_OFFSET_DOUBLE = 6,
+ NAME_LINE_OFF_X = 2,
+ NAME_LINE_OFF_Y = 2,
+ NAME_LINE_HEIGHT = 2,
+ NAME_OFFSET = 2,
+ SCRBAR_OFFSET = 1,
+ SCROLL_OFFSET = 4
+};
+
ThumbnailView::ThumbnailView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
- : ValueSet(pParent,nWinStyle,bDisableTransientChildren)
+ : Control( pParent, nWinStyle ),
+ maVirDev( *this ),
+ maColor( COL_TRANSPARENT )
{
+ ImplInit();
+ mbIsTransientChildrenDisabled = bDisableTransientChildren;
}
ThumbnailView::ThumbnailView (Window *pParent, const ResId &rResId, bool bDisableTransientChildren)
- : ValueSet(pParent,rResId,bDisableTransientChildren)
+ : Control( pParent, rResId ),
+ maVirDev( *this ),
+ maColor( COL_TRANSPARENT )
{
+ ImplInit();
+ mbIsTransientChildrenDisabled = bDisableTransientChildren;
}
ThumbnailView::~ThumbnailView()
{
+ com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>
+ xComponent(GetAccessible(sal_False),
+ com::sun::star::uno::UNO_QUERY);
+
+ if (xComponent.is())
+ xComponent->dispose ();
+
+ delete mpScrBar;
+ delete mpNoneItem;
+
+ ImplDeleteItems();
+}
+
+void ThumbnailView::ImplInit()
+{
+ mpNoneItem = NULL;
+ mpScrBar = NULL;
+ mnItemWidth = 0;
+ mnItemHeight = 0;
+ mnTextOffset = 0;
+ mnVisLines = 0;
+ mnLines = 0;
+ mnUserItemWidth = 0;
+ mnUserItemHeight = 0;
+ mnFirstLine = 0;
+ mnSelItemId = 0;
+ mnHighItemId = 0;
+ mnCols = 0;
+ mnCurCol = 0;
+ mnUserCols = 0;
+ mnUserVisLines = 0;
+ mnSpacing = 0;
+ mnFrameStyle = 0;
+ mbFormat = true;
+ mbHighlight = false;
+ mbSelection = false;
+ mbNoSelection = true;
+ mbDrawSelection = true;
+ mbBlackSel = false;
+ mbDoubleSel = false;
+ mbScroll = false;
+ mbFullMode = true;
+ mbHasVisibleItems = false;
+
+ // #106446#, #106601# force mirroring of virtual device
+ maVirDev.EnableRTL( GetParent()->IsRTLEnabled() );
+
+ ImplInitSettings( true, true, true );
+}
+
+void ThumbnailView::ImplDeleteItems()
+{
+ const size_t n = mItemList.size();
+
+ for ( size_t i = 0; i < n; ++i )
+ {
+ ThumbnailViewItem *const pItem = mItemList[i];
+ if ( pItem->mbVisible && ImplHasAccessibleListeners() )
+ {
+ ::com::sun::star::uno::Any aOldAny, aNewAny;
+
+ aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
+ ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
+ }
+
+ delete pItem;
+ }
+
+ mItemList.clear();
+}
+
+void ThumbnailView::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
+{
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+
+ if ( bFont )
+ {
+ Font aFont;
+ aFont = rStyleSettings.GetAppFont();
+ if ( IsControlFont() )
+ aFont.Merge( GetControlFont() );
+ SetZoomedPointFont( aFont );
+ }
+
+ if ( bForeground || bFont )
+ {
+ Color aColor;
+ if ( IsControlForeground() )
+ aColor = GetControlForeground();
+ else
+ aColor = rStyleSettings.GetButtonTextColor();
+ SetTextColor( aColor );
+ SetTextFillColor();
+ }
+
+ if ( bBackground )
+ {
+ Color aColor;
+ if ( IsControlBackground() )
+ aColor = GetControlBackground();
+ else if ( GetStyle() & WB_MENUSTYLEVALUESET )
+ aColor = rStyleSettings.GetMenuColor();
+ else if ( IsEnabled() && (GetStyle() & WB_FLATVALUESET) )
+ aColor = rStyleSettings.GetWindowColor();
+ else
+ aColor = rStyleSettings.GetFaceColor();
+ SetBackground( aColor );
+ }
+}
+
+void ThumbnailView::ImplInitScrollBar()
+{
+ if ( GetStyle() & WB_VSCROLL )
+ {
+ if ( !mpScrBar )
+ {
+ mpScrBar = new ScrollBar( this, WB_VSCROLL | WB_DRAG );
+ mpScrBar->SetScrollHdl( LINK( this, ThumbnailView, ImplScrollHdl ) );
+ }
+ else
+ {
+ // adapt the width because of the changed settings
+ long nScrBarWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
+ mpScrBar->SetPosSizePixel( 0, 0, nScrBarWidth, 0, WINDOW_POSSIZE_WIDTH );
+ }
+ }
+}
+
+void ThumbnailView::ImplFormatItem( ThumbnailViewItem *pItem, Rectangle aRect )
+{
+ WinBits nStyle = GetStyle();
+ if ( nStyle & WB_ITEMBORDER )
+ {
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ if ( nStyle & WB_FLATVALUESET )
+ {
+ if ( nStyle & WB_DOUBLEBORDER )
+ {
+ aRect.Left() += 2;
+ aRect.Top() += 2;
+ aRect.Right() -= 2;
+ aRect.Bottom() -= 2;
+ }
+ else
+ {
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ }
+ }
+ else
+ {
+ DecorationView aView( &maVirDev );
+ aRect = aView.DrawFrame( aRect, mnFrameStyle );
+ }
+ }
+
+ if ( pItem == mpNoneItem )
+ pItem->maText = GetText();
+
+ if ( (aRect.GetHeight() > 0) && (aRect.GetWidth() > 0) )
+ {
+ if ( pItem == mpNoneItem )
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ maVirDev.SetFont( GetFont() );
+ maVirDev.SetTextColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor() );
+ maVirDev.SetTextFillColor();
+ maVirDev.SetFillColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuColor() : rStyleSettings.GetWindowColor() );
+ maVirDev.DrawRect( aRect );
+ Point aTxtPos( aRect.Left()+2, aRect.Top() );
+ long nTxtWidth = GetTextWidth( pItem->maText );
+ if ( nStyle & WB_RADIOSEL )
+ {
+ aTxtPos.X() += 4;
+ aTxtPos.Y() += 4;
+ }
+ if ( (aTxtPos.X()+nTxtWidth) > aRect.Right() )
+ {
+ maVirDev.SetClipRegion( Region( aRect ) );
+ maVirDev.DrawText( aTxtPos, pItem->maText );
+ maVirDev.SetClipRegion();
+ }
+ else
+ maVirDev.DrawText( aTxtPos, pItem->maText );
+ }
+ else if ( pItem->meType == THUMBNAILITEM_COLOR )
+ {
+ maVirDev.SetFillColor( pItem->maColor );
+ maVirDev.DrawRect( aRect );
+ }
+ else
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ if ( IsColor() )
+ maVirDev.SetFillColor( maColor );
+ else if ( nStyle & WB_MENUSTYLEVALUESET )
+ maVirDev.SetFillColor( rStyleSettings.GetMenuColor() );
+ else if ( IsEnabled() )
+ maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
+ else
+ maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
+ maVirDev.DrawRect( aRect );
+
+ if ( pItem->meType == THUMBNAILITEM_USERDRAW )
+ {
+ UserDrawEvent aUDEvt( &maVirDev, aRect, pItem->mnId );
+ UserDraw( aUDEvt );
+ }
+ else
+ {
+ Size aImageSize = pItem->maImage.GetSizePixel();
+ Size aRectSize = aRect.GetSize();
+ Point aPos( aRect.Left(), aRect.Top() );
+ aPos.X() += (aRectSize.Width()-aImageSize.Width())/2;
+ aPos.Y() += (aRectSize.Height()-aImageSize.Height())/2;
+
+ sal_uInt16 nImageStyle = 0;
+ if( !IsEnabled() )
+ nImageStyle |= IMAGE_DRAW_DISABLE;
+
+ if ( (aImageSize.Width() > aRectSize.Width()) ||
+ (aImageSize.Height() > aRectSize.Height()) )
+ {
+ maVirDev.SetClipRegion( Region( aRect ) );
+ maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle);
+ maVirDev.SetClipRegion();
+ }
+ else
+ maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle );
+ }
+ }
+ }
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ThumbnailView::CreateAccessible()
+{
+ return new ThumbnailViewAcc( this, mbIsTransientChildrenDisabled );
+}
+
+void ThumbnailView::Format()
+{
+ Size aWinSize = GetOutputSizePixel();
+ size_t nItemCount = mItemList.size();
+ WinBits nStyle = GetStyle();
+ long nTxtHeight = GetTextHeight();
+ long nOff;
+ long nNoneHeight;
+ long nNoneSpace;
+ ScrollBar* pDelScrBar = NULL;
+
+ // consider the scrolling
+ if ( nStyle & WB_VSCROLL )
+ ImplInitScrollBar();
+ else
+ {
+ if ( mpScrBar )
+ {
+ // delete ScrollBar not until later, to prevent recursive calls
+ pDelScrBar = mpScrBar;
+ mpScrBar = NULL;
+ }
+ }
+
+ // calculate item offset
+ if ( nStyle & WB_ITEMBORDER )
+ {
+ if ( nStyle & WB_DOUBLEBORDER )
+ nOff = ITEM_OFFSET_DOUBLE;
+ else
+ nOff = ITEM_OFFSET;
+ }
+ else
+ nOff = 0;
+
+ // consider size, if NameField does exist
+ if ( nStyle & WB_NAMEFIELD )
+ {
+ mnTextOffset = aWinSize.Height()-nTxtHeight-NAME_OFFSET;
+ aWinSize.Height() -= nTxtHeight+NAME_OFFSET;
+
+ if ( !(nStyle & WB_FLATVALUESET) )
+ {
+ mnTextOffset -= NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
+ aWinSize.Height() -= NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
+ }
+ }
+ else
+ mnTextOffset = 0;
+
+ // consider offset and size, if NoneField does exist
+ if ( nStyle & WB_NONEFIELD )
+ {
+ nNoneHeight = nTxtHeight+nOff;
+ nNoneSpace = mnSpacing;
+ if ( nStyle & WB_RADIOSEL )
+ nNoneHeight += 8;
+ }
+ else
+ {
+ nNoneHeight = 0;
+ nNoneSpace = 0;
+
+ if ( mpNoneItem )
+ {
+ delete mpNoneItem;
+ mpNoneItem = NULL;
+ }
+ }
+
+ // calculate ScrollBar width
+ long nScrBarWidth = 0;
+ if ( mpScrBar )
+ nScrBarWidth = mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
+
+ // calculate number of columns
+ if ( !mnUserCols )
+ {
+ if ( mnUserItemWidth )
+ {
+ mnCols = (sal_uInt16)((aWinSize.Width()-nScrBarWidth+mnSpacing) / (mnUserItemWidth+mnSpacing));
+ if ( !mnCols )
+ mnCols = 1;
+ }
+ else
+ mnCols = 1;
+ }
+ else
+ mnCols = mnUserCols;
+
+ // calculate number of rows
+ mbScroll = false;
+ // Floor( (M+N-1)/N )==Ceiling( M/N )
+ mnLines = (static_cast<long>(nItemCount)+mnCols-1) / mnCols;
+ if ( !mnLines )
+ mnLines = 1;
+
+ long nCalcHeight = aWinSize.Height()-nNoneHeight;
+ if ( mnUserVisLines )
+ mnVisLines = mnUserVisLines;
+ else if ( mnUserItemHeight )
+ {
+ mnVisLines = (nCalcHeight-nNoneSpace+mnSpacing) / (mnUserItemHeight+mnSpacing);
+ if ( !mnVisLines )
+ mnVisLines = 1;
+ }
+ else
+ mnVisLines = mnLines;
+ if ( mnLines > mnVisLines )
+ mbScroll = true;
+ if ( mnLines <= mnVisLines )
+ mnFirstLine = 0;
+ else
+ {
+ if ( mnFirstLine > (sal_uInt16)(mnLines-mnVisLines) )
+ mnFirstLine = (sal_uInt16)(mnLines-mnVisLines);
+ }
+
+ // calculate item size
+ const long nColSpace = (mnCols-1)*mnSpacing;
+ const long nLineSpace = ((mnVisLines-1)*mnSpacing)+nNoneSpace;
+ if ( mnUserItemWidth && !mnUserCols )
+ {
+ mnItemWidth = mnUserItemWidth;
+ if ( mnItemWidth > aWinSize.Width()-nScrBarWidth-nColSpace )
+ mnItemWidth = aWinSize.Width()-nScrBarWidth-nColSpace;
+ }
+ else
+ mnItemWidth = (aWinSize.Width()-nScrBarWidth-nColSpace) / mnCols;
+ if ( mnUserItemHeight && !mnUserVisLines )
+ {
+ mnItemHeight = mnUserItemHeight;
+ if ( mnItemHeight > nCalcHeight-nNoneSpace )
+ mnItemHeight = nCalcHeight-nNoneSpace;
+ }
+ else
+ {
+ nCalcHeight -= nLineSpace;
+ mnItemHeight = nCalcHeight / mnVisLines;
+ }
+
+ // Init VirDev
+ maVirDev.SetSettings( GetSettings() );
+ maVirDev.SetBackground( GetBackground() );
+ maVirDev.SetOutputSizePixel( aWinSize, sal_True );
+
+ // nothing is changed in case of too small items
+ if ( (mnItemWidth <= 0) ||
+ (mnItemHeight <= (( nStyle & WB_ITEMBORDER ) ? 4 : 2)) ||
+ !nItemCount )
+ {
+ mbHasVisibleItems = false;
+
+ if ( nStyle & WB_NONEFIELD )
+ {
+ if ( mpNoneItem )
+ {
+ mpNoneItem->mbVisible = false;
+ mpNoneItem->maText = GetText();
+ }
+ }
+
+ for ( size_t i = 0; i < nItemCount; i++ )
+ {
+ mItemList[i]->mbVisible = false;
+ }
+
+ if ( mpScrBar )
+ mpScrBar->Hide();
+ }
+ else
+ {
+ mbHasVisibleItems = true;
+
+ // determine Frame-Style
+ if ( nStyle & WB_DOUBLEBORDER )
+ mnFrameStyle = FRAME_DRAW_DOUBLEIN;
+ else
+ mnFrameStyle = FRAME_DRAW_IN;
+
+ // determine selected color and width
+ // if necessary change the colors, to make the selection
+ // better detectable
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ Color aHighColor( rStyleSettings.GetHighlightColor() );
+ if ( ((aHighColor.GetRed() > 0x80) || (aHighColor.GetGreen() > 0x80) ||
+ (aHighColor.GetBlue() > 0x80)) ||
+ ((aHighColor.GetRed() == 0x80) && (aHighColor.GetGreen() == 0x80) &&
+ (aHighColor.GetBlue() == 0x80)) )
+ mbBlackSel = true;
+ else
+ mbBlackSel = false;
+
+ // draw the selection with double width if the items are bigger
+ if ( (nStyle & WB_DOUBLEBORDER) &&
+ ((mnItemWidth >= 25) && (mnItemHeight >= 20)) )
+ mbDoubleSel = true;
+ else
+ mbDoubleSel = false;
+
+ // calculate offsets
+ long nStartX;
+ long nStartY;
+ if ( mbFullMode )
+ {
+ long nAllItemWidth = (mnItemWidth*mnCols)+nColSpace;
+ long nAllItemHeight = (mnItemHeight*mnVisLines)+nNoneHeight+nLineSpace;
+ nStartX = (aWinSize.Width()-nScrBarWidth-nAllItemWidth)/2;
+ nStartY = (aWinSize.Height()-nAllItemHeight)/2;
+ }
+ else
+ {
+ nStartX = 0;
+ nStartY = 0;
+ }
+
+ // calculate and draw items
+ maVirDev.SetLineColor();
+ long x = nStartX;
+ long y = nStartY;
+
+ // create NoSelection field and show it
+ if ( nStyle & WB_NONEFIELD )
+ {
+ if ( !mpNoneItem )
+ mpNoneItem = new ThumbnailViewItem( *this );
+
+ mpNoneItem->mnId = 0;
+ mpNoneItem->meType = THUMBNAILITEM_NONE;
+ mpNoneItem->mbVisible = true;
+ maNoneItemRect.Left() = x;
+ maNoneItemRect.Top() = y;
+ maNoneItemRect.Right() = maNoneItemRect.Left()+aWinSize.Width()-x-1;
+ maNoneItemRect.Bottom() = y+nNoneHeight-1;
+
+ ImplFormatItem( mpNoneItem, maNoneItemRect );
+
+ y += nNoneHeight+nNoneSpace;
+ }
+
+ // draw items
+ sal_uLong nFirstItem = mnFirstLine * mnCols;
+ sal_uLong nLastItem = nFirstItem + (mnVisLines * mnCols);
+
+ maItemListRect.Left() = x;
+ maItemListRect.Top() = y;
+ maItemListRect.Right() = x + mnCols*(mnItemWidth+mnSpacing) - mnSpacing - 1;
+ maItemListRect.Bottom() = y + mnVisLines*(mnItemHeight+mnSpacing) - mnSpacing - 1;
+
+ if ( !mbFullMode )
+ {
+ // If want also draw parts of items in the last line,
+ // then we add one more line if parts of these line are
+ // visible
+ if ( y+(mnVisLines*(mnItemHeight+mnSpacing)) < aWinSize.Height() )
+ nLastItem += mnCols;
+ maItemListRect.Bottom() = aWinSize.Height() - y;
+ }
+ for ( size_t i = 0; i < nItemCount; i++ )
+ {
+ ThumbnailViewItem *const pItem = mItemList[i];
+
+ if ( (i >= nFirstItem) && (i < nLastItem) )
+ {
+ if( !pItem->mbVisible && ImplHasAccessibleListeners() )
+ {
+ ::com::sun::star::uno::Any aOldAny, aNewAny;
+
+ aNewAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
+ ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
+ }
+
+ pItem->mbVisible = true;
+ ImplFormatItem( pItem, Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ) );
+
+ if ( !((i+1) % mnCols) )
+ {
+ x = nStartX;
+ y += mnItemHeight+mnSpacing;
+ }
+ else
+ x += mnItemWidth+mnSpacing;
+ }
+ else
+ {
+ if( pItem->mbVisible && ImplHasAccessibleListeners() )
+ {
+ ::com::sun::star::uno::Any aOldAny, aNewAny;
+
+ aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
+ ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
+ }
+
+ pItem->mbVisible = false;
+ }
+ }
+
+ // arrange ScrollBar, set values and show it
+ if ( mpScrBar )
+ {
+ Point aPos( aWinSize.Width()-nScrBarWidth+SCRBAR_OFFSET, 0 );
+ Size aSize( nScrBarWidth-SCRBAR_OFFSET, aWinSize.Height() );
+ // If a none field is visible, then we center the scrollbar
+ if ( nStyle & WB_NONEFIELD )
+ {
+ aPos.Y() = nStartY+nNoneHeight+1;
+ aSize.Height() = ((mnItemHeight+mnSpacing)*mnVisLines)-2-mnSpacing;
+ }
+ mpScrBar->SetPosSizePixel( aPos, aSize );
+ mpScrBar->SetRangeMax( mnLines );
+ mpScrBar->SetVisibleSize( mnVisLines );
+ mpScrBar->SetThumbPos( (long)mnFirstLine );
+ long nPageSize = mnVisLines;
+ if ( nPageSize < 1 )
+ nPageSize = 1;
+ mpScrBar->SetPageSize( nPageSize );
+ mpScrBar->Show();
+ }
+ }
+
+ // waiting for the next since the formatting is finished
+ mbFormat = false;
+
+ // delete ScrollBar
+ delete pDelScrBar;
+}
+
+void ThumbnailView::ImplDrawItemText( const rtl::OUString& rText )
+{
+ if ( !(GetStyle() & WB_NAMEFIELD) )
+ return;
+
+ Size aWinSize = GetOutputSizePixel();
+ long nTxtWidth = GetTextWidth( rText );
+ long nTxtOffset = mnTextOffset;
+
+ // delete rectangle and show text
+ if ( GetStyle() & WB_FLATVALUESET )
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ SetLineColor();
+ SetFillColor( rStyleSettings.GetFaceColor() );
+ DrawRect( Rectangle( Point( 0, nTxtOffset ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
+ SetTextColor( rStyleSettings.GetButtonTextColor() );
+ }
+ else
+ {
+ nTxtOffset += NAME_LINE_HEIGHT+NAME_LINE_OFF_Y;
+ Erase( Rectangle( Point( 0, nTxtOffset ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
+ }
+ DrawText( Point( (aWinSize.Width()-nTxtWidth) / 2, nTxtOffset+(NAME_OFFSET/2) ), rText );
+}
+
+void ThumbnailView::ImplDrawSelect()
+{
+ if ( !IsReallyVisible() )
+ return;
+
+ const bool bFocus = HasFocus();
+ const bool bDrawSel = !( (mbNoSelection && !mbHighlight) || (!mbDrawSelection && mbHighlight) );
+
+ if ( !bFocus && !bDrawSel )
+ {
+ rtl::OUString aEmptyStr;
+ ImplDrawItemText( aEmptyStr );
+ return;
+ }
+
+ ImplDrawSelect( mnSelItemId, bFocus, bDrawSel );
+ if (mbHighlight)
+ {
+ ImplDrawSelect( mnHighItemId, bFocus, bDrawSel );
+ }
+}
+
+void ThumbnailView::ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel )
+{
+ ThumbnailViewItem* pItem;
+ Rectangle aRect;
+ if ( nItemId )
+ {
+ const size_t nPos = GetItemPos( nItemId );
+ pItem = mItemList[ nPos ];
+ aRect = ImplGetItemRect( nPos );
+ }
+ else if ( mpNoneItem )
+ {
+ pItem = mpNoneItem;
+ aRect = maNoneItemRect;
+ }
+ else if ( bFocus && (pItem = ImplGetFirstItem()) )
+ {
+ aRect = ImplGetItemRect( 0 );
+ }
+ else
+ {
+ return;
+ }
+
+ if ( pItem->mbVisible )
+ {
+ // draw selection
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ Control::SetFillColor();
+
+ Color aDoubleColor( rStyleSettings.GetHighlightColor() );
+ Color aSingleColor( rStyleSettings.GetHighlightTextColor() );
+ if( !mbDoubleSel )
+ {
+ /*
+ * #99777# contrast enhancement for thin mode
+ */
+ const Wallpaper& rWall = GetDisplayBackground();
+ if( ! rWall.IsBitmap() && ! rWall.IsGradient() )
+ {
+ const Color& rBack = rWall.GetColor();
+ if( rBack.IsDark() && ! aDoubleColor.IsBright() )
+ {
+ aDoubleColor = Color( COL_WHITE );
+ aSingleColor = Color( COL_BLACK );
+ }
+ else if( rBack.IsBright() && ! aDoubleColor.IsDark() )
+ {
+ aDoubleColor = Color( COL_BLACK );
+ aSingleColor = Color( COL_WHITE );
+ }
+ }
+ }
+
+ // specify selection output
+ WinBits nStyle = GetStyle();
+ if ( nStyle & WB_MENUSTYLEVALUESET )
+ {
+ if ( bFocus )
+ ShowFocus( aRect );
+
+ if ( bDrawSel )
+ {
+ SetLineColor( mbBlackSel ? Color( COL_BLACK ) : aDoubleColor );
+ DrawRect( aRect );
+ }
+ }
+ else if ( nStyle & WB_RADIOSEL )
+ {
+ aRect.Left() += 3;
+ aRect.Top() += 3;
+ aRect.Right() -= 3;
+ aRect.Bottom() -= 3;
+ if ( nStyle & WB_DOUBLEBORDER )
+ {
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ }
+
+ if ( bFocus )
+ ShowFocus( aRect );
+
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+
+ if ( bDrawSel )
+ {
+ SetLineColor( aDoubleColor );
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ DrawRect( aRect );
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ DrawRect( aRect );
+ }
+ }
+ else
+ {
+ if ( bDrawSel )
+ {
+ SetLineColor( mbBlackSel ? Color( COL_BLACK ) : aDoubleColor );
+ DrawRect( aRect );
+ }
+ if ( mbDoubleSel )
+ {
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ if ( bDrawSel )
+ DrawRect( aRect );
+ }
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ Rectangle aRect2 = aRect;
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ if ( bDrawSel )
+ DrawRect( aRect );
+ if ( mbDoubleSel )
+ {
+ aRect.Left()++;
+ aRect.Top()++;
+ aRect.Right()--;
+ aRect.Bottom()--;
+ if ( bDrawSel )
+ DrawRect( aRect );
+ }
+
+ if ( bDrawSel )
+ {
+ SetLineColor( mbBlackSel ? Color( COL_WHITE ) : aSingleColor );
+ }
+ else
+ {
+ SetLineColor( Color( COL_LIGHTGRAY ) );
+ }
+ DrawRect( aRect2 );
+
+ if ( bFocus )
+ ShowFocus( aRect2 );
+ }
+
+ ImplDrawItemText( pItem->maText );
+ }
+}
+
+void ThumbnailView::ImplHideSelect( sal_uInt16 nItemId )
+{
+ Rectangle aRect;
+
+ const size_t nItemPos = GetItemPos( nItemId );
+ if ( nItemPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ {
+ if ( !mItemList[nItemPos]->mbVisible )
+ {
+ return;
+ }
+ aRect = ImplGetItemRect(nItemPos);
+ }
+ else
+ {
+ if ( !mpNoneItem )
+ {
+ return;
+ }
+ aRect = maNoneItemRect;
+ }
+
+ HideFocus();
+ const Point aPos = aRect.TopLeft();
+ const Size aSize = aRect.GetSize();
+ DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
+}
+
+void ThumbnailView::ImplHighlightItem( sal_uInt16 nItemId, bool bIsSelection )
+{
+ if ( mnHighItemId != nItemId )
+ {
+ // remember the old item to delete the previous selection
+ sal_uInt16 nOldItem = mnHighItemId;
+ mnHighItemId = nItemId;
+
+ // don't draw the selection if nothing is selected
+ if ( !bIsSelection && mbNoSelection )
+ mbDrawSelection = false;
+
+ // remove the old selection and draw the new one
+ ImplHideSelect( nOldItem );
+ ImplDrawSelect();
+ mbDrawSelection = true;
+ }
+}
+
+void ThumbnailView::ImplDraw()
+{
+ if ( mbFormat )
+ Format();
+
+ HideFocus();
+
+ Point aDefPos;
+ Size aSize = maVirDev.GetOutputSizePixel();
+
+ if ( mpScrBar && mpScrBar->IsVisible() )
+ {
+ Point aScrPos = mpScrBar->GetPosPixel();
+ Size aScrSize = mpScrBar->GetSizePixel();
+ Point aTempPos( 0, aScrPos.Y() );
+ Size aTempSize( aSize.Width(), aScrPos.Y() );
+
+ DrawOutDev( aDefPos, aTempSize, aDefPos, aTempSize, maVirDev );
+ aTempSize.Width() = aScrPos.X()-1;
+ aTempSize.Height() = aScrSize.Height();
+ DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
+ aTempPos.Y() = aScrPos.Y()+aScrSize.Height();
+ aTempSize.Width() = aSize.Width();
+ aTempSize.Height() = aSize.Height()-aTempPos.Y();
+ DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
+ }
+ else
+ DrawOutDev( aDefPos, aSize, aDefPos, aSize, maVirDev );
+
+ // draw parting line to the Namefield
+ if ( GetStyle() & WB_NAMEFIELD )
+ {
+ if ( !(GetStyle() & WB_FLATVALUESET) )
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ Size aWinSize = GetOutputSizePixel();
+ Point aPos1( NAME_LINE_OFF_X, mnTextOffset+NAME_LINE_OFF_Y );
+ Point aPos2( aWinSize.Width()-(NAME_LINE_OFF_X*2), mnTextOffset+NAME_LINE_OFF_Y );
+ if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
+ {
+ SetLineColor( rStyleSettings.GetShadowColor() );
+ DrawLine( aPos1, aPos2 );
+ aPos1.Y()++;
+ aPos2.Y()++;
+ SetLineColor( rStyleSettings.GetLightColor() );
+ }
+ else
+ SetLineColor( rStyleSettings.GetWindowTextColor() );
+ DrawLine( aPos1, aPos2 );
+ }
+ }
+
+ ImplDrawSelect();
+}
+
+bool ThumbnailView::ImplScroll( const Point& rPos )
+{
+ if ( !mbScroll || !maItemListRect.IsInside(rPos) )
+ return false;
+
+ const long nScrollOffset = (mnItemHeight <= 16) ? SCROLL_OFFSET/2 : SCROLL_OFFSET;
+ bool bScroll = false;
+
+ if ( rPos.Y() <= maItemListRect.Top()+nScrollOffset )
+ {
+ if ( mnFirstLine > 0 )
+ {
+ --mnFirstLine;
+ bScroll = true;
+ }
+ }
+ else if ( rPos.Y() >= maItemListRect.Bottom()-nScrollOffset )
+ {
+ if ( mnFirstLine < static_cast<sal_uInt16>(mnLines-mnVisLines) )
+ {
+ ++mnFirstLine;
+ bScroll = true;
+ }
+ }
+
+ if ( !bScroll )
+ return false;
+
+ mbFormat = true;
+ ImplDraw();
+ return true;
+}
+
+size_t ThumbnailView::ImplGetItem( const Point& rPos, bool bMove ) const
+{
+ if ( !mbHasVisibleItems )
+ {
+ return THUMBNAILVIEW_ITEM_NOTFOUND;
+ }
+
+ if ( mpNoneItem && maNoneItemRect.IsInside( rPos ) )
+ {
+ return THUMBNAILVIEW_ITEM_NONEITEM;
+ }
+
+ if ( maItemListRect.IsInside( rPos ) )
+ {
+ const int xc = rPos.X()-maItemListRect.Left();
+ const int yc = rPos.Y()-maItemListRect.Top();
+ // The point is inside the area of item list,
+ // let's find the containing item.
+ const int col = xc/(mnItemWidth+mnSpacing);
+ const int x = xc%(mnItemWidth+mnSpacing);
+ const int row = yc/(mnItemHeight+mnSpacing);
+ const int y = yc%(mnItemHeight+mnSpacing);
+
+ if (x<mnItemWidth && y<mnItemHeight)
+ {
+ // the point is inside item rect and not inside spacing
+ const size_t item = (mnFirstLine+row)*mnCols+col;
+ if (item < mItemList.size())
+ {
+ return item;
+ }
+ }
+
+ // return the previously selected item if spacing is set and
+ // the mouse hasn't left the window yet
+ if ( bMove && mnSpacing && mnHighItemId )
+ {
+ return GetItemPos( mnHighItemId );
+ }
+ }
+
+ return THUMBNAILVIEW_ITEM_NOTFOUND;
+}
+
+ThumbnailViewItem* ThumbnailView::ImplGetItem( size_t nPos )
+{
+ if ( nPos == THUMBNAILVIEW_ITEM_NONEITEM )
+ return mpNoneItem;
+ else
+ return ( nPos < mItemList.size() ) ? mItemList[nPos] : NULL;
+}
+
+ThumbnailViewItem* ThumbnailView::ImplGetFirstItem()
+{
+ return mItemList.empty() ? NULL : mItemList[0];
+}
+
+sal_uInt16 ThumbnailView::ImplGetVisibleItemCount() const
+{
+ sal_uInt16 nRet = 0;
+ const size_t nItemCount = mItemList.size();
+
+ for ( size_t n = 0; n < nItemCount; ++n )
+ {
+ if ( mItemList[n]->mbVisible )
+ ++nRet;
+ }
+
+ return nRet;
+}
+
+ThumbnailViewItem* ThumbnailView::ImplGetVisibleItem( sal_uInt16 nVisiblePos )
+{
+ const size_t nItemCount = mItemList.size();
+
+ for ( size_t n = 0; n < nItemCount; ++n )
+ {
+ ThumbnailViewItem *const pItem = mItemList[n];
+
+ if ( pItem->mbVisible && !nVisiblePos-- )
+ return pItem;
+ }
+
+ return NULL;
+}
+
+void ThumbnailView::ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue )
+{
+ ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
+
+ if( pAcc )
+ pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue );
+}
+
+bool ThumbnailView::ImplHasAccessibleListeners()
+{
+ ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
+ return( pAcc && pAcc->HasAccessibleListeners() );
+}
+
+IMPL_LINK( ThumbnailView,ImplScrollHdl, ScrollBar*, pScrollBar )
+{
+ sal_uInt16 nNewFirstLine = (sal_uInt16)pScrollBar->GetThumbPos();
+ if ( nNewFirstLine != mnFirstLine )
+ {
+ mnFirstLine = nNewFirstLine;
+ mbFormat = true;
+ ImplDraw();
+ }
+ return 0;
+}
+
+IMPL_LINK_NOARG(ThumbnailView, ImplTimerHdl)
+{
+ ImplTracking( GetPointerPosPixel(), true );
+ return 0;
+}
+
+void ThumbnailView::ImplTracking( const Point& rPos, bool bRepeat )
+{
+ if ( bRepeat || mbSelection )
+ {
+ if ( ImplScroll( rPos ) )
+ {
+ if ( mbSelection )
+ {
+ maTimer.SetTimeoutHdl( LINK( this, ThumbnailView, ImplTimerHdl ) );
+ maTimer.SetTimeout( GetSettings().GetMouseSettings().GetScrollRepeat() );
+ maTimer.Start();
+ }
+ }
+ }
+
+ ThumbnailViewItem* pItem = ImplGetItem( ImplGetItem( rPos ) );
+ if ( pItem )
+ {
+ if( GetStyle() & WB_MENUSTYLEVALUESET )
+ mbHighlight = true;
+
+ ImplHighlightItem( pItem->mnId );
+ }
+ else
+ {
+ if( GetStyle() & WB_MENUSTYLEVALUESET )
+ mbHighlight = true;
+
+ ImplHighlightItem( mnSelItemId, false );
+ }
+}
+
+void ThumbnailView::ImplEndTracking( const Point& rPos, bool bCancel )
+{
+ ThumbnailViewItem* pItem;
+
+ // restore the old status in case of termination
+ if ( bCancel )
+ pItem = NULL;
+ else
+ pItem = ImplGetItem( ImplGetItem( rPos ) );
+
+ if ( pItem )
+ {
+ SelectItem( pItem->mnId );
+ if ( !mbSelection && !(GetStyle() & WB_NOPOINTERFOCUS) )
+ GrabFocus();
+ mbHighlight = false;
+ mbSelection = false;
+ Select();
+ }
+ else
+ {
+ ImplHighlightItem( mnSelItemId, false );
+ mbHighlight = false;
+ mbSelection = false;
+ }
+}
+
+void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
+{
+ if ( rMEvt.IsLeft() )
+ {
+ ThumbnailViewItem* pItem = ImplGetItem( ImplGetItem( rMEvt.GetPosPixel() ) );
+ if ( mbSelection )
+ {
+ mbHighlight = true;
+ if ( pItem )
+ {
+ mnHighItemId = mnSelItemId;
+ ImplHighlightItem( pItem->mnId );
+ }
+
+ return;
+ }
+ else
+ {
+ if ( pItem && !rMEvt.IsMod2() )
+ {
+ if ( rMEvt.GetClicks() == 1 )
+ {
+ mbHighlight = true;
+ mnHighItemId = mnSelItemId;
+ ImplHighlightItem( pItem->mnId );
+ StartTracking( STARTTRACK_SCROLLREPEAT );
+ }
+ else if ( rMEvt.GetClicks() == 2 )
+ DoubleClick();
+
+ return;
+ }
+ }
+ }
+
+ Control::MouseButtonDown( rMEvt );
+}
+
+void ThumbnailView::MouseButtonUp( const MouseEvent& rMEvt )
+{
+ // because of SelectionMode
+ if ( rMEvt.IsLeft() && mbSelection )
+ ImplEndTracking( rMEvt.GetPosPixel(), false );
+ else
+ Control::MouseButtonUp( rMEvt );
+}
+
+void ThumbnailView::MouseMove( const MouseEvent& rMEvt )
+{
+ // because of SelectionMode
+ if ( mbSelection || (GetStyle() & WB_MENUSTYLEVALUESET) )
+ ImplTracking( rMEvt.GetPosPixel(), false );
+ Control::MouseMove( rMEvt );
+}
+
+void ThumbnailView::Tracking( const TrackingEvent& rTEvt )
+{
+ Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
+
+ if ( rTEvt.IsTrackingEnded() )
+ ImplEndTracking( aMousePos, rTEvt.IsTrackingCanceled() );
+ else
+ ImplTracking( aMousePos, rTEvt.IsTrackingRepeat() );
+}
+
+void ThumbnailView::KeyInput( const KeyEvent& rKEvt )
+{
+ size_t nLastItem = mItemList.size();
+
+ if ( !nLastItem || !ImplGetFirstItem() )
+ {
+ Control::KeyInput( rKEvt );
+ return;
+ }
+
+ --nLastItem;
+ const size_t nCurPos = mnSelItemId ? GetItemPos( mnSelItemId )
+ : mpNoneItem ? THUMBNAILVIEW_ITEM_NONEITEM : 0;
+ size_t nItemPos = THUMBNAILVIEW_ITEM_NOTFOUND;
+ size_t nVStep = mnCols;
+
+ switch ( rKEvt.GetKeyCode().GetCode() )
+ {
+ case KEY_HOME:
+ nItemPos = mpNoneItem ? THUMBNAILVIEW_ITEM_NONEITEM : 0;
+ break;
+
+ case KEY_END:
+ nItemPos = nLastItem;
+ break;
+
+ case KEY_LEFT:
+ if (nCurPos != THUMBNAILVIEW_ITEM_NONEITEM)
+ {
+ if (nCurPos)
+ {
+ nItemPos = nCurPos-1;
+ }
+ else if (mpNoneItem)
+ {
+ nItemPos = THUMBNAILVIEW_ITEM_NONEITEM;
+ }
+ }
+ break;
+
+ case KEY_RIGHT:
+ if (nCurPos < nLastItem)
+ {
+ if (nCurPos == THUMBNAILVIEW_ITEM_NONEITEM)
+ {
+ nItemPos = 0;
+ }
+ else
+ {
+ nItemPos = nCurPos+1;
+ }
+ }
+ break;
+
+ case KEY_PAGEUP:
+ if (rKEvt.GetKeyCode().IsShift() || rKEvt.GetKeyCode().IsMod1() || rKEvt.GetKeyCode().IsMod2())
+ {
+ Control::KeyInput( rKEvt );
+ return;
+ }
+ nVStep *= mnVisLines;
+ // intentional fall-through
+ case KEY_UP:
+ if (nCurPos != THUMBNAILVIEW_ITEM_NONEITEM)
+ {
+ if (nCurPos == nLastItem)
+ {
+ const size_t nCol = nLastItem % mnCols;
+ if (nCol < mnCurCol)
+ {
+ // Move to previous row/page, keeping the old column
+ nVStep -= mnCurCol - nCol;
+ }
+ }
+ if (nCurPos >= nVStep)
+ {
+ // Go up of a whole page
+ nItemPos = nCurPos-nVStep;
+ }
+ else if (mpNoneItem)
+ {
+ nItemPos = THUMBNAILVIEW_ITEM_NONEITEM;
+ }
+ else if (nCurPos > mnCols)
+ {
+ // Go to same column in first row
+ nItemPos = nCurPos % mnCols;
+ }
+ }
+ break;
+
+ case KEY_PAGEDOWN:
+ if (rKEvt.GetKeyCode().IsShift() || rKEvt.GetKeyCode().IsMod1() || rKEvt.GetKeyCode().IsMod2())
+ {
+ Control::KeyInput( rKEvt );
+ return;
+ }
+ nVStep *= mnVisLines;
+ // intentional fall-through
+ case KEY_DOWN:
+ if (nCurPos != nLastItem)
+ {
+ if (nCurPos == THUMBNAILVIEW_ITEM_NONEITEM)
+ {
+ nItemPos = nVStep-mnCols+mnCurCol;
+ }
+ else
+ {
+ nItemPos = nCurPos+nVStep;
+ }
+ if (nItemPos > nLastItem)
+ {
+ nItemPos = nLastItem;
+ }
+ }
+ break;
+
+ case KEY_RETURN:
+ if (GetStyle() & WB_NO_DIRECTSELECT)
+ {
+ Select();
+ break;
+ }
+ // intentional fall-through
+ default:
+ Control::KeyInput( rKEvt );
+ return;
+ }
+
+ // This point is reached only if key travelling was used,
+ // in which case selection mode should be switched off
+ EndSelection();
+
+ if ( nItemPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ {
+ if ( nItemPos!=THUMBNAILVIEW_ITEM_NONEITEM && nItemPos<nLastItem )
+ {
+ // update current column only in case of a new position
+ // which is also not a "specially" handled one.
+ mnCurCol = nItemPos % mnCols;
+ }
+ const sal_uInt16 nItemId = (nItemPos != THUMBNAILVIEW_ITEM_NONEITEM) ? GetItemId( nItemPos ) : 0;
+ if ( nItemId != mnSelItemId )
+ {
+ SelectItem( nItemId );
+ if (!(GetStyle() & WB_NO_DIRECTSELECT))
+ {
+ // select only if WB_NO_DIRECTSELECT is not set
+ Select();
+ }
+ }
+ }
+}
+
+void ThumbnailView::Command( const CommandEvent& rCEvt )
+{
+ if ( (rCEvt.GetCommand() == COMMAND_WHEEL) ||
+ (rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
+ (rCEvt.GetCommand() == COMMAND_AUTOSCROLL) )
+ {
+ if ( HandleScrollCommand( rCEvt, NULL, mpScrBar ) )
+ return;
+ }
+
+ Control::Command( rCEvt );
+}
+
+void ThumbnailView::Paint( const Rectangle& )
+{
+ if ( GetStyle() & WB_FLATVALUESET )
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ SetLineColor();
+ SetFillColor( rStyleSettings.GetFaceColor() );
+ long nOffY = maVirDev.GetOutputSizePixel().Height();
+ Size aWinSize = GetOutputSizePixel();
+ DrawRect( Rectangle( Point( 0, nOffY ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
+ }
+
+ ImplDraw();
+}
+
+void ThumbnailView::GetFocus()
+{
+ ImplDrawSelect();
+ Control::GetFocus();
+
+ // Tell the accessible object that we got the focus.
+ ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
+ if( pAcc )
+ pAcc->GetFocus();
+}
+
+void ThumbnailView::LoseFocus()
+{
+ if ( mbNoSelection && mnSelItemId )
+ ImplHideSelect( mnSelItemId );
+ else
+ HideFocus();
+ Control::LoseFocus();
+
+ // Tell the accessible object that we lost the focus.
+ ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
+ if( pAcc )
+ pAcc->LoseFocus();
+}
+
+void ThumbnailView::Resize()
+{
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+ Control::Resize();
+}
+
+void ThumbnailView::RequestHelp( const HelpEvent& rHEvt )
+{
+ if ( (rHEvt.GetMode() & (HELPMODE_QUICK | HELPMODE_BALLOON)) == HELPMODE_QUICK )
+ {
+ Point aPos = ScreenToOutputPixel( rHEvt.GetMousePosPixel() );
+ size_t nItemPos = ImplGetItem( aPos );
+ if ( nItemPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ {
+ Rectangle aItemRect = ImplGetItemRect( nItemPos );
+ Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
+ aItemRect.Left() = aPt.X();
+ aItemRect.Top() = aPt.Y();
+ aPt = OutputToScreenPixel( aItemRect.BottomRight() );
+ aItemRect.Right() = aPt.X();
+ aItemRect.Bottom() = aPt.Y();
+ Help::ShowQuickHelp( this, aItemRect, GetItemText( ImplGetItem( nItemPos )->mnId ) );
+ return;
+ }
+ }
+
+ Control::RequestHelp( rHEvt );
+}
+
+void ThumbnailView::StateChanged( StateChangedType nType )
+{
+ Control::StateChanged( nType );
+
+ if ( nType == STATE_CHANGE_INITSHOW )
+ {
+ if ( mbFormat )
+ Format();
+ }
+ else if ( nType == STATE_CHANGE_UPDATEMODE )
+ {
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+ }
+ else if ( nType == STATE_CHANGE_TEXT )
+ {
+ if ( mpNoneItem && !mbFormat && IsReallyVisible() && IsUpdateMode() )
+ {
+ ImplFormatItem( mpNoneItem, maNoneItemRect );
+ Invalidate( maNoneItemRect );
+ }
+ }
+ else if ( (nType == STATE_CHANGE_ZOOM) ||
+ (nType == STATE_CHANGE_CONTROLFONT) )
+ {
+ ImplInitSettings( true, false, false );
+ Invalidate();
+ }
+ else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
+ {
+ ImplInitSettings( false, true, false );
+ Invalidate();
+ }
+ else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
+ {
+ ImplInitSettings( false, false, true );
+ Invalidate();
+ }
+ else if ( (nType == STATE_CHANGE_STYLE) || (nType == STATE_CHANGE_ENABLE) )
+ {
+ mbFormat = true;
+ ImplInitSettings( false, false, true );
+ Invalidate();
+ }
+}
+
+void ThumbnailView::DataChanged( const DataChangedEvent& rDCEvt )
+{
+ Control::DataChanged( rDCEvt );
+
+ if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
+ (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
+ (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
+ ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
+ (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
+ {
+ mbFormat = true;
+ ImplInitSettings( true, true, true );
+ Invalidate();
+ }
+}
+
+void ThumbnailView::Select()
+{
+ maSelectHdl.Call( this );
+}
+
+void ThumbnailView::DoubleClick()
+{
+ maDoubleClickHdl.Call( this );
+}
+
+void ThumbnailView::UserDraw( const UserDrawEvent& )
+{
+}
+
+void ThumbnailView::InsertItem( sal_uInt16 nItemId, const Image& rImage, size_t nPos )
+{
+ ThumbnailViewItem* pItem = new ThumbnailViewItem( *this );
+ pItem->mnId = nItemId;
+ pItem->meType = THUMBNAILITEM_IMAGE;
+ pItem->maImage = rImage;
+ ImplInsertItem( pItem, nPos );
+}
+
+void ThumbnailView::InsertItem( sal_uInt16 nItemId, const Color& rColor, size_t nPos )
+{
+ ThumbnailViewItem* pItem = new ThumbnailViewItem( *this );
+ pItem->mnId = nItemId;
+ pItem->meType = THUMBNAILITEM_COLOR;
+ pItem->maColor = rColor;
+ ImplInsertItem( pItem, nPos );
+}
+
+void ThumbnailView::InsertItem( sal_uInt16 nItemId, const Image& rImage,
+ const rtl::OUString& rText, size_t nPos )
+{
+ ThumbnailViewItem* pItem = new ThumbnailViewItem( *this );
+ pItem->mnId = nItemId;
+ pItem->meType = THUMBNAILITEM_IMAGE;
+ pItem->maImage = rImage;
+ pItem->maText = rText;
+ ImplInsertItem( pItem, nPos );
+}
+
+void ThumbnailView::InsertItem( sal_uInt16 nItemId, const Color& rColor,
+ const rtl::OUString& rText, size_t nPos )
+{
+ ThumbnailViewItem* pItem = new ThumbnailViewItem( *this );
+ pItem->mnId = nItemId;
+ pItem->meType = THUMBNAILITEM_COLOR;
+ pItem->maColor = rColor;
+ pItem->maText = rText;
+ ImplInsertItem( pItem, nPos );
+}
+
+void ThumbnailView::InsertItem( sal_uInt16 nItemId, size_t nPos )
+{
+ ThumbnailViewItem* pItem = new ThumbnailViewItem( *this );
+ pItem->mnId = nItemId;
+ pItem->meType = THUMBNAILITEM_USERDRAW;
+ ImplInsertItem( pItem, nPos );
+}
+
+void ThumbnailView::ImplInsertItem( ThumbnailViewItem *const pItem, const size_t nPos )
+{
+ assert(pItem->mnId); // "ItemId == 0"
+ assert(GetItemPos( pItem->mnId ) == THUMBNAILVIEW_ITEM_NOTFOUND); // ItemId already exists
+
+ if ( nPos < mItemList.size() ) {
+ ValueItemList::iterator it = mItemList.begin();
+ ::std::advance( it, nPos );
+ mItemList.insert( it, pItem );
+ } else {
+ mItemList.push_back( pItem );
+ }
+
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+}
+
+Rectangle ThumbnailView::ImplGetItemRect( size_t nPos ) const
+{
+ const size_t nVisibleBegin = static_cast<size_t>(mnFirstLine)*mnCols;
+ const size_t nVisibleEnd = nVisibleBegin + static_cast<size_t>(mnVisLines)*mnCols;
+
+ // Check if the item is inside the range of the displayed ones,
+ // taking into account that last row could be incomplete
+ if ( nPos<nVisibleBegin || nPos>=nVisibleEnd || nPos>=mItemList.size() )
+ return Rectangle();
+
+ nPos -= nVisibleBegin;
+
+ const size_t row = nPos/mnCols;
+ const size_t col = nPos%mnCols;
+ const long x = maItemListRect.Left()+col*(mnItemWidth+mnSpacing);
+ const long y = maItemListRect.Top()+row*(mnItemHeight+mnSpacing);
+
+ return Rectangle( Point(x, y), Size(mnItemWidth, mnItemHeight) );
+}
+
+void ThumbnailView::RemoveItem( sal_uInt16 nItemId )
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND )
+ return;
+
+ if ( nPos < mItemList.size() ) {
+ ValueItemList::iterator it = mItemList.begin();
+ ::std::advance( it, nPos );
+ delete *it;
+ mItemList.erase( it );
+ }
+
+ // reset variables
+ if ( (mnHighItemId == nItemId) || (mnSelItemId == nItemId) )
+ {
+ mnCurCol = 0;
+ mnHighItemId = 0;
+ mnSelItemId = 0;
+ mbNoSelection = true;
+ }
+
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+}
+
+void ThumbnailView::Clear()
+{
+ ImplDeleteItems();
+
+ // reset variables
+ mnFirstLine = 0;
+ mnCurCol = 0;
+ mnHighItemId = 0;
+ mnSelItemId = 0;
+ mbNoSelection = true;
+
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+}
+
+size_t ThumbnailView::GetItemCount() const
+{
+ return mItemList.size();
+}
+
+size_t ThumbnailView::GetItemPos( sal_uInt16 nItemId ) const
+{
+ for ( size_t i = 0, n = mItemList.size(); i < n; ++i ) {
+ if ( mItemList[i]->mnId == nItemId ) {
+ return i;
+ }
+ }
+ return THUMBNAILVIEW_ITEM_NOTFOUND;
+}
+
+sal_uInt16 ThumbnailView::GetItemId( size_t nPos ) const
+{
+ return ( nPos < mItemList.size() ) ? mItemList[nPos]->mnId : 0 ;
+}
+
+sal_uInt16 ThumbnailView::GetItemId( const Point& rPos ) const
+{
+ size_t nItemPos = ImplGetItem( rPos );
+ if ( nItemPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ return GetItemId( nItemPos );
+
+ return 0;
+}
+
+Rectangle ThumbnailView::GetItemRect( sal_uInt16 nItemId ) const
+{
+ const size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos!=THUMBNAILVIEW_ITEM_NOTFOUND && mItemList[nPos]->mbVisible )
+ return ImplGetItemRect( nPos );
+
+ return Rectangle();
+}
+
+void ThumbnailView::EnableFullItemMode( bool bFullMode )
+{
+ mbFullMode = bFullMode;
+}
+
+void ThumbnailView::SetColCount( sal_uInt16 nNewCols )
+{
+ if ( mnUserCols != nNewCols )
+ {
+ mnUserCols = nNewCols;
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+ }
+}
+
+void ThumbnailView::SetLineCount( sal_uInt16 nNewLines )
+{
+ if ( mnUserVisLines != nNewLines )
+ {
+ mnUserVisLines = nNewLines;
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+ }
+}
+
+void ThumbnailView::SetItemWidth( long nNewItemWidth )
+{
+ if ( mnUserItemWidth != nNewItemWidth )
+ {
+ mnUserItemWidth = nNewItemWidth;
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+ }
+}
+
+void ThumbnailView::SetItemHeight( long nNewItemHeight )
+{
+ if ( mnUserItemHeight != nNewItemHeight )
+ {
+ mnUserItemHeight = nNewItemHeight;
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+ }
+}
+
+void ThumbnailView::SelectItem( sal_uInt16 nItemId )
+{
+ size_t nItemPos = 0;
+
+ if ( nItemId )
+ {
+ nItemPos = GetItemPos( nItemId );
+ if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND )
+ return;
+ }
+
+ if ( (mnSelItemId != nItemId) || mbNoSelection )
+ {
+ sal_uInt16 nOldItem = mnSelItemId ? mnSelItemId : 1;
+ mnSelItemId = nItemId;
+ mbNoSelection = false;
+
+ bool bNewOut = !mbFormat && IsReallyVisible() && IsUpdateMode();
+ bool bNewLine = false;
+
+ // if necessary scroll to the visible area
+ if ( mbScroll && nItemId )
+ {
+ sal_uInt16 nNewLine = (sal_uInt16)(nItemPos / mnCols);
+ if ( nNewLine < mnFirstLine )
+ {
+ mnFirstLine = nNewLine;
+ bNewLine = true;
+ }
+ else if ( nNewLine > (sal_uInt16)(mnFirstLine+mnVisLines-1) )
+ {
+ mnFirstLine = (sal_uInt16)(nNewLine-mnVisLines+1);
+ bNewLine = true;
+ }
+ }
+
+ if ( bNewOut )
+ {
+ if ( bNewLine )
+ {
+ // redraw everything if the visible area has changed
+ mbFormat = true;
+ ImplDraw();
+ }
+ else
+ {
+ // remove old selection and draw the new one
+ ImplHideSelect( nOldItem );
+ ImplDrawSelect();
+ }
+ }
+
+ if( ImplHasAccessibleListeners() )
+ {
+ // focus event (deselect)
+ if( nOldItem )
+ {
+ const size_t nPos = GetItemPos( nItemId );
+
+ if( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ {
+ ThumbnailViewAcc* pItemAcc = ThumbnailViewAcc::getImplementation(
+ mItemList[nPos]->GetAccessible( mbIsTransientChildrenDisabled ) );
+
+ if( pItemAcc )
+ {
+ ::com::sun::star::uno::Any aOldAny, aNewAny;
+ if( !mbIsTransientChildrenDisabled )
+ {
+ aOldAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
+ static_cast< ::cppu::OWeakObject* >( pItemAcc ));
+ ImplFireAccessibleEvent (::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
+ }
+ else
+ {
+ aOldAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
+ pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
+ }
+ }
+ }
+ }
+
+ // focus event (select)
+ const size_t nPos = GetItemPos( mnSelItemId );
+
+ ThumbnailViewItem* pItem;
+ if( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ pItem = mItemList[nPos];
+ else
+ pItem = mpNoneItem;
+
+ ThumbnailViewAcc* pItemAcc = NULL;
+ if (pItem != NULL)
+ pItemAcc = ThumbnailViewAcc::getImplementation( pItem->GetAccessible( mbIsTransientChildrenDisabled ) );
+
+ if( pItemAcc )
+ {
+ ::com::sun::star::uno::Any aOldAny, aNewAny;
+ if( !mbIsTransientChildrenDisabled )
+ {
+ aNewAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
+ static_cast< ::cppu::OWeakObject* >( pItemAcc ));
+ ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
+ }
+ else
+ {
+ aNewAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
+ pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
+ }
+ }
+
+ // selection event
+ ::com::sun::star::uno::Any aOldAny, aNewAny;
+ ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny );
+ }
+ maHighlightHdl.Call(this);
+ }
+}
+
+void ThumbnailView::SetNoSelection()
+{
+ mbNoSelection = true;
+ mbHighlight = false;
+ mbSelection = false;
+
+ if ( IsReallyVisible() && IsUpdateMode() )
+ ImplDraw();
+}
+
+void ThumbnailView::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND )
+ return;
+
+ ThumbnailViewItem* pItem = mItemList[nPos];
+ pItem->meType = THUMBNAILITEM_IMAGE;
+ pItem->maImage = rImage;
+
+ if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
+ {
+ const Rectangle aRect = ImplGetItemRect(nPos);
+ ImplFormatItem( pItem, aRect );
+ Invalidate( aRect );
+ }
+ else
+ mbFormat = true;
+}
+
+Image ThumbnailView::GetItemImage( sal_uInt16 nItemId ) const
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ return mItemList[nPos]->maImage;
+ else
+ return Image();
+}
+
+void ThumbnailView::SetItemColor( sal_uInt16 nItemId, const Color& rColor )
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND )
+ return;
+
+ ThumbnailViewItem* pItem = mItemList[nPos];
+ pItem->meType = THUMBNAILITEM_COLOR;
+ pItem->maColor = rColor;
+
+ if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
+ {
+ const Rectangle aRect = ImplGetItemRect(nPos);
+ ImplFormatItem( pItem, aRect );
+ Invalidate( aRect );
+ }
+ else
+ mbFormat = true;
+}
+
+Color ThumbnailView::GetItemColor( sal_uInt16 nItemId ) const
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ return mItemList[nPos]->maColor;
+ else
+ return Color();
+}
+
+void ThumbnailView::SetItemData( sal_uInt16 nItemId, void* pData )
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND )
+ return;
+
+ ThumbnailViewItem* pItem = mItemList[nPos];
+ pItem->mpData = pData;
+
+ if ( pItem->meType == THUMBNAILITEM_USERDRAW )
+ {
+ if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
+ {
+ const Rectangle aRect = ImplGetItemRect(nPos);
+ ImplFormatItem( pItem, aRect );
+ Invalidate( aRect );
+ }
+ else
+ mbFormat = true;
+ }
+}
+
+void* ThumbnailView::GetItemData( sal_uInt16 nItemId ) const
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ return mItemList[nPos]->mpData;
+ else
+ return NULL;
+}
+
+void ThumbnailView::SetItemText( sal_uInt16 nItemId, const rtl::OUString& rText )
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND )
+ return;
+
+
+ ThumbnailViewItem* pItem = mItemList[nPos];
+
+ // Remember old and new name for accessibility event.
+ ::com::sun::star::uno::Any aOldName, aNewName;
+ ::rtl::OUString sString (pItem->maText);
+ aOldName <<= sString;
+ sString = rText;
+ aNewName <<= sString;
+
+ pItem->maText = rText;
+
+ if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
+ {
+ sal_uInt16 nTempId = mnSelItemId;
+
+ if ( mbHighlight )
+ nTempId = mnHighItemId;
+
+ if ( nTempId == nItemId )
+ ImplDrawItemText( pItem->maText );
+ }
+
+ if (ImplHasAccessibleListeners())
+ {
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::accessibility::XAccessible> xAccessible (
+ pItem->GetAccessible( mbIsTransientChildrenDisabled ) );
+ static_cast<ThumbnailViewAcc*>(xAccessible.get())->FireAccessibleEvent (
+ ::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED,
+ aOldName, aNewName);
+ }
+}
+
+rtl::OUString ThumbnailView::GetItemText( sal_uInt16 nItemId ) const
+{
+ size_t nPos = GetItemPos( nItemId );
+
+ if ( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
+ return mItemList[nPos]->maText;
+
+ return rtl::OUString();
+}
+
+void ThumbnailView::SetColor( const Color& rColor )
+{
+ maColor = rColor;
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ ImplDraw();
+}
+
+void ThumbnailView::SetExtraSpacing( sal_uInt16 nNewSpacing )
+{
+ if ( GetStyle() & WB_ITEMBORDER )
+ {
+ mnSpacing = nNewSpacing;
+
+ mbFormat = true;
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+ }
+}
+
+void ThumbnailView::StartSelection()
+{
+ mbHighlight = true;
+ mbSelection = true;
+ mnHighItemId = mnSelItemId;
+}
+
+void ThumbnailView::EndSelection()
+{
+ if ( mbHighlight )
+ {
+ if ( IsTracking() )
+ EndTracking( ENDTRACK_CANCEL );
+
+ ImplHighlightItem( mnSelItemId );
+ mbHighlight = false;
+ }
+ mbSelection = false;
+}
+
+bool ThumbnailView::StartDrag( const CommandEvent& rCEvt, Region& rRegion )
+{
+ if ( rCEvt.GetCommand() != COMMAND_STARTDRAG )
+ return false;
+
+ // if necessary abort an existing action
+ EndSelection();
+
+ // Check out if the the clicked on page is selected. If this is not the
+ // case set it as the current item. We only check mouse actions since
+ // drag-and-drop can also be triggered by the keyboard
+ sal_uInt16 nSelId;
+ if ( rCEvt.IsMouseEvent() )
+ nSelId = GetItemId( rCEvt.GetMousePosPixel() );
+ else
+ nSelId = mnSelItemId;
+
+ // don't activate dragging if no item was clicked on
+ if ( !nSelId )
+ return false;
+
+ // Check out if the page was selected. If not set as current page and
+ // call select.
+ if ( nSelId != mnSelItemId )
+ {
+ SelectItem( nSelId );
+ Update();
+ Select();
+ }
+
+ Region aRegion;
+
+ // assign region
+ rRegion = aRegion;
+
+ return true;
+}
+
+Size ThumbnailView::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesireCols,
+ sal_uInt16 nDesireLines )
+{
+ size_t nCalcCols = nDesireCols;
+ size_t nCalcLines = nDesireLines;
+
+ if ( !nCalcCols )
+ {
+ if ( mnUserCols )
+ nCalcCols = mnUserCols;
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list