Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » GetProperty() / SetProperty() for Ctrl
Re: GetProperty() / SetProperty() for Ctrl [message #29995 is a reply to message #29994] Thu, 02 December 2010 13:39 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
thanks, thats a hint...i'll think about it

EDIT: the property definition is not as much of a problem as to organize the 'jump in to search the property of an arbitrary ctrl'

how would you do the property handling so that the entrance point is not relaying on the type information..?
i mean the following:


//needs type information to go forward 
//and access the corresponding properties table
template<class C>
void SetProp(C& c, const String& name, const Value& v);

////

//typeless, will search for type table of properties and
//there for the convenient property
void SetProp(Ctrl& c, const String& name, const Value& v);


this is basicly the question..

also, it may have get only properties, and set only properties

but i see your point to simplify it and handle everything in one function, to register only one function...

[Updated on: Thu, 02 December 2010 14:10]

Report message to a moderator

Re: GetProperty() / SetProperty() for Ctrl [message #30011 is a reply to message #29995] Thu, 02 December 2010 23:50 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i finally came up with sth like this, what do you think about it?


//for Ctrl

CTRL_PROPERTIES(Ctrl)
PROPERTY(Ctrl, "data", PropSetData, PropGetData)
PROPERTY(Ctrl, "enable", PropEnable, PropIsEnabled)
PROPERTY(Ctrl, "show", PropShow, PropIsVisible)
PROPERTY(Ctrl, "editable", PropEditable, PropIsEditable)
PROPERTY(Ctrl, "logpos", PropSetLogPos, PropGetLogPos)
PROPERTY(Ctrl, "focus", PropFocus, PropHasFocus)
PROPERTY(Ctrl, "modify", PropModify, PropIsModified)
PROPERTY(Ctrl, "tip", PropSetTip, PropGetTip)
PROPERTY(Ctrl, "wantfocus", PropWantFocus, PropIsWantFocus)
PROPERTY(Ctrl, "initFocus", PropInitFocus, PropIsInitFocus)
PROPERTY(Ctrl, "backpaint", PropBackPaint, PropIsBackPaint)
PROPERTY(Ctrl, "transparent", PropTransparent, PropIsTransparent)
PROPERTY_SET(Ctrl, "refresh", PropRefresh)
END_CTRL_PROPERTIES(Ctrl, RecurseDone)

//for EditInt

DEC_CTRL_PROPERTIES(Ctrl)

CTRL_PROPERTIES(EditInt)
PROPERTY(EditInt, "min", PropSetMin, PropGetMin)
PROPERTY(EditInt, "max", PropSetMax, PropGetMax)
END_CTRL_PROPERTIES(EditInt, Ctrl)



this already works and is a more slim solution as before. take a look in header.

note how one can specify properties even separated (see Ctrl definition)..

a good option is, that properties could be reset to sth different (overridden), by specifying again:
PROPERTY(Ctrl, "data", MyPropSetData, MyPropGetData)


i think this is simple enough..what do you think?

[Updated on: Fri, 03 December 2010 09:05]

Report message to a moderator

Re: GetProperty() / SetProperty() for Ctrl [message #30013 is a reply to message #30011] Fri, 03 December 2010 09:31 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
BTW: Edit Controls inconsistancy Smile
EditIntNotNullSpin not present
and
EditIntSpin not in same manner as EditDoubleSpin

add:
EditCtrl.h:326
class EditIntNotNullSpin : public EditIntSpin
{
public:
	EditIntNotNullSpin(int inc = 1) : EditIntSpin(inc) { NotNull(); }
	EditIntNotNullSpin(int min, int max, int inc = 1) : EditIntSpin(min, max, inc) { NotNull(); }
};


change to:
EditCtrl.h:321
	EditIntSpin(int inc = 1);
	EditIntSpin(int min, int max, int inc = 1);


EditField.cpp:1052
void EditIntSpin::Init()
{
	sb.inc.WhenAction = sb.inc.WhenRepeat = callback(this, &EditIntSpin::Inc);
	sb.dec.WhenAction = sb.dec.WhenRepeat = callback(this, &EditIntSpin::Dec);
	AddFrame(sb);
}

EditIntSpin::EditIntSpin(int inc) : inc(inc) { Init(); }
EditIntSpin::EditIntSpin(int min, int max, int inc) : EditInt(min, max), inc(inc) { Init(); }
Re: GetProperty() / SetProperty() for Ctrl [message #30097 is a reply to message #30013] Thu, 09 December 2010 06:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Still could be better IMO. Too much code to be written. What about something like:

PROPERTY(EditInt, "min", IsNumber(param), MinMax(param, o.GetMax()), GetMin())

also

REGISTERPROPS(EditInt);

is not neededed, you can squeeze that to CTRL_PROPERTIES

And with a little effort, you can move base class parameter to CTRL_PROPERTIES too and make END_CTRL_PROPERTIES parameter-less.
Re: GetProperty() / SetProperty() for Ctrl [message #30098 is a reply to message #30097] Thu, 09 December 2010 07:03 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
thanks, i'll try Smile
EDIT: question remains: am i using the dynamic_cast in the way you thought it?

[Updated on: Thu, 09 December 2010 07:10]

Report message to a moderator

Re: GetProperty() / SetProperty() for Ctrl [message #30100 is a reply to message #30098] Thu, 09 December 2010 08:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 09 December 2010 01:03

thanks, i'll try Smile
EDIT: question remains: am i using the dynamic_cast in the way you thought it?


Yes.

I would perhaps rather use simple ifs to test for property name instead of map of callbacks.

BTW, after more thinking, maybe:

PROPERTY(EditInt, "min", if(IsNumber(param)) MinMax(param, o.GetMax()), GetMin())

Mirek
Re: GetProperty() / SetProperty() for Ctrl [message #30101 is a reply to message #30100] Thu, 09 December 2010 08:36 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i'd prefer if's as well, if one could override them externally..
but it is questionable, if it is usefull to derive/override properties. if yes, than callbacks are the only option so far.
so a still stayed with the explicit naming of the handlers, so full control in handlers remains. everything else is done as you said, this is the result so far.

CTRL_PROPERTIES(Ctrl, RecurseDone)
PROPERTY("data", PropSetData, PropGetData)
PROPERTY("enable", PropEnable, PropIsEnabled)
PROPERTY("show", PropShow, PropIsVisible)
PROPERTY("editable", PropEditable, PropIsEditable)
PROPERTY("logpos", PropSetLogPos, PropGetLogPos)
PROPERTY("focus", PropFocus, PropHasFocus)
PROPERTY("modify", PropModify, PropIsModified)
PROPERTY("tip", PropSetTip, PropGetTip)
PROPERTY("wantfocus", PropWantFocus, PropIsWantFocus)
PROPERTY("initFocus", PropInitFocus, PropIsInitFocus)
PROPERTY("backpaint", PropBackPaint, PropIsBackPaint)
PROPERTY("transparent", PropTransparent, PropIsTransparent)
PROPERTY_SET("refresh", PropRefresh)
END_CTRL_PROPERTIES

..

CTRL_PROPERTIES(EditInt, Ctrl)
PROPERTY("min", PropSetMin, PropGetMin)
PROPERTY("max", PropSetMax, PropGetMax)
END_CTRL_PROPERTIES


if c++ had delegates like in c# Smile that'd be the best.

BTW: how to install a MouseHook (which is no __thiscall) to operate on a application local TopWindow? i want to start an edit properties window on arbitrary controls upon a mouse+key combination..

EDIT: solution found, just tell me if there are pitfalls i dont see:
bool MyMouseHook(Ctrl *ctrl, bool inframe, int event, Point p,
	                          int zdelta, dword keyflags)
{
	if(event & (Ctrl::MOUSEMOVE | Ctrl::MOUSEENTER | Ctrl::MOUSELEAVE | Ctrl::CURSORIMAGE)) return false;
	if((keyflags & K_MOUSERIGHT))
	if((keyflags & K_SHIFT_CTRL))
	{
		CallbackArgTarget<int> m;
		MenuBar menu;
		menu.Add("List Properties",m[0]);
		menu.Add("Edit Properties",m[1]);
		menu.Execute();
		if(IsNull(m)) return true;
		switch(m)
		{
			case 0:
				{ PropList& p = Single<PropList>(); p.PopUp(Ctrl::GetActiveWindow(), *ctrl); }
				break;
			case 1:
				{ PropEdit& p = Single<PropEdit>(); p.PopUp(Ctrl::GetActiveWindow(), *ctrl); }
				break;
		}
		return true;
	}
	return false;
}


[Updated on: Thu, 09 December 2010 08:52]

Report message to a moderator

Re: GetProperty() / SetProperty() for Ctrl [message #30125 is a reply to message #30101] Fri, 10 December 2010 08:55 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i've got a prolem with the mousehook..

it does not work with, i.e., StaticText, which has IgnoreMouse().
how could i grab arbitrary controls for editing? with the mouse hook?
Re: GetProperty() / SetProperty() for Ctrl [message #30128 is a reply to message #30125] Fri, 10 December 2010 10:24 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

kohait00 wrote on Fri, 10 December 2010 08:55

i've got a prolem with the mousehook..

it does not work with, i.e., StaticText, which has IgnoreMouse().
how could i grab arbitrary controls for editing? with the mouse hook?

One workaround could be the method that Sc0rch used in his FormEditor (have a look at it in the bazaar). It uses transparent Ctrl on top of all other Ctrls, grabs the mouse position and then finds the Ctrl that lies at the given location IIRC. It introduces some additional processing, but works for any Ctrl.

Honza
Re: GetProperty() / SetProperty() for Ctrl [message #30129 is a reply to message #30128] Fri, 10 December 2010 10:32 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
great idea thanks a lot
i used transparent clickable controls elsewhere, but never used it as a entire coverage to a layout..cool.

int FormView::ObjectFromPt(Point p)
{
	if (!IsLayout()) return -1;

	for (int i = GetObjectCount() - 1; i >= 0; --i)
		if (Zoom(Offseted( (*GetObjects())[i].GetRect() )).Contains(p))
			return i;
	return -1;
}

[Updated on: Sun, 12 December 2010 13:34]

Report message to a moderator

Re: GetProperty() / SetProperty() for Ctrl [message #30869 is a reply to message #30129] Wed, 26 January 2011 13:55 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
please have a look at bazaar/CtrlProp:

plans are to have a 'live workspace' where i can switch to manipulating the gui elements, store the layout, load it from elsewhere and ofcorse edit the properties of the listed controls.

the current solution is not very satisfying though.

i think/imagine to release the potential for Value and have each control have a set (list or array) of Value's as exposed interface of its properties. much like properties in C#. that'd be great. this would make really dynamic gui cases possible.

plans are, to have kind of a 'dictionary' of such properties, applicationwide, to be able to setup arithmetical functions based on values from the dictionary, and to feed other properties.

this would introduce a new Void() derive with some callbacks to feed the destination controls. it's much like a scripting environment, with all the controls and variables accessible.

it would also make some reactional channels nesseccary..i.e. when having arithmetical functions calculating something depending on some properties and resulting in setting another property.

ideas? on how to do that?


attached is a mini demo..
LiveWorkTest, needs current svn rev 3101..

ps: i am thinking of things like
http://www.jazzmutant.com/lemur_overview.php
http://www.jazzmutant.com/download_lemur_soft.php
check out the JazzEditor, where one can setup values and have the OSC messages be generated based on other values/properties in the system..



  • Attachment: LiveWork.rar
    (Size: 3.95KB, Downloaded 295 times)

[Updated on: Wed, 26 January 2011 14:02]

Report message to a moderator

properties like in C# [message #31021 is a reply to message #30869] Tue, 01 February 2011 14:45 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
see
http://www.codeproject.com/KB/cpp/cppproperties.aspx

which shows an implementation idea..
thanks to Callback we already can have stuff like that:

template<class T>
struct Property
{
	typedef Callback1<const T&> S;
	typedef Callback1<T&> G;

	Property(const S& s, const G& g)
		: set(s), get(g) {}

	const T& Set(const T& a) { ASSERT(set); set(a); return a; }
	T Get() const { ASSERT(get); T t; get(t); return t; }

	inline T operator= (const T& a) { return Set(a); }
	inline operator T() const { return Get(); }

public:
	const S set;
	const G get;
};

typedef Property<Value> PropertyValue;

...

//.h
class PropertyTest : public WithPropertyTestLayout<TopWindow> {
public:
	typedef PropertyTest CLASSNAME;
	PropertyTest();
	
	void GetD(Value& a) { a = "abc"; }
	void SetD(const Value& a) { RLOG(a); }
	
	PropertyValue vp;
};

//.cpp
PropertyTest::PropertyTest()

#pragma warning(push)
#pragma warning(disable:4355)
	: vp( THISBACK(SetD), THISBACK(GetD) )
#pragma warning(pop)

{
	CtrlLayout(*this, "Window title");

	//setting, will call SetD
	vp = 123;

	//getting, will call GetD
	Value v = vp;
	RLOG(v);
}

GUI_APP_MAIN
{
	PropertyTest().Run();
}



now what's the benefit of it? imagine the Ctrls beeing able to be parametrized like

EditInt ei;

ei.min = 100;
ei.max = 200;
ei.data = 150;
ei.show = true;
ei.rect = Rect(0,0, 100,200);
...


while i know it's not much better than current design rule of daisychaining methods, it makes code even bit more clean

[Updated on: Tue, 01 February 2011 14:47]

Report message to a moderator

Re: properties like in C# [message #31025 is a reply to message #31021] Tue, 01 February 2011 16:13 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

kohait00 wrote on Tue, 01 February 2011 14:45

now what's the benefit of it? imagine the Ctrls beeing able to be parametrized like

EditInt ei;

ei.min = 100;
ei.max = 200;
ei.data = 150;
ei.show = true;
ei.rect = Rect(0,0, 100,200);
...


while i know it's not much better than current design rule of daisychaining methods, it makes code even bit more clean


Hi kohait

Actually it is not better in any way... The underlaying code is more complex and the efficiency of chaining is better (both performance-wise and typing-wise). And the readability is IMHO exactly the same:
EditInt ei;

ei.SetMin(100)
  .SetMax(200)
  .SetData(150)
  .Show()
  .SetRect(Rect(0,0, 100,200));

Those are the basic reasons why all the previous proposals to add properties were vetted... You might find some more details by searching the forum.

Best regards,
Honza

PS: Plus having both properties and SetX()/GetX() functions leads to a unnecessary duplicity.
Re: properties like in C# [message #31026 is a reply to message #31025] Tue, 01 February 2011 18:51 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i'm aware of the lesser usefullness Smile

my problem is, actually, i'm still in search of exposing a uniform way of changing a set properties through a uniform interface.

basicly need it for a live workspace, where controls are placed, resized, edited etc..

any other idea?

sth like the following is planned...
index.php?t=getfile&id=3069&private=0
  • Attachment: lemur.JPG
    (Size: 88.06KB, Downloaded 744 times)

[Updated on: Tue, 01 February 2011 19:01]

Report message to a moderator

Re: properties like in C# [message #31031 is a reply to message #31026] Tue, 01 February 2011 22:34 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Shocked Cute!

Best regards
IƱaki
Re: properties like in C# [message #31038 is a reply to message #31031] Wed, 02 February 2011 09:30 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
dont be too excited.. this is *not* my project Smile but i am planning to have sth like that Smile
Re: GetProperty() / SetProperty() for Ctrl [message #33020 is a reply to message #29796] Fri, 01 July 2011 04:18 Go to previous message
luluxiu is currently offline  luluxiu
Messages: 3
Registered: June 2011
Location: New York
Junior Member
It uses the top of all other Ctrls transparent Ctrl key, to seize the position of the mouse, and then find the Ctrl, IIRC in a given location where the. It introduces some additional processing, but for any Ctrl key works.
  • Attachment: cool.gif
    (Size: 2.08KB, Downloaded 316 times)
Previous Topic: Drag and Drop between instances [FEATURE REQUEST]
Next Topic: PrinterJob prints blank pages in linux
Goto Forum:
  


Current Time: Thu Mar 28 18:16:43 CET 2024

Total time taken to generate the page: 0.01271 seconds