[Libreoffice-commits] .: Branch 'feature/cmclayout' - 2 commits - vcl/inc vcl/source
Caolán McNamara
caolan at kemper.freedesktop.org
Tue Jun 12 08:57:38 PDT 2012
vcl/inc/vcl/builder.hxx | 1
vcl/inc/vcl/tabctrl.hxx | 3 +
vcl/source/control/tabctrl.cxx | 30 ++++++++++---
vcl/source/window/builder.cxx | 90 +++++++++++++++++++++++++++++++----------
4 files changed, 98 insertions(+), 26 deletions(-)
New commits:
commit 4eab7331684945213897588ae3303be4c1c2453e
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Jun 12 16:02:26 2012 +0100
assign tab page ids such that retrofitting existing code is easier
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx
index f98b552..b44cb3f 100644
--- a/vcl/inc/vcl/builder.hxx
+++ b/vcl/inc/vcl/builder.hxx
@@ -98,6 +98,7 @@ public:
~VclBuilder();
Window *get_widget_root();
Window *get_by_name(rtl::OString sID);
+ rtl::OString get_by_window(const Window *pWindow);
//for the purposes of retrofitting this to the existing code
//look up sID, clone its properties into replacement and
//splice replacement into the tree instead of it, without
diff --git a/vcl/inc/vcl/tabctrl.hxx b/vcl/inc/vcl/tabctrl.hxx
index fd064db..14c68e0 100644
--- a/vcl/inc/vcl/tabctrl.hxx
+++ b/vcl/inc/vcl/tabctrl.hxx
@@ -196,6 +196,9 @@ public:
// returns the rectangle of the tab for page nPageId
Rectangle GetTabBounds( sal_uInt16 nPageId ) const;
+
+ // rename nOldId to nNewId);
+ void ReassignPageId(sal_uInt16 nOldId, sal_uInt16 nNewId);
};
#endif // _SV_TABCTRL_HXX
diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx
index 0ac4060..ccf6b4c 100644
--- a/vcl/source/control/tabctrl.cxx
+++ b/vcl/source/control/tabctrl.cxx
@@ -2228,7 +2228,20 @@ void TabControl::SetMinimumSizePixel( const Size& i_rSize )
mpTabCtrlData->maMinSize = i_rSize;
}
-// -----------------------------------------------------------------------
+void TabControl::ReassignPageId(sal_uInt16 nOldId, sal_uInt16 nNewId)
+{
+ for( std::vector< ImplTabItem >::iterator it = mpTabCtrlData->maItemList.begin();
+ it != mpTabCtrlData->maItemList.end(); ++it )
+ {
+ if( it->mnId == nOldId )
+ it->mnId = nNewId;
+ }
+ if (mnActPageId == nOldId)
+ mnActPageId = nNewId;
+
+ if (mnCurPageId == nOldId)
+ mnCurPageId = nOldId;
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 563322b..2f8e5d2 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -183,21 +183,31 @@ Window *VclBuilder::makeObject(Window *pParent, const rtl::OString &name, const
if (pParent && pParent->GetType() == WINDOW_TABCONTROL)
{
//We have to add a page
- TabControl *pTabControl = static_cast<TabControl*>(pParent);
- TabPage* pPage = new TabPage(pTabControl);
- m_aChildren.push_back(WinAndId(rtl::OString(), pPage));
-
- //And give the page one container as a child to make it a layout enabled
- //tab page
- VclBin* pContainer = new VclBin(pPage);
- m_aChildren.push_back(WinAndId(rtl::OString(), pContainer));
- pParent = pContainer;
- //keep it simple and make pageid == position
- sal_uInt16 nNewPageId = pTabControl->GetPageCount()+1;
+ //make default pageid == -position. Partitioning the
+ //id space into negative numbers for auto-generated
+ //ids and positive numbers for the handleTabChild
+ //derived ids
+ TabControl *pTabControl = static_cast<TabControl*>(pParent);
+ sal_uInt16 nNewPageId = -(pTabControl->GetPageCount()+1);
pTabControl->InsertPage(nNewPageId, rtl::OUString());
- pTabControl->SetTabPage(nNewPageId, pPage);
pTabControl->SetCurPageId(nNewPageId);
+
+ bool bIsPlaceHolder = name.isEmpty();
+
+ if (!bIsPlaceHolder)
+ {
+ TabPage* pPage = new TabPage(pTabControl);
+ m_aChildren.push_back(WinAndId(rtl::OString(), pPage));
+
+ //And give the page one container as a child to make it a layout enabled
+ //tab page
+ VclBin* pContainer = new VclBin(pPage);
+ m_aChildren.push_back(WinAndId(rtl::OString(), pContainer));
+ pParent = pContainer;
+
+ pTabControl->SetTabPage(nNewPageId, pPage);
+ }
}
Window *pWindow = NULL;
@@ -341,6 +351,8 @@ void VclBuilder::reorderWithinParent(Window &rWindow, sal_uInt16 nNewPosition)
void VclBuilder::handleTabChild(Window *pParent, xmlreader::XmlReader &reader)
{
+ rtl::OString sID;
+
int nLevel = 1;
stringmap aProperties;
while(1)
@@ -356,6 +368,17 @@ void VclBuilder::handleTabChild(Window *pParent, xmlreader::XmlReader &reader)
++nLevel;
if (name.equals(RTL_CONSTASCII_STRINGPARAM("property")))
collectProperty(reader, aProperties);
+ else if (name.equals(RTL_CONSTASCII_STRINGPARAM("object")))
+ {
+ while (reader.nextAttribute(&nsId, &name))
+ {
+ if (name.equals(RTL_CONSTASCII_STRINGPARAM("id")))
+ {
+ name = reader.getAttributeValue(false);
+ sID = rtl::OString(name.begin, name.length);
+ }
+ }
+ }
}
if (res == xmlreader::XmlReader::RESULT_END)
@@ -371,7 +394,26 @@ void VclBuilder::handleTabChild(Window *pParent, xmlreader::XmlReader &reader)
TabControl *pTabControl = static_cast<TabControl*>(pParent);
VclBuilder::stringmap::iterator aFind = aProperties.find(rtl::OString(RTL_CONSTASCII_STRINGPARAM("label")));
if (aFind != aProperties.end())
+ {
pTabControl->SetPageText(pTabControl->GetCurPageId(), rtl::OStringToOUString(aFind->second, RTL_TEXTENCODING_UTF8));
+
+ sal_Int32 nID = 0;
+ //To make it easier to retro fit pre-builder dialog code we take the
+ //notebook child id (falling back to notebook label id) and if its a
+ //positive number use that as the page id so existing code can find the
+ //right tabpage by id
+ TabPage *pPage = pTabControl->GetTabPage(pTabControl->GetCurPageId());
+ if (pPage)
+ {
+ VclBin *pContainer = static_cast<VclBin*>(pPage->GetWindow(WINDOW_FIRSTCHILD));
+ Window *pChild = pContainer->get_child();
+ nID = pChild ? get_by_window(pChild).toInt32() : 0;
+ }
+ if (nID == 0)
+ nID = sID.toInt32();
+ if (nID > 0)
+ pTabControl->ReassignPageId(pTabControl->GetCurPageId(), nID);
+ }
else
pTabControl->RemovePage(pTabControl->GetCurPageId());
}
@@ -411,13 +453,15 @@ void VclBuilder::handleChild(Window *pParent, xmlreader::XmlReader &reader)
{
pCurrentChild = handleObject(pParent, reader);
- if (pCurrentChild)
+ bool bObjectInserted = pCurrentChild && pParent != pCurrentChild;
+
+ if (bObjectInserted)
{
//Select the first page if its a notebook
if (pCurrentChild->GetType() == WINDOW_TABCONTROL)
{
TabControl *pTabControl = static_cast<TabControl*>(pCurrentChild);
- pTabControl->SetCurPageId(1);
+ pTabControl->SetCurPageId(pTabControl->GetPageId(0));
//To-Do add reorder capability to the TabControl
}
@@ -713,6 +757,18 @@ Window *VclBuilder::get_by_name(rtl::OString sID)
return NULL;
}
+rtl::OString VclBuilder::get_by_window(const Window *pWindow)
+{
+ for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
+ aEnd = m_aChildren.end(); aI != aEnd; ++aI)
+ {
+ if (aI->m_pWindow == pWindow)
+ return aI->m_sID;
+ }
+
+ return rtl::OString();
+}
+
VclBuilder::ListStore *VclBuilder::get_model_by_name(rtl::OString sID)
{
for (std::vector<ModelAndId>::iterator aI = m_aModels.begin(),
@@ -728,14 +784,8 @@ VclBuilder::ListStore *VclBuilder::get_model_by_name(rtl::OString sID)
void VclBuilder::swapGuts(Window &rOrig, Window &rReplacement)
{
#if 1
- if (rOrig.mpWindowImpl->mpBorderWindow)
- fprintf(stderr, "problem one\n");
-
sal_uInt16 nPosition = getPositionWithinParent(rOrig);
- if (rReplacement.mpWindowImpl->mpBorderWindow)
- fprintf(stderr, "problem two\n");
-
rReplacement.take_properties(rOrig);
reorderWithinParent(rReplacement, nPosition);
commit 0e59f9ed6f10211d0dbfe4b57ef2b5996378be3e
Author: Caolán McNamara <caolanm at redhat.com>
Date: Tue Jun 12 15:59:18 2012 +0100
consider tab widths even in empty tab pages
diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx
index b238e39..0ac4060 100644
--- a/vcl/source/control/tabctrl.cxx
+++ b/vcl/source/control/tabctrl.cxx
@@ -2181,17 +2181,18 @@ Size TabControl::GetOptimalSize(WindowSizeType eType) const
{
Size aOptimalPageSize(0, 0);
Size aOptimalTabSize(0, 0);
+ long nTotalTabWidths = 0;
for( std::vector< ImplTabItem >::const_iterator it = mpTabCtrlData->maItemList.begin();
it != mpTabCtrlData->maItemList.end(); ++it )
{
+ Size aPageSize;
const TabPage *pPage = it->mpTabPage;
- if (!pPage)
- {
+ if (pPage)
+ aPageSize = pPage->GetOptimalSize(eType);
+ else
fprintf(stderr, "nuisance, page not inserted yet :-(\n");
- continue;
- }
- Size aPageSize(pPage->GetOptimalSize(eType));
+
if (aPageSize.Width() > aOptimalPageSize.Width())
aOptimalPageSize.Width() = aPageSize.Width();
if (aPageSize.Height() > aOptimalPageSize.Height())
@@ -2202,11 +2203,15 @@ Size TabControl::GetOptimalSize(WindowSizeType eType) const
Size aTabSize = pThis->ImplGetItemSize(pItem, LONG_MAX);
if (aTabSize.Height() > aOptimalTabSize.Height())
aOptimalTabSize.Height() = aTabSize.Height();
+ nTotalTabWidths += aTabSize.Width();
}
Size aOptimalSize(aOptimalPageSize);
aOptimalSize.Height() += aOptimalTabSize.Height();
+ if (nTotalTabWidths > aOptimalSize.Width())
+ aOptimalSize.Width() = nTotalTabWidths;
+
aOptimalSize.Width() += TAB_OFFSET * 2;
aOptimalSize.Height() += TAB_OFFSET * 2;
More information about the Libreoffice-commits
mailing list