linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #03788
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2476: better range checking of splitter pos; fix tab settings preview
------------------------------------------------------------
revno: 2476
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2011-03-30 22:13:51 +0200
message:
better range checking of splitter pos; fix tab settings preview
modified:
dcpp/noexcept.h
dwt/include/dwt/widgets/Splitter.h
dwt/include/dwt/widgets/SplitterContainer.h
dwt/include/dwt/widgets/TabView.h
dwt/src/widgets/Splitter.cpp
dwt/src/widgets/SplitterContainer.cpp
dwt/src/widgets/TabView.cpp
win32/TabsPage.cpp
win32/TabsPage.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/noexcept.h'
--- dcpp/noexcept.h 2011-03-29 20:40:28 +0000
+++ dcpp/noexcept.h 2011-03-30 20:13:51 +0000
@@ -19,7 +19,7 @@
#ifndef DCPLUSPLUS_DCPP_NOEXCEPT_H
#define DCPLUSPLUS_DCPP_NOEXCEPT_H
-// for compilers that don't support noexcept, use a noexcept specifier
+// for compilers that don't support noexcept, use an exception specifier
#ifdef __GNUC__
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6) // GCC 4.6 is the first GCC to implement noexcept.
@@ -32,7 +32,7 @@
#elif defined(_MSC_VER)
#ifndef noexcept
-#define noexcept FIX_ME_BECAUSE_I_DON_T_KNOW
+#define noexcept throw()
#endif
#endif
=== modified file 'dwt/include/dwt/widgets/Splitter.h'
--- dwt/include/dwt/widgets/Splitter.h 2011-03-29 18:19:38 +0000
+++ dwt/include/dwt/widgets/Splitter.h 2011-03-30 20:13:51 +0000
@@ -32,6 +32,7 @@
#ifndef DWT_SPLITTER_H
#define DWT_SPLITTER_H
+#include <dwt/forward.h>
#include "Control.h"
#include <dwt/Theme.h>
@@ -43,6 +44,7 @@
typedef Control BaseType;
friend class WidgetCreator<Splitter>;
+ friend class SplitterContainer;
public:
/// Class type
@@ -74,8 +76,7 @@
void create(const Seed& cs = Seed());
- typedef std::function<void(double)> OnMoveFunction;
- void onMove(OnMoveFunction func);
+ SplitterContainerPtr getParent() const;
virtual Point getPreferredSize() { return horizontal ? Point(0, thickness()) : Point(thickness(), 0); }
@@ -93,8 +94,6 @@
bool moving;
bool horizontal;
- OnMoveFunction onMoveFunc;
-
void handlePainting(PaintCanvas& canvas);
bool handleLButtonDown() {
@@ -128,10 +127,6 @@
{
}
-inline void Splitter::onMove(OnMoveFunction onMove) {
- onMoveFunc = onMove;
-}
-
}
#endif
=== modified file 'dwt/include/dwt/widgets/SplitterContainer.h'
--- dwt/include/dwt/widgets/SplitterContainer.h 2011-03-15 19:52:17 +0000
+++ dwt/include/dwt/widgets/SplitterContainer.h 2011-03-30 20:13:51 +0000
@@ -32,6 +32,7 @@
#ifndef DWT_SPLITTERCONTAINER_H_
#define DWT_SPLITTERCONTAINER_H_
+#include <dwt/forward.h>
#include "Container.h"
namespace dwt {
@@ -40,6 +41,10 @@
public Container
{
typedef Container BaseType;
+
+ friend class WidgetCreator<SplitterContainer>;
+ friend class Splitter;
+
public:
/// Class type
typedef SplitterContainer ThisType;
@@ -63,14 +68,13 @@
virtual void layout();
private:
-protected:
- friend class WidgetCreator<SplitterContainer>;
-
explicit SplitterContainer( Widget * parent ) : BaseType(parent), horizontal(false), startPos(0.5) { }
size_t ensureSplitters();
- void onMove(SplitterPtr splitter, double newPos);
+ double getMaxSize(SplitterPtr splitter);
+
+ void onMove();
bool horizontal;
double startPos;
=== modified file 'dwt/include/dwt/widgets/TabView.h'
--- dwt/include/dwt/widgets/TabView.h 2011-01-02 17:12:02 +0000
+++ dwt/include/dwt/widgets/TabView.h 2011-03-30 20:13:51 +0000
@@ -51,7 +51,7 @@
class TabView :
public CommonControl,
// Aspects
- private AspectCollection<TabView, int>,
+ public AspectCollection<TabView, int>,
public AspectSelection< TabView, int >,
public AspectText< TabView >,
public Taskbar
=== modified file 'dwt/src/widgets/Splitter.cpp'
--- dwt/src/widgets/Splitter.cpp 2011-03-29 18:19:38 +0000
+++ dwt/src/widgets/Splitter.cpp 2011-03-30 20:13:51 +0000
@@ -35,6 +35,7 @@
#include <dwt/Texts.h>
#include <dwt/WidgetCreator.h>
#include <dwt/resources/Brush.h>
+#include <dwt/widgets/SplitterContainer.h>
#include <dwt/widgets/ToolTip.h>
namespace dwt {
@@ -53,6 +54,10 @@
WidgetCreator<ToolTip>::create(this, ToolTip::Seed())->setText(Texts::get(Texts::resize));
}
+
+SplitterContainerPtr Splitter::getParent() const {
+ return static_cast<SplitterContainerPtr>(BaseType::getParent());
+}
void Splitter::handlePainting(PaintCanvas& canvas) {
if(theme) {
@@ -84,11 +89,10 @@
});
}
- if(moving && mouseEvent.ButtonPressed == MouseEvent::LEFT && onMoveFunc) {
+ if(moving && mouseEvent.ButtonPressed == MouseEvent::LEFT) {
ClientCoordinate cc(mouseEvent.pos, getParent());
- double pos = horizontal ? cc.y() : cc.x();
- double size = horizontal ? getParent()->getClientSize().y : getParent()->getClientSize().x;
- onMoveFunc(pos / size);
+ pos = (horizontal ? cc.y() : cc.x()) / getParent()->getMaxSize(this);
+ getParent()->onMove();
}
return true;
=== modified file 'dwt/src/widgets/SplitterContainer.cpp'
--- dwt/src/widgets/SplitterContainer.cpp 2011-03-23 20:26:21 +0000
+++ dwt/src/widgets/SplitterContainer.cpp 2011-03-30 20:13:51 +0000
@@ -30,11 +30,13 @@
*/
#include <dwt/widgets/SplitterContainer.h>
+
#include <dwt/widgets/Splitter.h>
#include <dwt/util/HoldResize.h>
#include <boost/next_prior.hpp>
#include <boost/range/distance.hpp>
+#include <boost/range/algorithm/find.hpp>
#include <boost/range/algorithm/for_each.hpp>
namespace dwt {
@@ -44,6 +46,7 @@
bool isNotSplitter(Widget *w) { return !isSplitter(w); }
}
+using boost::find;
using boost::for_each;
using boost::next;
@@ -135,18 +138,35 @@
for_each(children, [&](Widget *w) { isSplitter(w) ? ns++ : nc++; });
while(ns < nc - 1) {
- auto splitter = addChild(Splitter::Seed(startPos, horizontal));
- splitter->onMove([=] (double pos) { onMove(splitter, pos); });
+ addChild(Splitter::Seed(startPos, horizontal));
ns++;
}
return ns;
}
-void SplitterContainer::onMove(SplitterPtr splitter, double pos)
-{
- // TODO Check that one splitter does not move past another
- splitter->setRelativePos(pos);
+double SplitterContainer::getMaxSize(SplitterPtr splitter) {
+ double ret = splitter->thickness();
+
+ auto children = getChildren<Widget>();
+ auto splitters = getChildren<Splitter>();
+
+ splitters.second = find(splitters, splitter);
+ auto n = boost::distance(splitters);
+
+ bool horizontal = splitter->horizontal;
+ auto pos = 0;
+ for_each(children, [&](Widget* w) {
+ if((pos == n || pos == n + 1) && w) {
+ ret += horizontal ? w->getClientSize().y : w->getClientSize().x;
+ }
+ ++pos;
+ });
+
+ return ret;
+}
+
+void SplitterContainer::onMove() {
layout();
redraw(true);
}
=== modified file 'dwt/src/widgets/TabView.cpp'
--- dwt/src/widgets/TabView.cpp 2011-03-15 19:52:17 +0000
+++ dwt/src/widgets/TabView.cpp 2011-03-30 20:13:51 +0000
@@ -48,7 +48,7 @@
const TCHAR TabView::windowClass[] = WC_TABCONTROL;
TabView::Seed::Seed(unsigned widthConfig_, bool toggleActive_, bool ctrlTab_) :
-BaseType::Seed(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |
+BaseType::Seed(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
TCS_FOCUSNEVER | TCS_HOTTRACK | TCS_MULTILINE | TCS_OWNERDRAWFIXED | TCS_RAGGEDRIGHT | TCS_TOOLTIPS),
tabStyle(WinDefault),
font(new Font(DefaultGuiFont)),
=== modified file 'win32/TabsPage.cpp'
--- win32/TabsPage.cpp 2011-03-15 19:52:17 +0000
+++ win32/TabsPage.cpp 2011-03-30 20:13:51 +0000
@@ -49,7 +49,7 @@
themeGroup(0),
browserTheme(0),
tabWidth(0),
-previewGroup(0),
+previewGrid(0),
options(0)
{
setHelpId(IDH_TABSPAGE);
@@ -125,9 +125,18 @@
tabWidth->onScrollHorz(std::bind(&TabsPage::createPreview, this));
}
- previewGroup = grid->addChild(GroupBox::Seed(T_("Preview")));
- previewGroup->setHelpId(IDH_SETTINGS_TAB_PREVIEW);
- createPreview();
+ {
+ GroupBoxPtr group = grid->addChild(GroupBox::Seed(T_("Preview")));
+ group->setHelpId(IDH_SETTINGS_TAB_PREVIEW);
+
+ previewGrid = group->addChild(Grid::Seed(1, 1));
+ previewGrid->column(0).mode = GridInfo::FILL;
+ previewGrid->row(0).size = 100;
+ previewGrid->row(0).mode = GridInfo::STATIC;
+ previewGrid->row(0).align = GridInfo::STRETCH;
+
+ createPreview();
+ }
options = grid->addChild(GroupBox::Seed(T_("Tab highlight on content change")))->addChild(WinUtil::Seeds::Dialog::optionsTable);
@@ -153,13 +162,12 @@
}
void TabsPage::createPreview() {
- GridPtr cur = previewGroup->addChild(Grid::Seed(1, 1));
- cur->column(0).mode = GridInfo::FILL;
- cur->row(0).size = 100;
- cur->row(0).mode = GridInfo::STATIC;
- cur->row(0).align = GridInfo::STRETCH;
+ auto previous = *previewGrid->getChildren<TabView>().first;
+ if(previous)
+ previous->close();
TabView::Seed seed = WinUtil::Seeds::tabs;
+ seed.style &= ~TCS_TOOLTIPS;
seed.widthConfig = tabWidth->getPosition();
seed.style |= WS_DISABLED;
if(dcppDraw->getChecked()) {
@@ -172,10 +180,10 @@
if(buttonStyle->getChecked())
seed.style |= TCS_BUTTONS;
seed.closeIcon = WinUtil::tabIcon(IDI_EXIT);
- TabViewPtr tabs = cur->addChild(seed);
+ TabViewPtr tabs = previewGrid->addChild(seed);
- auto makeTab = [&tabs](const tstring& text) -> ContainerPtr {
- Container::Seed cs;
+ Container::Seed cs;
+ auto makeTab = [&tabs, &cs](const tstring& text) -> ContainerPtr {
cs.caption = text;
ContainerPtr ret = dwt::WidgetCreator<Container>::create(tabs, cs);
// the tab control sends WM_ACTIVATE messages; catch them, otherwise the dialog gets messed up.
@@ -192,8 +200,5 @@
tabs->setSelected(1);
tabs->mark(highlighted);
- // refresh
- dwt::Rectangle rect = previewGroup->getWindowRect();
- rect.pos -= grid->getWindowRect().pos; // screen->client coords
- previewGroup->resize(rect);
+ previewGrid->layout();
}
=== modified file 'win32/TabsPage.h'
--- win32/TabsPage.h 2011-03-16 18:35:03 +0000
+++ win32/TabsPage.h 2011-03-30 20:13:51 +0000
@@ -35,7 +35,7 @@
GroupBoxPtr themeGroup;
RadioButtonPtr browserTheme;
SliderPtr tabWidth;
- GroupBoxPtr previewGroup;
+ GridPtr previewGrid;
static ListItem listItems[];
TablePtr options;