[Libreoffice-commits] core.git: include/svx svx/Library_svxcore.mk svx/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Tue Aug 29 10:15:54 UTC 2017
include/svx/listctrl.hxx | 57 ++++++++++++++++
svx/Library_svxcore.mk | 1
svx/source/dialog/listctrl.cxx | 145 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 203 insertions(+)
New commits:
commit 218ca21147c0a8c7da4691ed63915499cfc1c80e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Aug 28 18:19:13 2017 +0200
add a listbox that can contain any controls as children
This is adapted from the code that I originally wrote for the
conditional format dialogs.
Change-Id: I3349b7c720d99ede595cc6ebea2046e0f9dadc57
Reviewed-on: https://gerrit.libreoffice.org/41653
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/include/svx/listctrl.hxx b/include/svx/listctrl.hxx
new file mode 100644
index 000000000000..6f303aa7dec9
--- /dev/null
+++ b/include/svx/listctrl.hxx
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SVX_LISTCTRL_HXX
+#define INCLUDED_SVX_LISTCTRL_HXX
+
+#include <vcl/ctrl.hxx>
+#include <vcl/scrbar.hxx>
+
+#include <vector>
+
+#include <svx/svxdllapi.h>
+
+class SVX_DLLPUBLIC ListControl : public Control
+{
+private:
+ std::vector<VclPtr<Control>> maEntries;
+ bool mbHasScrollBar;
+ VclPtr<ScrollBar> mpScrollBar;
+
+ void DoScroll(long nDiff);
+ void RecalcAll();
+public:
+
+ ListControl(vcl::Window* pParent, WinBits nStyle);
+ virtual ~ListControl() override;
+ virtual void dispose() override;
+
+ void addEntry(VclPtr<Control> xEntry, sal_uInt32 nPos = 0);
+ void deleteEntry(sal_uInt32 nPos);
+
+ virtual Size GetOptimalSize() const override;
+ virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;
+ virtual void Resize() override;
+
+ DECL_LINK( ScrollHdl, ScrollBar*, void );
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 5bfbf899034d..ffb8321cfbe5 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -117,6 +117,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/dialog/hexcolorcontrol \
svx/source/dialog/framelink \
svx/source/dialog/langbox \
+ svx/source/dialog/listctrl \
svx/source/dialog/pagenumberlistbox \
svx/source/dialog/papersizelistbox \
svx/source/dialog/samecontentlistbox \
diff --git a/svx/source/dialog/listctrl.cxx b/svx/source/dialog/listctrl.cxx
new file mode 100644
index 000000000000..29a8b14410d3
--- /dev/null
+++ b/svx/source/dialog/listctrl.cxx
@@ -0,0 +1,145 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <svx/listctrl.hxx>
+
+ListControl::ListControl(vcl::Window* pParent, WinBits nBits):
+ Control(pParent, nBits),
+ mbHasScrollBar(false),
+ mpScrollBar(VclPtr<ScrollBar>::Create(this, WB_VERT))
+{
+ mpScrollBar->SetScrollHdl( LINK( this, ListControl, ScrollHdl ) );
+ mpScrollBar->EnableDrag();
+}
+
+ListControl::~ListControl()
+{
+ disposeOnce();
+}
+
+void ListControl::dispose()
+{
+ mpScrollBar.disposeAndClear();
+ for (auto& aEntry : maEntries)
+ aEntry.disposeAndClear();
+ maEntries.clear();
+
+ Control::dispose();
+}
+
+void ListControl::RecalcAll()
+{
+ sal_Int32 nTotalHeight = 0;
+ for (const auto& item : maEntries)
+ {
+ if (!item)
+ continue;
+ nTotalHeight += item->GetSizePixel().Height();
+ }
+
+ Size aCtrlSize = GetOutputSize();
+ long nSrcBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
+ if(nTotalHeight > GetSizePixel().Height())
+ {
+ mbHasScrollBar = true;
+ mpScrollBar->SetPosSizePixel(Point(aCtrlSize.Width() -nSrcBarSize, 0),
+ Size(nSrcBarSize, aCtrlSize.Height()) );
+ mpScrollBar->SetRangeMax(nTotalHeight);
+ mpScrollBar->SetVisibleSize(aCtrlSize.Height());
+ mpScrollBar->Show();
+ }
+ else
+ {
+ mbHasScrollBar = false;
+ mpScrollBar->Hide();
+ }
+
+ Point aPoint(0,-1*mpScrollBar->GetThumbPos());
+ for (const auto& item : maEntries)
+ {
+ if (!item)
+ continue;
+ item->SetPosPixel(aPoint);
+ Size aSize = item->GetSizePixel();
+ if(mbHasScrollBar)
+ aSize.Width() = aCtrlSize.Width() - nSrcBarSize;
+ else
+ aSize.Width() = aCtrlSize.Width();
+ item->SetSizePixel(aSize);
+
+ aPoint.Y() += item->GetSizePixel().Height();
+ }
+}
+
+Size ListControl::GetOptimalSize() const
+{
+ return LogicToPixel(Size(300, 185), MapUnit::MapAppFont);
+}
+
+void ListControl::Resize()
+{
+ Control::Resize();
+ RecalcAll();
+}
+
+void ListControl::queue_resize(StateChangedType eReason)
+{
+ Control::queue_resize(eReason);
+ RecalcAll();
+}
+
+void ListControl::DoScroll(long nDelta)
+{
+ Point aNewPoint = mpScrollBar->GetPosPixel();
+ tools::Rectangle aRect(Point(), GetOutputSize());
+ aRect.Right() -= mpScrollBar->GetSizePixel().Width();
+ Scroll( 0, -nDelta, aRect );
+ mpScrollBar->SetPosPixel(aNewPoint);
+}
+
+IMPL_LINK_NOARG( ListControl, ScrollHdl, ScrollBar*, void )
+{
+ DoScroll(mpScrollBar->GetDelta());
+}
+
+void ListControl::addEntry(VclPtr<Control> xEntry, sal_uInt32 nPos)
+{
+ xEntry->Show();
+ if (nPos < maEntries.size())
+ {
+ maEntries.insert(maEntries.begin() + nPos, xEntry);
+ }
+ else
+ {
+ maEntries.push_back(xEntry);
+ }
+ RecalcAll();
+}
+
+void ListControl::deleteEntry(sal_uInt32 nPos)
+{
+ if (nPos >= maEntries.size())
+ return;
+
+ maEntries[nPos].disposeAndClear();
+ maEntries.erase(maEntries.begin() + nPos);
+ RecalcAll();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list