summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-12-04 15:28:48 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-12-04 16:19:10 +0000
commit953cb304b16d04e8ec6e023643b9393395e2d99a (patch)
tree8660df8191daa93c4f4b825939daf88653437c30 /vcl
parent0178ef0039a10a9d2adfe081845ac2e6e8e0ef05 (diff)
export VclScrolledWindow for external-to-builder use
as a work-in-progress Change-Id: I6065f3a4db5056cd925152dccd275de0d17b77b9
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/vcl/layout.hxx40
-rw-r--r--vcl/source/window/builder.cxx15
-rw-r--r--vcl/source/window/dialog.cxx10
-rw-r--r--vcl/source/window/layout.cxx99
-rw-r--r--vcl/source/window/tabdlg.cxx6
-rw-r--r--vcl/source/window/tabpage.cxx2
-rw-r--r--vcl/source/window/window2.cxx2
7 files changed, 141 insertions, 33 deletions
diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx
index 04ee7e3fb31f..b09b112348f0 100644
--- a/vcl/inc/vcl/layout.hxx
+++ b/vcl/inc/vcl/layout.hxx
@@ -12,13 +12,14 @@
#include <vcl/dllapi.h>
#include <vcl/button.hxx>
+#include <vcl/scrbar.hxx>
#include <vcl/window.hxx>
#include <boost/multi_array.hpp>
class VCL_DLLPUBLIC VclContainer : public Window
{
public:
- VclContainer(Window *pParent);
+ VclContainer(Window *pParent, WinBits nStyle = WB_HIDE);
virtual Size GetOptimalSize(WindowSizeType eType) const;
virtual void SetPosSizePixel(const Point& rNewPos, const Size& rNewSize);
virtual void SetPosPixel(const Point& rAllocPos);
@@ -426,7 +427,10 @@ VCL_DLLPUBLIC void setGridAttach(Window &rWidget, sal_Int32 nLeft, sal_Int32 nTo
class VCL_DLLPUBLIC VclBin : public VclContainer
{
public:
- VclBin(Window *pParent) : VclContainer(pParent) {}
+ VclBin(Window *pParent, WinBits nStyle = WB_HIDE)
+ : VclContainer(pParent, nStyle)
+ {
+ }
virtual Window *get_child();
virtual const Window *get_child() const;
virtual Size calculateRequisition() const;
@@ -498,6 +502,32 @@ private:
DECL_DLLPRIVATE_LINK(ClickHdl, DisclosureButton* pBtn);
};
+//This is a work in progress, so if you want to put something inside a
+//scrolled window that doesn't handle its own scrolling, then you may need to
+//implement this fully
+class VCL_DLLPUBLIC VclScrolledWindow : public VclBin
+{
+public:
+ VclScrolledWindow(Window *pParent, WinBits nStyle = WB_HIDE | WB_AUTOHSCROLL | WB_AUTOVSCROLL)
+ : VclBin(pParent, nStyle)
+ , m_aVScroll(this, WB_HIDE | WB_VERT)
+ , m_aHScroll(this, WB_HIDE | WB_HORZ)
+ {
+ SetType(WINDOW_SCROLLWINDOW);
+ }
+ virtual Window *get_child();
+ virtual const Window *get_child() const;
+ virtual bool set_property(const OString &rKey, const OString &rValue);
+ ScrollBar& getVertScrollBar() { return m_aVScroll; }
+ ScrollBar& getHorzScrollBar() { return m_aHScroll; }
+ Size getVisibleChildSize() const;
+protected:
+ virtual Size calculateRequisition() const;
+ virtual void setAllocation(const Size &rAllocation);
+private:
+ ScrollBar m_aVScroll;
+ ScrollBar m_aHScroll;
+};
// retro-fitting utilities //
@@ -525,6 +555,12 @@ bool isEnabledInLayout(const Window *pWindow);
Window* nextLogicalChildOfParent(Window *pTopLevel, Window *pChild);
Window* prevLogicalChildOfParent(Window *pTopLevel, Window *pChild);
+inline bool isContainerWindow(const Window &rWindow)
+{
+ WindowType eType = rWindow.GetType();
+ return (eType == WINDOW_CONTAINER || eType == WINDOW_SCROLLWINDOW);
+}
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 0d8068bf83d3..5b4b5e29f452 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -573,21 +573,6 @@ bool VclBuilder::extractImage(const OString &id, stringmap &rMap)
return false;
}
-//This doesn't actually do anything yet, so hide it down here in builder.cxx as
-//merely a temporary storage for scrolling information for vcl controls which
-//actually manage their own scrolling. If you want to put something inside
-//a scrolled window that doesn't handle its own scrolling, then you
-//need to implement this fully and move into a top-level header
-class VclScrolledWindow : public Window
-{
-public:
- VclScrolledWindow(Window *pParent)
- : Window(WINDOW_SCROLLWINDOW)
- {
- ImplInit(pParent, WB_HIDE | WB_AUTOHSCROLL | WB_AUTOVSCROLL, NULL);
- }
-};
-
#ifndef DISABLE_DYNLOADING
extern "C" { static void SAL_CALL thisModule() {} }
#endif
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 20f143124080..3ef0f445b446 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -123,7 +123,7 @@ Window * nextLogicalChildOfParent(Window *pTopLevel, Window *pChild)
{
Window *pLastChild = pChild;
- if (pChild->GetType() == WINDOW_CONTAINER)
+ if (isContainerWindow(*pChild))
pChild = pChild->GetWindow(WINDOW_FIRSTCHILD);
else
pChild = pChild->GetWindow(WINDOW_NEXT);
@@ -139,7 +139,7 @@ Window * nextLogicalChildOfParent(Window *pTopLevel, Window *pChild)
pChild = pParent->GetWindow(WINDOW_NEXT);
}
- if (pChild && pChild->GetType() == WINDOW_CONTAINER)
+ if (pChild && isContainerWindow(*pChild))
pChild = nextLogicalChildOfParent(pTopLevel, pChild);
return pChild;
@@ -149,7 +149,7 @@ Window * prevLogicalChildOfParent(Window *pTopLevel, Window *pChild)
{
Window *pLastChild = pChild;
- if (pChild->GetType() == WINDOW_CONTAINER)
+ if (isContainerWindow(*pChild))
pChild = pChild->GetWindow(WINDOW_LASTCHILD);
else
pChild = pChild->GetWindow(WINDOW_PREV);
@@ -165,7 +165,7 @@ Window * prevLogicalChildOfParent(Window *pTopLevel, Window *pChild)
pChild = pParent->GetWindow(WINDOW_PREV);
}
- if (pChild && pChild->GetType() == WINDOW_CONTAINER)
+ if (pChild && isContainerWindow(*pChild))
pChild = prevLogicalChildOfParent(pTopLevel, pChild);
return pChild;
@@ -1170,7 +1170,7 @@ bool Dialog::isLayoutEnabled() const
{
//pre dtor called, and single child is a container => we're layout enabled
const Window *pChild = mpDialogImpl ? GetWindow(WINDOW_FIRSTCHILD) : NULL;
- return pChild && pChild->GetType() == WINDOW_CONTAINER && !pChild->GetWindow(WINDOW_NEXT);
+ return pChild && isContainerWindow(*pChild) && !pChild->GetWindow(WINDOW_NEXT);
}
Size Dialog::GetOptimalSize(WindowSizeType eType) const
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index f947bee97773..91017d5cb9ca 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -11,11 +11,11 @@
#include <vcl/layout.hxx>
#include "window.h"
-VclContainer::VclContainer(Window *pParent)
+VclContainer::VclContainer(Window *pParent, WinBits nStyle)
: Window(WINDOW_CONTAINER)
, m_bLayoutDirty(true)
{
- ImplInit(pParent, WB_HIDE, NULL);
+ ImplInit(pParent, nStyle, NULL);
EnableChildTransparentMode();
SetPaintTransparent(sal_True);
SetBackground();
@@ -1195,6 +1195,93 @@ IMPL_LINK( VclExpander, ClickHdl, DisclosureButton*, pBtn )
return 0;
}
+const Window *VclScrolledWindow::get_child() const
+{
+ assert(GetChildCount() == 3);
+ const WindowImpl* pWindowImpl = ImplGetWindowImpl();
+ return pWindowImpl->mpLastChild;
+}
+
+Window *VclScrolledWindow::get_child()
+{
+ return const_cast<Window*>(const_cast<const VclScrolledWindow*>(this)->get_child());
+}
+
+Size VclScrolledWindow::calculateRequisition() const
+{
+ Size aRet(0, 0);
+
+ const Window *pChild = get_child();
+ if (pChild && pChild->IsVisible())
+ aRet = getLayoutRequisition(*pChild);
+
+ if (m_aVScroll.IsVisible())
+ aRet.Width() += getLayoutRequisition(m_aVScroll).Width();
+
+ if (m_aHScroll.IsVisible())
+ aRet.Height() += getLayoutRequisition(m_aVScroll).Height();
+
+ return aRet;
+}
+
+void VclScrolledWindow::setAllocation(const Size &rAllocation)
+{
+ Size aChildAllocation(rAllocation);
+ Size aChildReq;
+
+ Window *pChild = get_child();
+ if (pChild && pChild->IsVisible())
+ aChildReq = getLayoutRequisition(*pChild);
+
+ if (m_aVScroll.IsVisible())
+ {
+ long nScrollBarWidth = getLayoutRequisition(m_aVScroll).Width();
+ Point aScrollPos(rAllocation.Width() - nScrollBarWidth, 0);
+ Size aScrollSize(nScrollBarWidth, rAllocation.Height());
+ setLayoutAllocation(m_aVScroll, aScrollPos, aScrollSize);
+ aChildAllocation.Width() -= nScrollBarWidth;
+ aChildAllocation.Height() = aChildReq.Height();
+ }
+
+ if (m_aHScroll.IsVisible())
+ {
+ long nScrollBarHeight = getLayoutRequisition(m_aHScroll).Height();
+ Point aScrollPos(0, rAllocation.Height() - nScrollBarHeight);
+ Size aScrollSize(rAllocation.Width(), nScrollBarHeight);
+ setLayoutAllocation(m_aHScroll, aScrollPos, aScrollSize);
+ aChildAllocation.Height() -= nScrollBarHeight;
+ aChildAllocation.Width() = aChildReq.Width();
+ }
+
+ if (pChild && pChild->IsVisible())
+ {
+ Point aChildPos(pChild->GetPosPixel());
+ if (!m_aHScroll.IsVisible())
+ aChildPos.X() = 0;
+ if (!m_aVScroll.IsVisible())
+ aChildPos.Y() = 0;
+ setLayoutAllocation(*pChild, aChildPos, aChildAllocation);
+ }
+}
+
+Size VclScrolledWindow::getVisibleChildSize() const
+{
+ Size aRet(GetSizePixel());
+ if (m_aVScroll.IsVisible())
+ aRet.Width() -= m_aVScroll.GetSizePixel().Width();
+ if (m_aHScroll.IsVisible())
+ aRet.Height() -= m_aHScroll.GetSizePixel().Height();
+ return aRet;
+}
+
+bool VclScrolledWindow::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
+{
+ bool bRet = VclBin::set_property(rKey, rValue);
+ m_aVScroll.Show(GetStyle() & WB_VERT);
+ m_aHScroll.Show(GetStyle() & WB_HORZ);
+ return bRet;
+}
+
Size getLegacyBestSizeForChildren(const Window &rWindow)
{
Rectangle aBounds;
@@ -1225,7 +1312,7 @@ Window* getNonLayoutParent(Window *pWindow)
while (pWindow)
{
pWindow = pWindow->GetParent();
- if (!pWindow || pWindow->GetType() != WINDOW_CONTAINER)
+ if (!pWindow || !isContainerWindow(*pWindow))
break;
}
return pWindow;
@@ -1236,7 +1323,7 @@ Window* getNonLayoutRealParent(Window *pWindow)
while (pWindow)
{
pWindow = pWindow->ImplGetParent();
- if (!pWindow || pWindow->GetType() != WINDOW_CONTAINER)
+ if (!pWindow || !isContainerWindow(*pWindow))
break;
}
return pWindow;
@@ -1249,7 +1336,7 @@ bool isVisibleInLayout(const Window *pWindow)
{
bVisible = pWindow->IsVisible();
pWindow = pWindow->GetParent();
- if (!pWindow || pWindow->GetType() != WINDOW_CONTAINER)
+ if (!pWindow || !isContainerWindow(*pWindow))
break;
}
return bVisible;
@@ -1262,7 +1349,7 @@ bool isEnabledInLayout(const Window *pWindow)
{
bEnabled = pWindow->IsEnabled();
pWindow = pWindow->GetParent();
- if (!pWindow || pWindow->GetType() != WINDOW_CONTAINER)
+ if (!pWindow || !isContainerWindow(*pWindow))
break;
}
return bEnabled;
diff --git a/vcl/source/window/tabdlg.cxx b/vcl/source/window/tabdlg.cxx
index 64b44b5cfd9a..d6dbcd38f7bc 100644
--- a/vcl/source/window/tabdlg.cxx
+++ b/vcl/source/window/tabdlg.cxx
@@ -18,6 +18,7 @@
*/
#include <vcl/fixed.hxx>
+#include <vcl/layout.hxx>
#include <vcl/tabctrl.hxx>
#include <vcl/tabdlg.hxx>
#include <tools/rc.h>
@@ -51,8 +52,7 @@ void TabDialog::ImplPosControls()
{
if ( pChild->IsVisible() && (pChild != mpViewWindow) )
{
- WindowType eChildType = pChild->GetType();
- if ( eChildType == WINDOW_TABCONTROL || eChildType == WINDOW_CONTAINER )
+ if (pChild->GetType() == WINDOW_TABCONTROL || isContainerWindow(*pChild))
pTabControl = pChild;
else if ( pTabControl )
{
@@ -85,7 +85,7 @@ void TabDialog::ImplPosControls()
Point aTabOffset( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+nOffY );
- if (pTabControl->GetType() == WINDOW_CONTAINER)
+ if (isContainerWindow(*pTabControl))
pTabControl->SetSizePixel(pTabControl->GetOptimalSize(WINDOWSIZE_PREFERRED));
Size aTabSize = pTabControl->GetSizePixel();
diff --git a/vcl/source/window/tabpage.cxx b/vcl/source/window/tabpage.cxx
index 820a73f8127a..3546c4f15508 100644
--- a/vcl/source/window/tabpage.cxx
+++ b/vcl/source/window/tabpage.cxx
@@ -213,7 +213,7 @@ bool TabPage::isLayoutEnabled() const
{
//Child is a container => we're layout enabled
const Window *pChild = GetWindow(WINDOW_FIRSTCHILD);
- return pChild && pChild->GetType() == WINDOW_CONTAINER && !pChild->GetWindow(WINDOW_NEXT);
+ return pChild && isContainerWindow(*pChild) && !pChild->GetWindow(WINDOW_NEXT);
}
Size TabPage::GetOptimalSize(WindowSizeType eType) const
diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx
index 647463c2e127..0459a5be7b86 100644
--- a/vcl/source/window/window2.cxx
+++ b/vcl/source/window/window2.cxx
@@ -1746,7 +1746,7 @@ void Window::queue_resize()
while( pWindow )
{
- if (pWindow->GetType() == WINDOW_CONTAINER)
+ if (isContainerWindow(*pWindow))
{
VclContainer *pContainer = static_cast<VclContainer*>(pWindow);
pContainer->markLayoutDirty();