From 685361024a98aaa8ff64f266edab6deea3418b8d Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 3 Oct 2013 07:56:21 +0000 Subject: [PATCH] CtrlLib: WithDropChoice now reacts to mouse wheel git-svn-id: svn://ultimatepp.org/upp/trunk@6388 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/DropChoice.cpp | 7 +++++++ uppsrc/CtrlLib/DropChoice.h | 13 +++++++++++++ uppsrc/CtrlLib/src.tpp/WithDropChoice$en-us.tpp | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/uppsrc/CtrlLib/DropChoice.cpp b/uppsrc/CtrlLib/DropChoice.cpp index 9618ab9a7..f9311d2df 100644 --- a/uppsrc/CtrlLib/DropChoice.cpp +++ b/uppsrc/CtrlLib/DropChoice.cpp @@ -11,6 +11,7 @@ DropChoice::DropChoice() { dropfocus = true; EnableDrop(false); dropwidth = 0; + appending = false; } void DropChoice::EnableDrop(bool b) @@ -68,6 +69,12 @@ bool DropChoice::DataSelect(Ctrl& owner, DropChoice& drop, const String& appends return true; } +void DropChoice::DoWheel(int zdelta) +{ + if(!appending) + DoKey(zdelta < 0 ? K_UP : K_DOWN); +} + bool DropChoice::DoKey(dword key) { if(owner && !owner->IsReadOnly() && list.GetCount()) { int q = list.GetCursor(); diff --git a/uppsrc/CtrlLib/DropChoice.h b/uppsrc/CtrlLib/DropChoice.h index e60ee0357..1d5998f27 100644 --- a/uppsrc/CtrlLib/DropChoice.h +++ b/uppsrc/CtrlLib/DropChoice.h @@ -171,6 +171,7 @@ public: Callback WhenSelect; bool DoKey(dword key); + void DoWheel(int zdelta); void Clear(); void Add(const Value& data); @@ -214,6 +215,7 @@ public: virtual bool Key(dword key, int repcnt); virtual void MouseEnter(Point p, dword keyflags); virtual void MouseLeave(); + virtual void MouseWheel(Point p, int zdelta, dword keyflags); virtual void GotFocus(); virtual void LostFocus(); @@ -221,6 +223,7 @@ public: protected: DropChoice select; String appends; + bool withwheel; void DoWhenSelect(); void DoWhenDrop() { WhenDrop(); } @@ -257,6 +260,8 @@ public: WithDropChoice& SetDisplay(const Display& d, int lcy) { select.SetDisplay(d, lcy); return *this; } WithDropChoice& SetConvert(const Convert& d) { select.SetConvert(d); return *this; } WithDropChoice& AlwaysDrop(bool b = true) { select.AlwaysDrop(b); return *this; } + WithDropChoice& WithWheel(bool b = true) { withwheel = b; return *this; } + WithDropChoice& NoWithWheel() { return WithWheel(false); } WithDropChoice& DropWidth(int w) { select.DropWidth(w); return *this; } WithDropChoice& DropWidthZ(int w) { select.DropWidthZ(w); return *this; } @@ -270,6 +275,7 @@ WithDropChoice::WithDropChoice() { select.WhenDrop = callback(this, &WithDropChoice::DoWhenDrop); select.WhenSelect = callback(this, &WithDropChoice::DoWhenSelect); appends = String::GetVoid(); + withwheel = true; SetStyle(StyleDefault()); } @@ -278,6 +284,13 @@ bool WithDropChoice::Key(dword key, int repcnt) { return select.DoKey(key) || T::Key(key, repcnt); } +template +void WithDropChoice::MouseWheel(Point p, int zdelta, dword keyflags) +{ + if(withwheel) + select.DoWheel(zdelta); +} + template void WithDropChoice::MouseEnter(Point p, dword keyflags) { diff --git a/uppsrc/CtrlLib/src.tpp/WithDropChoice$en-us.tpp b/uppsrc/CtrlLib/src.tpp/WithDropChoice$en-us.tpp index bd67df464..2383a7e79 100644 --- a/uppsrc/CtrlLib/src.tpp/WithDropChoice$en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/WithDropChoice$en-us.tpp @@ -125,12 +125,28 @@ hoice][@(0.0.255) `&]_[* SetDisplay]([@(0.0.255) const]_[_^Display^ Display][@(0 [s2;%% Same as SetDisplay(d).SetLineCy(lcy).&] [s3;%% &] [s4; &] +[s5;:WithDropChoice`:`:SetConvert`(const Convert`&`): [_^WithDropChoice^ WithDropChoice +][@(0.0.255) `&]_[* SetConvert]([@(0.0.255) const]_[_^Convert^ Convert][@(0.0.255) `&]_[*@3 d +])&] +[s2;%% Sets the Convert to be used with drop`-down list item [%-*@3 i].&] +[s3;%% &] +[s4; &] [s5;:WithDropChoice`:`:AlwaysDrop`(bool`): [_^WithDropChoice^ WithDropChoice][@(0.0.255) `& ]_[* AlwaysDrop]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&] [s2;%% If active, drop button is visible even if the list is empty (client code can fill it using WhenDrop callback).&] [s3; &] [s4; &] +[s5;:WithDropChoice`:`:WithWheel`(bool`): [_^WithDropChoice^ WithDropChoice][@(0.0.255) `& +]_[* WithWheel]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&] +[s2;%% Widget reacts to mousewheel. This is active by default.&] +[s3;%% &] +[s4; &] +[s5;:WithDropChoice`:`:NoWithWheel`(`): [_^WithDropChoice^ WithDropChoice][@(0.0.255) `&]_ +[* NoWithWheel]()&] +[s2;%% Same as WithWheel(false).&] +[s3; &] +[s4; &] [s5;:WithDropChoice`:`:DropWidth`(int`): [_^WithDropChoice^ WithDropChoice][@(0.0.255) `& ]_[* DropWidth]([@(0.0.255) int]_[*@3 w])&] [s2;%% Set the width of the drop down list to [%-*@3 w].&]