CtrlLib: EditWithSpin option to disable mouse wheel action, Core: String::Find fix

git-svn-id: svn://ultimatepp.org/upp/trunk@15934 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2021-04-22 16:50:11 +00:00
parent d7a19f05e6
commit 7cd753b5ae
3 changed files with 55 additions and 20 deletions

View file

@ -41,7 +41,7 @@ int t_find(const char *ptr, int slen, const char *p, int len, int from)
int32 p0 = Peek32le(p); int32 p0 = Peek32le(p);
int32 p1 = Peek32le(p + len); int32 p1 = Peek32le(p + len);
while(s <= e) { while(s <= e) {
if(Peek32le(s) == p0 && Peek32le(s + len) == p1) if((int32)Peek32le(s) == p0 && (int32)Peek32le(s + len) == p1)
return (int)(s - ptr); return (int)(s - ptr);
s += step; s += step;
} }
@ -50,7 +50,7 @@ int t_find(const char *ptr, int slen, const char *p, int len, int from)
if(len == 4) { if(len == 4) {
int32 p0 = Peek32le(p); int32 p0 = Peek32le(p);
while(s <= e) { while(s <= e) {
if(Peek32le(s) == p0) if((int32)Peek32le(s) == p0)
return (int)(s - ptr); return (int)(s - ptr);
s += step; s += step;
} }
@ -60,7 +60,7 @@ int t_find(const char *ptr, int slen, const char *p, int len, int from)
int16 p0 = Peek16le(p); int16 p0 = Peek16le(p);
char p1 = p[2]; char p1 = p[2];
while(s <= e) { while(s <= e) {
if(Peek16le(s) == p0 && s[2] == p1) if((int16)Peek16le(s) == p0 && s[2] == p1)
return (int)(s - ptr); return (int)(s - ptr);
s += step; s += step;
} }
@ -69,7 +69,7 @@ int t_find(const char *ptr, int slen, const char *p, int len, int from)
if(len == 2) { if(len == 2) {
int16 p0 = Peek16le(p); int16 p0 = Peek16le(p);
while(s <= e) { while(s <= e) {
if(Peek16le(s) == p0) if((int16)Peek16le(s) == p0)
return (int)(s - ptr); return (int)(s - ptr);
s += step; s += step;
} }
@ -93,21 +93,21 @@ int t_find(const char *ptr, int slen, const char *p, int len, int from)
len -= 8; len -= 8;
int64 p1 = Peek64le(p + len); int64 p1 = Peek64le(p + len);
while(s <= e) { while(s <= e) {
if(Peek64le(s) == p0 && Peek64le(s + len) == p1) if((int64)Peek64le(s) == p0 && (int64)Peek64le(s + len) == p1)
return (int)(s - ptr); return (int)(s - ptr);
s += step; s += step;
} }
} }
else else
while(s <= e) { while(s <= e) {
if(Peek64le(s) == p0 && equal_back_8(s, p, len)) if((int64)Peek64le(s) == p0 && equal_back_8(s, p, len))
return (int)(s - ptr); return (int)(s - ptr);
s += step; s += step;
} }
#else #else
int32 p0 = Peek32le(p); int32 p0 = Peek32le(p);
while(s <= e) { while(s <= e) {
if(Peek32le(s) == p0 && equal_back_4(s, p, len)) if((int32)Peek32le(s) == p0 && equal_back_4(s, p, len))
return (int)(s - ptr); return (int)(s - ptr);
s += step; s += step;
} }

View file

@ -381,6 +381,8 @@ private:
SpinButtons sb; SpinButtons sb;
IncType inc; IncType inc;
bool roundfrommin; bool roundfrommin;
bool mousewheel = true;
bool keys = true;
typedef WithSpin CLASSNAME; typedef WithSpin CLASSNAME;
public: public:
@ -396,6 +398,12 @@ public:
WithSpin& RoundFromMin(bool b = true) { roundfrommin = b; return *this; } WithSpin& RoundFromMin(bool b = true) { roundfrommin = b; return *this; }
WithSpin& MouseWheelSpin(bool b = true){ mousewheel = b; return *this; }
WithSpin& NoMouseWheelSpin() { return MouseWheelSpin(false); }
WithSpin& KeySpin(bool b = true) { keys = b; return *this; }
WithSpin& NoKeySpin() { return KeySpin(false); }
SpinButtons& SpinButtonsObject() { return sb; } SpinButtons& SpinButtonsObject() { return sb; }
const SpinButtons& SpinButtonsObject() const { return sb; } const SpinButtons& SpinButtonsObject() const { return sb; }
@ -489,6 +497,7 @@ void WithSpin<DataType, Base, IncType>::Dec()
template <class DataType, class Base, class IncType> template <class DataType, class Base, class IncType>
bool WithSpin<DataType, Base, IncType>::Key(dword key, int repcnt) bool WithSpin<DataType, Base, IncType>::Key(dword key, int repcnt)
{ {
if(keys) {
if(key == K_UP) { if(key == K_UP) {
Inc(); Inc();
return true; return true;
@ -497,16 +506,19 @@ bool WithSpin<DataType, Base, IncType>::Key(dword key, int repcnt)
Dec(); Dec();
return true; return true;
} }
}
return Base::Key(key, repcnt); return Base::Key(key, repcnt);
} }
template <class DataType, class Base, class IncType> template <class DataType, class Base, class IncType>
void WithSpin<DataType, Base, IncType>::MouseWheel(Point, int zdelta, dword) void WithSpin<DataType, Base, IncType>::MouseWheel(Point, int zdelta, dword)
{ {
if(mousewheel) {
if(zdelta < 0) if(zdelta < 0)
Dec(); Dec();
else else
Inc(); Inc();
}
} }
typedef WithSpin<int, EditInt> EditIntSpin; typedef WithSpin<int, EditInt> EditIntSpin;

View file

@ -1,5 +1,4 @@
topic "WithSpin template and Value editors with spin buttons"; topic "WithSpin template and Value editors with spin buttons";
[2 $$0,0#00000000000000000000000000000000:Default]
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
[l288;2 $$2,2#27521748481378242620020725143825:desc] [l288;2 $$2,2#27521748481378242620020725143825:desc]
[0 $$3,0#96390100711032703541132217272105:end] [0 $$3,0#96390100711032703541132217272105:end]
@ -9,6 +8,7 @@ topic "WithSpin template and Value editors with spin buttons";
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
[b42;2 $$9,9#13035079074754324216151401829390:normal] [b42;2 $$9,9#13035079074754324216151401829390:normal]
[2 $$0,0#00000000000000000000000000000000:Default]
[{_}%EN-US [{_}%EN-US
[ {{10000@(113.42.0) [s0; [*@7;4 WithSpin]]}}&] [ {{10000@(113.42.0) [s0; [*@7;4 WithSpin]]}}&]
[s3;%- &] [s3;%- &]
@ -61,7 +61,7 @@ ool]_[*@3 s]_`=_[@(0.0.255) true])&]
[s4; &] [s4; &]
[s5;:WithSpin`:`:IsSpinVisible`(`)const:%- [@(0.0.255) bool]_[* IsSpinVisible]()_[@(0.0.255) c [s5;:WithSpin`:`:IsSpinVisible`(`)const:%- [@(0.0.255) bool]_[* IsSpinVisible]()_[@(0.0.255) c
onst]&] onst]&]
[s2; Returns true if spin buttes are shown.&] [s2; Returns true if spin buttons are shown.&]
[s3; &] [s3; &]
[s4;%- &] [s4;%- &]
[s5;:Upp`:`:WithSpin`:`:RoundFromMin`(bool`):%- [_^Upp`:`:WithSpin^ WithSpin][@(0.0.255) `& [s5;:Upp`:`:WithSpin`:`:RoundFromMin`(bool`):%- [_^Upp`:`:WithSpin^ WithSpin][@(0.0.255) `&
@ -72,6 +72,29 @@ value is 3, going up from the minimum goes through values 3,
5, 10, ..., which when RoundFromMin is active, it goes through 5, 10, ..., which when RoundFromMin is active, it goes through
3, 8, 13, ...&] 3, 8, 13, ...&]
[s3; &] [s3; &]
[s4;%- &]
[s5;:Upp`:`:WithSpin`:`:MouseWheelSpin`(bool`):%- [_^Upp`:`:WithSpin^ WithSpin][@(0.0.255) `&
]_[* MouseWheelSpin]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; If active, the value can be altered by mouse wheel `- rolling
the wheel is equivalent to pushing up/down arrows. Default is
active.&]
[s3; &]
[s4;%- &]
[s5;:Upp`:`:WithSpin`:`:NoMouseWheelSpin`(`):%- [_^Upp`:`:WithSpin^ WithSpin][@(0.0.255) `&
]_[* NoMouseWheelSpin]()&]
[s2; Same as MouseWheelSpin(false).&]
[s3;%- &]
[s4;%- &]
[s5;:Upp`:`:WithSpin`:`:KeySpin`(bool`):%- [_^Upp`:`:WithSpin^ WithSpin][@(0.0.255) `&]_[* K
eySpin]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&]
[s2; If active, the value can be altered with Up and Down keys. Default
is active.&]
[s3; &]
[s4;%- &]
[s5;:Upp`:`:WithSpin`:`:NoKeySpin`(`):%- [_^Upp`:`:WithSpin^ WithSpin][@(0.0.255) `&]_[* No
KeySpin]()&]
[s2; Same as KeySpin(false).&]
[s3;%- &]
[s4; &] [s4; &]
[s5;:WithSpin`:`:SpinButtonsObject`(`):%- [_^SpinButtons^ SpinButtons][@(0.0.255) `&]_[* Sp [s5;:WithSpin`:`:SpinButtonsObject`(`):%- [_^SpinButtons^ SpinButtons][@(0.0.255) `&]_[* Sp
inButtonsObject]()&] inButtonsObject]()&]