1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/SvxPresetListBox.hxx>
21 #include <svx/xtable.hxx>
22 #include <vcl/builderfactory.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
25 #include <vcl/image.hxx>
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <vcl/menu.hxx>
29 #include <vcl/popupmenuwindow.hxx>
31 SvxPresetListBox::SvxPresetListBox(vcl::Window
* pParent
, WinBits nWinStyle
)
32 : ValueSet(pParent
, nWinStyle
)
34 SetEdgeBlending(true);
38 VCL_BUILDER_DECL_FACTORY(SvxPresetListBox
)
40 WinBits nWinBits
= WB_TABSTOP
;
42 OString sBorder
= VclBuilder::extractCustomProperty(rMap
);
43 if(!sBorder
.isEmpty())
44 nWinBits
|= WB_BORDER
;
45 nWinBits
|= (WB_ITEMBORDER
| WB_3DLOOK
|WB_OWNERDRAWDECORATION
|WB_VSCROLL
);
46 rRet
= VclPtr
<SvxPresetListBox
>::Create(pParent
, nWinBits
);
49 void SvxPresetListBox::Resize()
55 void SvxPresetListBox::Command( const CommandEvent
& rEvent
)
57 switch(rEvent
.GetCommand())
59 case CommandEventId::ContextMenu
:
61 const sal_uInt16 nIndex
= GetSelectItemId();
64 Point
aPos(rEvent
.GetMousePosPixel());
65 ScopedVclPtrInstance
<PopupMenu
> pMenu(SVX_RES(RID_SVX_PRESET_MENU
));
66 FloatingWindow
* pMenuWindow
= dynamic_cast<FloatingWindow
*>(pMenu
->GetWindow());
67 if(pMenuWindow
!= nullptr)
69 pMenuWindow
->SetPopupModeFlags(
70 pMenuWindow
->GetPopupModeFlags() | FloatWinPopupFlags::NoMouseUpClose
);
72 pMenu
->SetSelectHdl( LINK(this, SvxPresetListBox
, OnMenuItemSelected
) );
73 pMenu
->Execute(this,Rectangle(aPos
,Size(1,1)),PopupMenuFlags::ExecuteDown
);
78 ValueSet::Command( rEvent
);
83 void SvxPresetListBox::DrawLayout()
85 SetColCount(getColumnCount());
88 template< typename ListType
, typename EntryType
>
89 void SvxPresetListBox::FillPresetListBoxImpl(ListType
& pList
, sal_uInt32 nStartIndex
)
91 const Size
aSize(100,60);
93 for(long nIndex
= 0; nIndex
< pList
.Count(); nIndex
++, nStartIndex
++)
95 aBitmap
= pList
.GetBitmapForPreview(nIndex
, aSize
);
96 EntryType
*pItem
= static_cast<EntryType
*>( pList
.Get( nIndex
) );
97 InsertItem(nStartIndex
, Image(aBitmap
), pItem
->GetName());
101 void SvxPresetListBox::FillPresetListBox(XGradientList
& pList
, sal_uInt32 nStartIndex
)
103 FillPresetListBoxImpl
< XGradientList
, XGradientEntry
>( pList
, nStartIndex
);
106 void SvxPresetListBox::FillPresetListBox(XHatchList
& pList
, sal_uInt32 nStartIndex
)
108 FillPresetListBoxImpl
< XHatchList
, XHatchEntry
>( pList
, nStartIndex
);
111 void SvxPresetListBox::FillPresetListBox(XBitmapList
& pList
, sal_uInt32 nStartIndex
)
113 FillPresetListBoxImpl
< XBitmapList
, XBitmapEntry
>( pList
, nStartIndex
);
116 IMPL_LINK_TYPED(SvxPresetListBox
, OnMenuItemSelected
, Menu
*, pMenu
, bool)
118 if( pMenu
== nullptr )
120 OSL_ENSURE( pMenu
!= nullptr, "SvxPresetListBox::OnMenuItemSelected : illegal menu!" );
124 switch(pMenu
->GetCurItemId())
127 case RID_SVX_PRESET_RENAME
:
128 maRenameHdl
.Call(this);
130 case RID_SVX_PRESET_DELETE
:
131 maDeleteHdl
.Call(this);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */