From b43569fc91c5ffd4889b126b91451f7d387f1b4e Mon Sep 17 00:00:00 2001 From: kohait Date: Mon, 16 May 2011 20:32:29 +0000 Subject: [PATCH] bazaar: ValueCtrl: some type and handling fixes; LogPosCtrl & RectCtrl: handling fixes; BoostPyTest: type handling fixes, live eval example, Callback stack overflow fix git-svn-id: svn://ultimatepp.org/upp/trunk@3426 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/BoostPyTest/BoostPyTest.h | 3 ++ bazaar/BoostPyTest/BoostPyTest.lay | 14 ++++--- bazaar/BoostPyTest/main.cpp | 20 +++++++++- bazaar/CoreBoostPy/Callback.cpp | 25 ++----------- bazaar/CoreBoostPy/Value.cpp | 24 ++++++------ bazaar/CtrlLibBoostPy/CtrlCore.cpp | 2 + bazaar/LogPosCtrl/LogPosCtrl.cpp | 1 + bazaar/RectCtrl/RectCtrl.cpp | 17 ++++++++- bazaar/ValueCtrl/ValueCtrl.cpp | 39 +++++++------------ bazaar/ValueCtrl/ValueCtrl.h | 60 ++++++++++++++++++++++++++++++ 10 files changed, 137 insertions(+), 68 deletions(-) diff --git a/bazaar/BoostPyTest/BoostPyTest.h b/bazaar/BoostPyTest/BoostPyTest.h index 3a0711632..1d0447bcc 100644 --- a/bazaar/BoostPyTest/BoostPyTest.h +++ b/bazaar/BoostPyTest/BoostPyTest.h @@ -19,6 +19,9 @@ public: void ExitHandler(); void CBi(int i); + void EvalCB(); + + object main_namespace; #if PUREVIRTEST #else diff --git a/bazaar/BoostPyTest/BoostPyTest.lay b/bazaar/BoostPyTest/BoostPyTest.lay index 4711ec67d..8337c00f0 100644 --- a/bazaar/BoostPyTest/BoostPyTest.lay +++ b/bazaar/BoostPyTest/BoostPyTest.lay @@ -1,10 +1,12 @@ LAYOUT(BoostPyTestLayout, 672, 380) ITEM(PyConsoleCtrl, con, HSizePosZ(0, 248).VSizePosZ(0, 0)) - ITEM(SliderCtrl, sl, RightPosZ(8, 232).TopPosZ(12, 48)) - ITEM(ValueCtrl, vc, RightPosZ(8, 232).TopPosZ(76, 56)) - ITEM(ValueCtrl, vc2, RightPosZ(8, 232).BottomPosZ(112, 56)) - ITEM(EditString, es, RightPosZ(8, 232).TopPosZ(148, 19)) - ITEM(Label, dv___5, SetLabel(t_("eval:")).RightPosZ(210, 30).BottomPosZ(173, 19)) - ITEM(EditString, ev, RightPosZ(8, 200).BottomPosZ(173, 19)) + ITEM(SliderCtrl, sl, RightPosZ(8, 232).TopPosZ(8, 28)) + ITEM(ValueCtrl, vc, RightPosZ(8, 232).TopPosZ(44, 56)) + ITEM(ValueCtrl, evr, RightPosZ(8, 192).TopPosZ(172, 20)) + ITEM(EditString, es, RightPosZ(8, 232).TopPosZ(108, 19)) + ITEM(Label, dv___5, SetLabel(t_("eval:")).RightPosZ(200, 40).TopPosZ(148, 19)) + ITEM(Label, dv___6, SetLabel(t_("return:")).RightPosZ(200, 40).TopPosZ(172, 19)) + ITEM(EditString, ev, RightPosZ(28, 172).TopPosZ(148, 19)) + ITEM(Button, ex, SetLabel(t_("Ex")).RightPosZ(8, 16).TopPosZ(148, 20)) END_LAYOUT diff --git a/bazaar/BoostPyTest/main.cpp b/bazaar/BoostPyTest/main.cpp index 4a7534fb5..8ded4dc96 100644 --- a/bazaar/BoostPyTest/main.cpp +++ b/bazaar/BoostPyTest/main.cpp @@ -8,6 +8,16 @@ void BoostPyTest::CBi(int i) RLOG(i); } +void BoostPyTest::EvalCB() +{ + String s = ev.GetData(); + + object o = eval(s.Begin(), main_namespace, main_namespace); + Value v = extract(o); + + evr.SetData(v); +} + BoostPyTest::BoostPyTest() { CtrlLayout(*this, "Boost Test"); @@ -26,7 +36,7 @@ BoostPyTest::BoostPyTest() try { object main_module(handle<>(borrowed(PyImport_AddModule("__main__")))); - object main_namespace = main_module.attr("__dict__"); + main_namespace = main_module.attr("__dict__"); handle<> ign(PyRun_String( "print \"Hello, World\"", Py_file_input, @@ -69,8 +79,16 @@ BoostPyTest::BoostPyTest() object o = eval("100 + upp.sl.data", main_namespace, main_namespace); int data = extract(o); + ev.WhenEnter = THISBACK(EvalCB); + ex <<= THISBACK(EvalCB); + evr.SetReadOnly(); + ev.SetData("100 + upp.sl.getdata()"); + EvalCB(); + String sc = + "upp.app.title = 'My Big BoostPy Test Environment'\n" + #if PUREVIRTEST #else "p = hello.World()\n" diff --git a/bazaar/CoreBoostPy/Callback.cpp b/bazaar/CoreBoostPy/Callback.cpp index 6ce9503a6..b2c48e66a 100644 --- a/bazaar/CoreBoostPy/Callback.cpp +++ b/bazaar/CoreBoostPy/Callback.cpp @@ -23,7 +23,6 @@ struct Callback_from_python static void* convertible(PyObject* po) { if(po == Py_None) return po; - if(extract(po).check()) return po; if(PyFunction_Check(po)) return po; if(PyCallable_Check(po) && PyMethod_Self(po)) return po; return 0; @@ -34,13 +33,9 @@ struct Callback_from_python void* d = ((converter::rvalue_from_python_storage*)data)->storage.bytes; if(po == Py_None) { new(d) Callback(); } -#if 1 //actually isnt used anywhere so far - else if(extract(po).check()) { - Callback& c = extract(po); new(d) Callback(c); } -#endif else if(PyFunction_Check(po)) { new(d) Callback(new CallbackActionPy(po)); } else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Callback(new CallbackActionPy(po)); } - else { throw_error_already_set(); } //FIXME dont know type, which to throw? + else { throw_error_already_set(); } data->convertible = d; } @@ -63,7 +58,6 @@ struct Gate_from_python if(po == Py_None) return po; if(PyFunction_Check(po)) return po; if(PyCallable_Check(po) && PyMethod_Self(po)) return po; - if(extract(po).check()) return po; return 0; } @@ -74,10 +68,7 @@ struct Gate_from_python if(po == Py_None) { new(d) Gate(); } else if(PyFunction_Check(po)) { new(d) Gate(new GateActionPy(po)); } else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Gate(new GateActionPy(po)); } -#if 1 //actually isnt used anywhere so far - else if(extract(po).check()) { Gate& c = extract(po); new(d) Gate(c); } -#endif - else { throw_error_already_set(); } //FIXME dont know type, which to throw? + else { throw_error_already_set(); } data->convertible = d; } @@ -100,7 +91,6 @@ struct Callback1_int_from_python if(po == Py_None) return po; if(PyFunction_Check(po)) return po; if(PyCallable_Check(po) && PyMethod_Self(po)) return po; - if(extract&>(po).check()) return po; return 0; } @@ -111,10 +101,7 @@ struct Callback1_int_from_python if(po == Py_None) { new(d) Callback1(); } else if(PyFunction_Check(po)) { new(d) Callback1(new Callback1Action_int_Py(po)); } else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Callback1(new Callback1Action_int_Py(po)); } -#if 1 //actually isnt used anywhere so far - else if(extract&>(po).check()) { Callback1& c = extract&>(po); new(d) Callback1(c); } -#endif - else { throw_error_already_set(); } //FIXME dont know type, which to throw? + else { throw_error_already_set(); } data->convertible = d; } @@ -137,7 +124,6 @@ struct Gate1_int_from_python if(po == Py_None) return po; if(PyFunction_Check(po)) return po; if(PyCallable_Check(po) && PyMethod_Self(po)) return po; - if(extract&>(po).check()) return po; return 0; } @@ -148,10 +134,7 @@ struct Gate1_int_from_python if(po == Py_None) { new(d) Gate1(); } else if(PyFunction_Check(po)) { new(d) Gate1(new Gate1Action_int_Py(po)); } else if(PyCallable_Check(po) && PyMethod_Self(po)) { new(d) Gate1(new Gate1Action_int_Py(po)); } -#if 1 //actually isnt used anywhere so far - else if(extract&>(po).check()) { Gate1& c = extract&>(po); new(d) Gate1(c); } -#endif - else { throw_error_already_set(); } //FIXME dont know type, which to throw? + else { throw_error_already_set(); } data->convertible = d; } diff --git a/bazaar/CoreBoostPy/Value.cpp b/bazaar/CoreBoostPy/Value.cpp index 2931d99e0..929eec539 100644 --- a/bazaar/CoreBoostPy/Value.cpp +++ b/bazaar/CoreBoostPy/Value.cpp @@ -43,10 +43,10 @@ struct Value_from_python if(PyString_Check(po)) return po; if(PyList_Check(po)) return po; if(PyDict_Check(po)) return po; - if(extract(po).check()) return po; - if(extract(po).check()) return po; - if(extract(po).check()) return po; - if(extract(po).check()) return po; + if(extract(po).check()) return po; + if(extract(po).check()) return po; + if(extract(po).check()) return po; + if(extract(po).check()) return po; return 0; } @@ -106,27 +106,27 @@ struct Value_from_python new(d) Value(c); } else - if(extract(po).check()) + if(extract(po).check()) { - Color& c = extract(po); //use upper converter + Color c = extract(po); //use upper converter new(d) Value(c.operator Value()); } else - if(extract(po).check()) + if(extract(po).check()) { - Point& c = extract(po); //use upper converter + Point c = extract(po); //use upper converter new(d) Value(c.operator Value()); } else - if(extract(po).check()) + if(extract(po).check()) { - Size& c = extract(po); //use upper converter + Size c = extract(po); //use upper converter new(d) Value(c.operator Value()); } else - if(extract(po).check()) + if(extract(po).check()) { - Rect& c = extract(po); //use upper converter + Rect c = extract(po); //use upper converter new(d) Value(c.operator Value()); } else diff --git a/bazaar/CtrlLibBoostPy/CtrlCore.cpp b/bazaar/CtrlLibBoostPy/CtrlCore.cpp index f9f05b631..362b3eaf4 100644 --- a/bazaar/CtrlLibBoostPy/CtrlCore.cpp +++ b/bazaar/CtrlLibBoostPy/CtrlCore.cpp @@ -562,6 +562,8 @@ ONCELOCK .add_property("maximize", &TopWindow::IsMaximized, &TopWindow::Maximize) .add_property("overlap", &TopWindow::IsOverlapped, &TopWindow::Overlap) + .add_property("title", &TopWindowGetTitle, &TopWindowSetTitle) + .add_property("sizeable", &TopWindow::IsSizeable, &TopWindowSizeable) .add_property("zoomable", &TopWindow::IsZoomable, &TopWindowZoomable) .add_property("topmost", &TopWindow::IsTopMost, &TopWindowTopMost) diff --git a/bazaar/LogPosCtrl/LogPosCtrl.cpp b/bazaar/LogPosCtrl/LogPosCtrl.cpp index 22cadd446..ff9ed132f 100644 --- a/bazaar/LogPosCtrl/LogPosCtrl.cpp +++ b/bazaar/LogPosCtrl/LogPosCtrl.cpp @@ -264,6 +264,7 @@ LogPosCtrl::LogPosCtrl() : push(false) void LogPosCtrl::LeftDown(Point p, dword keyflags) { + if(IsReadOnly() || !IsEnabled()) return; if(!HasFocus()) SetFocus(); Drop(); } diff --git a/bazaar/RectCtrl/RectCtrl.cpp b/bazaar/RectCtrl/RectCtrl.cpp index 388fc2080..f28c7b798 100644 --- a/bazaar/RectCtrl/RectCtrl.cpp +++ b/bazaar/RectCtrl/RectCtrl.cpp @@ -145,9 +145,14 @@ void RectCtrl::Paint(Draw& w) { Size sz = GetSize(); if(r.IsNullInstance()) return; - - w.DrawRect(r, style->rectcol); + + if(IsEnabled()) + w.DrawRect(r, style->rectcol); + DrawHandleFrame(w, r, style->framecol, style->framesize); + + if(!IsEnabled() || IsReadOnly()) return; + DrawHandle(w, r, style->handcol, style->handsize); if(pressed)// && moving) DrawRectInfo(w, Point(10,10), r, style->framecol, style->textcol); @@ -155,6 +160,8 @@ void RectCtrl::Paint(Draw& w) void RectCtrl::LeftDown(Point p, dword keyflags) { + if(IsReadOnly() || !IsEnabled()) return; + SetCapture(); moving = false; pressed = (keyflags & K_MOUSELEFT); @@ -170,6 +177,8 @@ void RectCtrl::LeftDown(Point p, dword keyflags) void RectCtrl::MouseMove(Point p, dword keyflags) { + if(IsReadOnly() || !IsEnabled()) return; + moving = true; pressed = (keyflags & K_MOUSELEFT); //int m = GetMode(r, p, keyflags, style->handsize); @@ -191,6 +200,8 @@ void RectCtrl::LeftUp(Point p, dword keyflags) xr.SetNull(); xp.SetNull(); mode = NONE; + if(IsReadOnly() || !IsEnabled()) return; + c = SetCursor(mode, keyflags, c); Refresh(); } @@ -205,6 +216,8 @@ void RectCtrl::RightDown(Point p, dword keyflags) //xp.SetNull(); int m = mode; mode = NONE; + if(IsReadOnly() || !IsEnabled()) return; + c = SetCursor(mode, keyflags, c); if(m != NONE) { diff --git a/bazaar/ValueCtrl/ValueCtrl.cpp b/bazaar/ValueCtrl/ValueCtrl.cpp index 35cf44448..c8d678aec 100644 --- a/bazaar/ValueCtrl/ValueCtrl.cpp +++ b/bazaar/ValueCtrl/ValueCtrl.cpp @@ -15,7 +15,7 @@ INITBLOCK map.Add(int(DATE_V), Instancer::Typed::GetInstancer()); map.Add(int(TIME_V), Instancer::Typed::GetInstancer()); map.Add(int(WSTRING_V),Instancer::Typed::GetInstancer()); - map.Add(int(INT64_V), Instancer::Typed< WithEnterAction >::GetInstancer()); + map.Add(int(INT64_V), Instancer::Typed >::GetInstancer()); map.Add(int(BOOL_V), &OptionInstancer); @@ -86,17 +86,17 @@ Ctrl* DefaultValueEditor(const Value& v) return p; } -void ValuePopUp::SetType(int _vt) +void ValuePopUp::SetType(int vt) { - if(_vt == vtype) return; + if(vt == vtype) return; v = Value(); //reset - if(_vt==VOID_V) //prevent loop + if(vt == VOID_V) //prevent loop { if(pc) return; //keep last Editor - _vt = STRING_V; //default, if no editor yet + vt = STRING_V; //default, if no editor yet } - pc = DefaultValueEditor(_vt); - vtype = _vt; + pc = DefaultValueEditor(vt); + vtype = vt; ASSERT(pc); Add(pc->HSizePos().VSizePos(0,20)); pc->WhenAction = THISBACK(DataAction); @@ -105,9 +105,9 @@ void ValuePopUp::SetType(int _vt) void ValuePopUp::Updated() { - int _vt = v.GetType(); - if(_vt != vtype && !v.IsNull()) //change only if needed, keep editor for !null - SetType(_vt); + int vt = v.GetType(); + if(vt != vtype && !v.IsNull()) //change only if needed, keep editor for !null + SetType(vt); if(type.GetData() != vtype) type.SetData(vtype); pc->SetData(v); @@ -126,23 +126,9 @@ ValuePopUp::ValuePopUp() CtrlLayout(*this); SetFrame(BlackFrame()); - type.Add(int(VOID_V), "VOID_V (reset data only)"); - type.Add(int(INT_V), "INT_V"); - type.Add(int(DOUBLE_V), "DOUBLE_V"); - type.Add(int(STRING_V), "STRING_V"); - type.Add(int(DATE_V), "DATE_V"); - type.Add(int(TIME_V), "TIME_V"); - type.Add(int(WSTRING_V), "WSTRING_V"); - type.Add(int(INT64_V), "INT64_V"); - type.Add(int(BOOL_V), "BOOL_V"); - type.Add(int(COLOR_V), "COLOR_V"); - type.Add(int(LOGPOS_V), "LOGPOS_V"); - //type.Add(int(VALUE_V), "VALUE_V"); - type.Add(int(VALUEARRAY_V), "VALUEARRAY_V"); - type.Add(int(VALUEMAP_V), "VALUEMAP_V"); - type.Add(int(ERROR_V), "ERROR_V"); - type <<= THISBACK(TypeAction); + type.Clear(); + AddTypesAll(); ok <<= THISBACK(Acceptor); cancel <<= THISBACK(Rejector); @@ -165,6 +151,7 @@ ValueCtrl::ValueCtrl() void ValueCtrl::LeftDown(Point p, dword keyflags) { + if(IsReadOnly() || !IsEnabled()) return; if(!HasFocus()) SetFocus(); Drop(); } diff --git a/bazaar/ValueCtrl/ValueCtrl.h b/bazaar/ValueCtrl/ValueCtrl.h index da99d482a..078b960a9 100644 --- a/bazaar/ValueCtrl/ValueCtrl.h +++ b/bazaar/ValueCtrl/ValueCtrl.h @@ -13,8 +13,14 @@ using namespace Upp; #define LAYOUTFILE #include +//For ValuePacker / RichValue and GCC +NAMESPACE_UPP +template<> inline bool IsNull(const Value& v) { return v.IsNull(); } +END_UPP_NAMESPACE + Ctrl* DefaultValueEditor(int vtype); Ctrl* DefaultValueEditor(const Value& v); +String VTypeToString(int vtype); class ValuePopUp : public WithValuePopUpLayout { public: @@ -30,6 +36,60 @@ public: void PopUp(Ctrl* owner, const Value& _v) { SetData(_v); PopUpC::PopUp(owner); } Callback WhenTypeChange; + + void AddType(int vtype, const String& s) { if(type.Find(vtype) < 0) type.Add(vtype, s); } + void AddType(int vtype) { AddType(vtype, VTypeToString(vtype)); } + + void ClearTypes() { type.Clear(); SetType(VOID_V); } + + void AddTypesInteger() + { + AddType(int(INT_V), "int"); + AddType(int(INT64_V), "int64"); + AddType(int(BOOL_V), "bool"); + } + + void AddTypesFloat() + { + AddType(int(DOUBLE_V), "double"); + } + + void AddTypesHighLevel() + { + AddType(int(STRING_V), "String"); + AddType(int(DATE_V), "Date"); + AddType(int(TIME_V), "Time"); + AddType(int(WSTRING_V), "WString"); + AddType(int(COLOR_V), "Color"); + } + + void AddTypesContainer() + { + //AddType(int(VALUE_V), "Value"); + AddType(int(VALUEARRAY_V), "ValueArray"); + AddType(int(VALUEMAP_V), "ValueMap"); + } + + void AddTypesExt() + { + AddType(int(LOGPOS_V), "Ctrl::LogPos"); + } + + void AddTypesDebug() + { + AddType(int(VOID_V), "Null (Reset data only)"); + AddType(int(ERROR_V), "ErrorValue"); + } + + void AddTypesAll() + { + AddTypesInteger(); + AddTypesFloat(); + AddTypesHighLevel(); + AddTypesContainer(); + AddTypesExt(); + AddTypesDebug(); + } protected: void TypeAction();