From 7c44f7b46bc85c08316673ce33287cdb7928fd1f Mon Sep 17 00:00:00 2001 From: chenwei <18149785619@qq.com> Date: Tue, 16 Jul 2019 20:48:17 +0800 Subject: [PATCH 1/2] change for Keil cpp11 compiler --- src/items.cpp | 12 ++++++++---- src/menuBase.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/items.cpp b/src/items.cpp index 4abb48e4..22a6f3e9 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -154,7 +154,8 @@ void textField::doNav(navNode& nav,navCmd cmd) { case upCmd: if (charEdit) { const char* v=validator(cursor); - char *at=strchr(v,buffer()[cursor]); + //wei, only for keil cpp11 + char *at=(char *)strchr(v,buffer()[cursor]); idx_t pos=at?at-v+1:1; if (pos>=(idx_t)strlen(v)) pos=0; buffer()[cursor]=v[pos]; @@ -169,7 +170,8 @@ void textField::doNav(navNode& nav,navCmd cmd) { case downCmd: if (charEdit) { const char* v=validator(cursor); - char *at=strchr(v,buffer()[cursor]);//at is not stored on the class to save memory + //wei, only for keil cpp11 + char *at=(char *)strchr(v,buffer()[cursor]);//at is not stored on the class to save memory idx_t pos=at?at-v-1:0; if (pos<0) pos=strlen(v)-1; buffer()[cursor]=v[pos]; @@ -307,7 +309,8 @@ void textField::parseInput(navNode& nav,menuIn& in) { return; default: { const char* v=validator(cursor); - char *at=strchr(v,c); + //wei, only for keil cpp11 + char *at=(char *)strchr(v,c); if (at) { in.read(); buffer()[cursor]=c; @@ -460,7 +463,8 @@ idx_t menuVariantBase::togglePrintTo(navRoot &root,bool sel,menuOut& out, idx_t l+=operator[](at).printRaw(out,len-l); #ifdef MENU_FMT_WRAPS out.fmtEnd(*this,menuOut::fmtToggle,root.node(),idx); - #endif- + //wei, only for keil cpp11 + #endif } return l; } diff --git a/src/menuBase.cpp b/src/menuBase.cpp index 5437fdf1..6cf4e8fc 100644 --- a/src/menuBase.cpp +++ b/src/menuBase.cpp @@ -14,7 +14,7 @@ using namespace Menu; #endif #endif -template result Menu::callCaster(eventMask event, navNode& nav, prompt &item, menuIn &in) {A(event,nav,item,in);return proceed;} +//template result Menu::callCaster(eventMask event, navNode& nav, prompt &item, menuIn &in) {A(event,nav,item,in);return proceed;} template result Menu::callCaster(eventMask event, navNode& nav, prompt &item) {A(event,nav,item);return proceed;} template result Menu::callCaster(eventMask event, navNode& nav) {A(event,nav);return proceed;} template result Menu::callCaster(eventMask event) {A(event);return proceed;} From f65bb4f0f2cf94e679d2e957ccced2e5adddd9b7 Mon Sep 17 00:00:00 2001 From: chenwei <18149785619@qq.com> Date: Tue, 16 Jul 2019 22:27:38 +0800 Subject: [PATCH 2/2] support multi-lang in menuNode string --- src/items.cpp | 15 +++++++++++ src/items.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/shadows.h | 34 +++++++++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/src/items.cpp b/src/items.cpp index 22a6f3e9..20036552 100644 --- a/src/items.cpp +++ b/src/items.cpp @@ -541,6 +541,21 @@ bool menuNode::_changes(const navNode &nav,const menuOut& out,bool sub,bool test } else return false; } +/* change language string in menuNode and its childen */ +void menuNode::chLang(idx_t lang) { + prompt::chLang(lang); // for this node itself + for(int i=0;ichLang(lang); + } + else + { + operator[](i).chLang(lang); + } + + } +} + #ifdef MENU_ASYNC const char* menu::typeName() const {return "menu";} #endif diff --git a/src/items.h b/src/items.h index 71fe4167..8f8447fe 100644 --- a/src/items.h +++ b/src/items.h @@ -44,6 +44,9 @@ inline prompt(constMEM promptShadow& shadow):shadow(&shadow) {} inline prompt(constText* t,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=_noStyle) :shadow(new promptShadow(t,a,e,s,ss)) {} + inline prompt(constText** pt,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=_noStyle,idx_t lang=0) + :shadow(new promptShadow(pt,a,e,s,ss,lang)) {} + inline void chLang(idx_t l) { shadow->chLang(l); dirty=true; } inline void enable() {enabled=enabledStatus;} inline void disable() {enabled=disabledStatus;} inline constText* getText() const {return shadow->getText();} @@ -110,6 +113,8 @@ inline navTarget(constMEM promptShadow& shadow):prompt(shadow) {} inline navTarget(constText* t,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=_noStyle) :prompt(t,a,e,s,ss) {} + inline navTarget(constText** pt,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=_noStyle,idx_t lang=0) + :prompt(pt,a,e,s,ss,lang) {} virtual void parseInput(navNode& nav,menuIn& in); virtual void doNav(navNode& nav,navCmd cmd); #ifdef MENU_ASYNC @@ -135,6 +140,17 @@ styles style=noStyle, systemStyles ss=(Menu::systemStyles)(_noStyle|_canNav|_parentDraw) ):navTarget(*new textFieldShadow(label,b,sz,v,a,e,style,ss)) {} + inline textField( + constText** plabel, + char* b, + idx_t sz, + char* const* v, + action a=doNothing, + eventMask e=noEvent, + styles style=noStyle, + systemStyles ss=(Menu::systemStyles)(_noStyle|_canNav|_parentDraw), + idx_t lang=0 + ):navTarget(*new textFieldShadow(plabel,b,sz,v,a,e,style,ss,lang)) {} inline char* buffer() const {return ((textFieldShadow*)shadow)->_buffer();} inline idx_t sz() const {return ((textFieldShadow*)shadow)->_sz();} constText* validator(int i); @@ -191,6 +207,19 @@ eventMask e=noEvent, styles s=noStyle ):menuField(*new menuFieldShadow(value,text,units,low,high,step,tune,a,e,s)) {} + menuField( + T &value, + constText** ptext, + constText*units, + T low, + T high, + T step, + T tune, + action a=doNothing, + eventMask e=noEvent, + styles s=noStyle, + idx_t lang=0 + ):menuField(*new menuFieldShadow(value,ptext,units,low,high,step,tune,a,e,s,lang)) {} bool canTune() override; void constrainField() override; idx_t printReflex(menuOut& o) const override; @@ -222,6 +251,8 @@ inline menuValue(constMEM menuValueShadow& shadow):prompt(shadow) {} inline menuValue(constText* text,T value,action a=doNothing,eventMask e=noEvent) :menuValue(*new menuValueShadow(text,value,a,e)) {} + inline menuValue(constText** ptext,T value,action a=doNothing,eventMask e=noEvent,idx_t lang=0) + :menuValue(*new menuValueShadow(ptext,value,a,e,lang)) {} inline T target() const {return ((menuValueShadow*)shadow)->target();} #ifdef MENU_FMT_WRAPS virtual classes type() const {return valueClass;} @@ -238,6 +269,8 @@ inline menuNode(constMEM menuNodeShadow& s):navTarget(s) {} inline menuNode(constText* text,idx_t sz,prompt* constMEM data[],action a=noAction,eventMask e=noEvent,styles style=wrapStyle,systemStyles ss=(systemStyles)(_menuData|_canNav)) :navTarget(*new menuNodeShadow(text,sz,data,a,e,style,ss)) {} + inline menuNode(constText** ptext,idx_t sz,prompt* constMEM data[],action a=noAction,eventMask e=noEvent,styles style=wrapStyle,systemStyles ss=(systemStyles)(_menuData|_canNav),idx_t lang=0) + :navTarget(*new menuNodeShadow(ptext,sz,data,a,e,style,ss,lang)) {} #ifdef MENU_FMT_WRAPS virtual classes type() const; #endif @@ -268,6 +301,7 @@ #endif template bool _changes(const navNode &nav,const menuOut& out,bool sub,bool test); + void chLang(idx_t lang); }; //-------------------------------------------------------------------------- @@ -301,6 +335,8 @@ inline menuVariant(constMEM menuNodeShadow& s):menuVariantBase(s) {} inline menuVariant(constText* text,T &target,idx_t sz,prompt* constMEM* data,action a,eventMask e,styles style) :menuVariantBase(*new menuVariantShadow(text,target,sz,data,a,e,style)) {} + inline menuVariant(constText** ptext,T &target,idx_t sz,prompt* constMEM* data,action a,eventMask e,styles style,idx_t lang=0) + :menuVariantBase(*new menuVariantShadow(ptext,target,sz,data,a,e,style,lang)) {} idx_t sync() override; idx_t sync(idx_t i) override; inline T& target() const {return ((menuVariantShadow*)shadow)->target();} @@ -325,6 +361,17 @@ styles style=noStyle, systemStyles ss=((systemStyles)(Menu::_menuData|Menu::_canNav|Menu::_isVariant|Menu::_parentDraw)) ):menuVariant(*new menuVariantShadow(text,target,sz,data,a,e,style,ss)) {} + inline select( + constText** ptext, + T &target, + idx_t sz, + prompt* constMEM* data, + action a=doNothing, + eventMask e=noEvent, + styles style=noStyle, + systemStyles ss=((systemStyles)(Menu::_menuData|Menu::_canNav|Menu::_isVariant|Menu::_parentDraw)), + idx_t lang=0 + ):menuVariant(*new menuVariantShadow(ptext,target,sz,data,a,e,style,ss,lang)) {} #ifdef MENU_FMT_WRAPS virtual classes type() const {return selectClass;} #endif @@ -347,6 +394,17 @@ styles style=noStyle, systemStyles ss=((systemStyles)(Menu::_menuData|Menu::_isVariant)) ):menuVariant(*new menuVariantShadow(text,target,sz,data,a,e,style,ss)) {} + inline toggle( + constText** ptext, + T &target, + idx_t sz, + prompt* constMEM* data, + action a=doNothing, + eventMask e=noEvent, + styles style=noStyle, + systemStyles ss=((systemStyles)(Menu::_menuData|Menu::_isVariant)), + idx_t lang=0 + ):menuVariant(*new menuVariantShadow(ptext,target,sz,data,a,e,style,ss,lang)) {} #ifdef MENU_FMT_WRAPS classes type() const override; #endif @@ -372,6 +430,17 @@ styles style=noStyle, systemStyles ss=((systemStyles)(Menu::_menuData|Menu::_canNav|Menu::_isVariant)) ):menuVariant(*new menuVariantShadow(text,target,sz,data,a,e,style,ss)) {} + inline choose( + constText** ptext, + T &target, + idx_t sz, + prompt* constMEM* data, + action a=doNothing, + eventMask e=noEvent, + styles style=noStyle, + systemStyles ss=((systemStyles)(Menu::_menuData|Menu::_canNav|Menu::_isVariant)), + idx_t lang=0 + ):menuVariant(*new menuVariantShadow(ptext,target,sz,data,a,e,style,ss,lang)) {} #ifdef MENU_FMT_WRAPS classes type() const override; #endif diff --git a/src/shadows.h b/src/shadows.h index 98d48d0c..857d99ce 100644 --- a/src/shadows.h +++ b/src/shadows.h @@ -19,11 +19,15 @@ public: systemStyles sysStyles; constText*text; + constText **ptext=NULL; // multi-lang string array eventMask events;//registered events (mask) styles style; public: promptShadow(constText* t,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=_noStyle) :action(a),sysStyles(ss),text(t),events(e),style(s) {} + promptShadow(constText* pt[],action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=_noStyle,idx_t lang=0) + :action(a),sysStyles(ss),ptext(pt),events(e),style(s) { text = pt[lang]; } + inline void chLang(idx_t l) { if(ptext) text = ptext[l]; } inline constText* getText() const {return (constText*)memPtr(text);} inline systemStyles _sysStyles() const {return (systemStyles)memEnum(&sysStyles);} inline eventMask _events() const {return (eventMask)memEnum(&events);} @@ -55,6 +59,17 @@ styles style=noStyle, systemStyles ss=(Menu::systemStyles)(_noStyle|_canNav|_parentDraw) ):promptShadow(label,a,e,style,ss),buffer(b),validators(v),sz(sz) {} + textFieldShadow( + constText** plabel, + char* b, + idx_t sz, + char* const* v, + action a=doNothing, + eventMask e=noEvent, + styles style=noStyle, + systemStyles ss=(Menu::systemStyles)(_noStyle|_canNav|_parentDraw), + idx_t lang=0 + ):promptShadow(plabel,a,e,style,ss,lang),buffer(b),validators(v),sz(sz) {} idx_t _sz() const {return (idx_t)memIdx(sz);} char* _buffer() const {return (char*)memPtr(buffer);} char* const* _validators() const {return (char* const*)memPtr(validators);} @@ -77,6 +92,8 @@ idx_t sz; prompt* constMEM* data; public: + menuNodeShadow(constText** ptext,idx_t sz,prompt* constMEM* data,action a,eventMask e,styles style,systemStyles ss=(systemStyles)(_menuData|_canNav),idx_t lang=0) + :promptShadow(ptext,a,e,style,ss,lang),sz(sz),data(data) {} menuNodeShadow(constText* text,idx_t sz,prompt* constMEM* data,action a,eventMask e,styles style,systemStyles ss=(systemStyles)(_menuData|_canNav)) :promptShadow(text,a,e,style,ss),sz(sz),data(data) {} idx_t _sz() const {return (idx_t)memIdx(sz);} @@ -98,6 +115,8 @@ class fieldBaseShadow:public promptShadow { public: constText* units; + fieldBaseShadow(constText** ptext,constText*units,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=((Menu::systemStyles)(Menu::_canNav|Menu::_parentDraw)),idx_t lang=0) + :promptShadow(ptext,a,e,s,ss,lang),units(units) {} fieldBaseShadow(constText* text,constText*units,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=((Menu::systemStyles)(Menu::_canNav|Menu::_parentDraw))) :promptShadow(text,a,e,s,ss),units(units) {} inline constText* _units() {return (constText*)memPtr(units);} @@ -122,6 +141,8 @@ public: menuFieldShadow(T &value,constText* text,constText*units,T low,T high,T step,T tune,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=((Menu::systemStyles)(Menu::_canNav|Menu::_parentDraw))) :fieldBaseShadow(text,units,a,e,s,ss),value(&value),low(low),high(high),step(step),tune(tune) {} + menuFieldShadow(T &value,constText** ptext,constText*units,T low,T high,T step,T tune,action a=doNothing,eventMask e=noEvent,styles s=noStyle,systemStyles ss=((Menu::systemStyles)(Menu::_canNav|Menu::_parentDraw)),idx_t lang=0) + :fieldBaseShadow(ptext,units,a,e,s,ss,lang),value(&value),low(low),high(high),step(step),tune(tune) {} inline T& target() const {return *(T*)memPtr(value);} inline T getTypeValue(const T* from) const { //TODO: dynamic versions require change of preprocessor to virtual @@ -156,6 +177,8 @@ public: inline menuValueShadow(constText* text,T value,action a=doNothing,eventMask e=noEvent) :promptShadow(text,a,e),value(value) {} + inline menuValueShadow(constText** ptext,T value,action a=doNothing,eventMask e=noEvent,idx_t lang=0) + :promptShadow(ptext,a,e,lang),value(value) {} inline T getTypeValue(const T* from) const { //TODO: dynamic versions require change of preprocessor to virtual #ifdef USING_PGM @@ -196,6 +219,17 @@ styles style, systemStyles ss=(systemStyles)(_menuData|_canNav) ):menuNodeShadow(text,sz,data,a,e,style,ss),value(&target) {} + menuVariantShadow( + constText** ptext, + T &target, + idx_t sz, + prompt* constMEM* data, + action a, + eventMask e, + styles style, + systemStyles ss=(systemStyles)(_menuData|_canNav), + idx_t lang=0 + ):menuNodeShadow(ptext,sz,data,a,e,style,ss,lang),value(&target) {} inline T& target() const {return *((T*)memPtr(value));} }; }//namespace Menu