CtrlLib: WithDropChoice now reacts to mouse wheel

git-svn-id: svn://ultimatepp.org/upp/trunk@6388 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-10-03 07:56:21 +00:00
parent 97d19762d2
commit 685361024a
3 changed files with 36 additions and 0 deletions

View file

@ -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();

View file

@ -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<T>::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<T>::Key(dword key, int repcnt) {
return select.DoKey(key) || T::Key(key, repcnt);
}
template <class T>
void WithDropChoice<T>::MouseWheel(Point p, int zdelta, dword keyflags)
{
if(withwheel)
select.DoWheel(zdelta);
}
template <class T>
void WithDropChoice<T>::MouseEnter(Point p, dword keyflags)
{

View file

@ -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].&]