widget layout: Allow specification of size request for toolbox items.

Change-Id: I4b2f1ca9eb0b5bdb77e16a969918dd4f6afefb53
This commit is contained in:
Jan Holesovsky
2013-06-14 16:33:23 +02:00
parent 468841be44
commit edbca87dea
7 changed files with 43 additions and 10 deletions

View File

@@ -56,6 +56,7 @@ public:
virtual void InsertItem(const OUString& rCommand,
const com::sun::star::uno::Reference<com::sun::star::frame::XFrame>& rFrame,
ToolBoxItemBits nBits = 0,
const Size& rRequestedSize = Size(),
sal_uInt16 nPos = TOOLBOX_APPEND);
void SetBorderWindow (const Window* pBorderWindow);

View File

@@ -343,6 +343,7 @@ public:
virtual void InsertItem( const OUString& rCommand,
const com::sun::star::uno::Reference<com::sun::star::frame::XFrame>& rFrame,
ToolBoxItemBits nBits = 0,
const Size& rRequestedSize = Size(),
sal_uInt16 nPos = TOOLBOX_APPEND );
void InsertItem( sal_uInt16 nItemId, const Image& rImage,
ToolBoxItemBits nBits = 0,

View File

@@ -125,11 +125,11 @@ SidebarToolBox::~SidebarToolBox (void)
void SidebarToolBox::InsertItem(const OUString& rCommand,
const com::sun::star::uno::Reference<com::sun::star::frame::XFrame>& rFrame,
ToolBoxItemBits nBits, sal_uInt16 nPos)
ToolBoxItemBits nBits, const Size& rRequestedSize, sal_uInt16 nPos)
{
ToolBox::InsertItem(rCommand, rFrame, nBits, nPos);
ToolBox::InsertItem(rCommand, rFrame, nBits, rRequestedSize, nPos);
CreateController(GetItemId(rCommand), rFrame, 0);
CreateController(GetItemId(rCommand), rFrame, std::max(rRequestedSize.Width(), 0L));
RegisterHandlers();
}

View File

@@ -63,7 +63,9 @@ struct ImplToolItem
OString maHelpId;
Rectangle maRect;
Rectangle maCalcRect;
// the overall horizontal item size, including one or more of [image size + textlength + dropdown arrow]
/// Widget layout may request size; set it as the minimal size.
Size maMinimalItemSize;
/// The overall horizontal item size, including one or more of [image size + textlength + dropdown arrow]
Size maItemSize;
long mnSepSize;
long mnDropDownArrowWidth;

View File

@@ -633,6 +633,25 @@ namespace
return sActionName;
}
Size extractSizeRequest(VclBuilder::stringmap &rMap)
{
OString sWidthRequest("0");
OString sHeightRequest("0");
VclBuilder::stringmap::iterator aFind = rMap.find(OString("width-request"));
if (aFind != rMap.end())
{
sWidthRequest = aFind->second;
rMap.erase(aFind);
}
aFind = rMap.find(OString("height-request"));
if (aFind != rMap.end())
{
sHeightRequest = aFind->second;
rMap.erase(aFind);
}
return Size(sWidthRequest.toInt32(), sHeightRequest.toInt32());
}
Window * extractStockAndBuildPushButton(Window *pParent, VclBuilder::stringmap &rMap)
{
WinBits nBits = WB_CENTER|WB_VCENTER|WB_3DLOOK;
@@ -1259,7 +1278,7 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri
nBits |= TIB_DROPDOWN;
if (!aCommand.isEmpty())
pToolBox->InsertItem(aCommand, m_xFrame, nBits);
pToolBox->InsertItem(aCommand, m_xFrame, nBits, extractSizeRequest(rMap));
return NULL; // no widget to be created
}

View File

@@ -1935,10 +1935,13 @@ sal_Bool ToolBox::ImplCalcItem()
if( it->meType == TOOLBOXITEM_BUTTON )
{
if( it->maItemSize.Width() < nMinWidth )
it->maItemSize.Width() = nMinWidth;
if( it->maItemSize.Height() < nMinHeight )
it->maItemSize.Height() = nMinHeight;
long nMinW = std::max(nMinWidth, it->maMinimalItemSize.Width());
long nMinH = std::max(nMinHeight, it->maMinimalItemSize.Height());
if( it->maItemSize.Width() < nMinW )
it->maItemSize.Width() = nMinW;
if( it->maItemSize.Height() < nMinH )
it->maItemSize.Height() = nMinH;
}
// keep track of max item size

View File

@@ -166,6 +166,7 @@ ImplToolItem::ImplToolItem( const ImplToolItem& rItem ) :
maHelpId ( rItem.maHelpId ),
maRect ( rItem.maRect ),
maCalcRect ( rItem.maCalcRect ),
maMinimalItemSize ( rItem.maMinimalItemSize ),
maItemSize ( rItem.maItemSize ),
mnSepSize ( rItem.mnSepSize ),
mnDropDownArrowWidth ( rItem.mnDropDownArrowWidth ),
@@ -207,6 +208,7 @@ ImplToolItem& ImplToolItem::operator=( const ImplToolItem& rItem )
maCalcRect = rItem.maCalcRect;
mnSepSize = rItem.mnSepSize;
mnDropDownArrowWidth = rItem.mnDropDownArrowWidth;
maMinimalItemSize = rItem.maMinimalItemSize;
maItemSize = rItem.maItemSize;
mbVisibleText = rItem.mbVisibleText;
meType = rItem.meType;
@@ -758,7 +760,7 @@ static Image getCommandImage(const OUString& rCommand, bool bLarge,
return Image();
}
void ToolBox::InsertItem(const OUString& rCommand, const uno::Reference<frame::XFrame>& rFrame, ToolBoxItemBits nBits, sal_uInt16 nPos)
void ToolBox::InsertItem(const OUString& rCommand, const uno::Reference<frame::XFrame>& rFrame, ToolBoxItemBits nBits, const Size& rRequestedSize, sal_uInt16 nPos)
{
uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
uno::Reference<frame::XModuleManager2> xModuleManager(frame::ModuleManager::create(xContext));
@@ -773,6 +775,11 @@ void ToolBox::InsertItem(const OUString& rCommand, const uno::Reference<frame::X
InsertItem(nItemId, aImage, aLabel, nBits, nPos);
SetItemCommand(nItemId, rCommand);
// set the minimal size
ImplToolItem* pItem = ImplGetItem( nItemId );
if ( pItem )
pItem->maMinimalItemSize = rRequestedSize;
}
// -----------------------------------------------------------------------