Discussion:
wxTextCtrl
yrs90
2005-04-29 04:21:13 UTC
Permalink
I get the impression that wxTextCtrl support is currently limited to use
with a double value. Why does wxTextCtrlBase::SetValue call
wxTextCtrl::SetLabel (rather than wxTextCtrl::SetValue) if the value isn't a
double?

I found that not passing an accessor in a rule to a property when one was
expected causes a crash in rule_base::execute_immediate(). Someday it would
be good to generate a warning instead. This is probably a common error. The
perpetrator follows.

// note defined as PROP_GetSet(accessor, Value).
RULE("xrcTextCtrl.Value", make_const<string>(string("test"))) // fails


I'd like to assign a wxString to Value, but I'm having trouble figuring out
how to convert a wxString to an accessor in a wxTextCtrl rule. I thought
wrongly that perhaps the following rule would work.

PROP_GetSet(wxString, Info)
RULE("xrcTextCtrl.Value",
make_accessor(make_expr<wxString>("xrcList.Current.Info")))


Since the only thing I know is an accessor is something declared as a
container, I tried using a container. The error makes sense, but doesn't
help me understand how to make an accessor.

test.push_back(wxString("test1"));
test.push_back(wxString("test2"));
IMPLEMENT_ADAPTER_CONTAINER(vector<wxString>)

RULE("xrcTextCtrl.Value", make_expr<accessor>("test"))

This complains that error converter<vector<wxString>>::to_string method
wasn't implemented. This makes some sense, because the SetValue code isn't
looking for a container.

I suppose I could make GetInfo() return an accessor (by calling
make_accessor before returning), but then it's not so useful internally.

- - -

On a different tact, I was puzzled by the following code snippet.

// mark current m_value as invalid
g_rapidUI->ValueChanged(GetWndAggregate()["Value"], false, false);
// assign new accessor
m_value=newValue;
// and send change notification for new accessor
g_rapidUI->ValueChanged(GetWndAggregate()["Value"], false);

How/why does the first call to ValueChanged mark m_value as invalid? I had
thought the notification was only required after updating. I notice that it
won't be solved until the second call, but I thought deferred resolution was
just for use when invalidating multiple values.


Regards,
Joel


---
[This E-mail scanned for viruses by Declude Virus]



-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start! http://www.idcswdc.com/cgi-bin/survey?id=105hix
Hajo Kirchhoff
2005-05-01 06:52:43 UTC
Permalink
Post by yrs90
I get the impression that wxTextCtrl support is currently limited to use
with a double value. Why does wxTextCtrlBase::SetValue call
wxTextCtrl::SetLabel (rather than wxTextCtrl::SetValue) if the value isn't a
double?
I will investigate that. Might be a typo or it might be that for
wxTextCtrl SetValue and SetLabel do the same thing.

wxTextCtrl should accept any data type. If its a double, it will switch
to 'numbers only' mode automatically. Also it eliminates the need to
convert your double from/to string, as is currently neccessary in the
traditional programming world.

But it should be possible to use a string.
Post by yrs90
I'd like to assign a wxString to Value, but I'm having trouble
figuring out
Post by yrs90
how to convert a wxString to an accessor in a wxTextCtrl rule. I thought
wrongly that perhaps the following rule would work.
PROP_GetSet(wxString, Info)
RULE("xrcTextCtrl.Value",
make_accessor(make_expr<wxString>("xrcList.Current.Info")))
I'll investigate.
Post by yrs90
- - -
On a different tact, I was puzzled by the following code snippet.
// mark current m_value as invalid
g_rapidUI->ValueChanged(GetWndAggregate()["Value"], false, false);
// assign new accessor
m_value=newValue;
// and send change notification for new accessor
g_rapidUI->ValueChanged(GetWndAggregate()["Value"], false);
How/why does the first call to ValueChanged mark m_value as invalid?
I had
Post by yrs90
thought the notification was only required after updating. I notice that it
won't be solved until the second call, but I thought deferred
resolution was
Post by yrs90
just for use when invalidating multiple values.
Actually the code does invalidate multiple values here. It is a bit
difficult to see, because the 'Value' is an accessor itself.

The first NotifyChanged tells the RapidUI mechanism that the accessor
that up to then pointed to the value has changed. RapidUI marks all
rules that depend on that accessor as 'dirty'. Every rule has a list of
accessors it depends on.

Next time they are evaluated, they will refresh their dependency list
with new accessors.

Without the first ValueChanged call the dependency-list for the rules
would still contain the old accessor, which is no longer valid after
m_value=newValue.

RapidUI rules dependency has two flavors. Static dependency means that a
rule depends on an accessor and that never changes its location and type
in memory during the lifetime of the rule. The object pointed to by this
accessor may change, but not the accessor itself.

Dynamic dependency otoh allows that the accessor itself changes.

Hajo



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
yrs90
2005-05-01 09:16:43 UTC
Permalink
Post by Hajo Kirchhoff
I will investigate that. Might be a typo or it might be that for
wxTextCtrl SetValue and SetLabel do the same thing.
I found the following:

http://groups-beta.google.com/group/comp.soft-sys.wxwindows/browse_thread/th
read/c3e65abf426862e/06bfe1a5055f37a9

<quote>
I believe the correct API calls for working with the contents of a
TextCtrl are GetValue and SetValue. The fact that Get/SetLabel works
on MSW is probably an artifact of how Windows itself implements the
text controls.
</quote>
Post by Hajo Kirchhoff
Post by yrs90
I'd like to assign a wxString to Value, but I'm having trouble
figuring out
how to convert a wxString to an accessor in a wxTextCtrl rule. I
thought wrongly that perhaps the following rule would work.
PROP_GetSet(wxString, Info)
RULE("xrcTextCtrl.Value",
make_accessor(make_expr<wxString>("xrcList.Current.Info")))
I'll investigate.
Thanks. I don't have a solution yet.

I've tried rules of a few different varieties:

RULE("xrcTextCtrl.Value", make_const<accessor>(make_accessor(wxString("test
string"))))

RULE("xrcTextCtrl.Value",
make_accessor(make_expr<wxString>("xrcList.Current.second.Info)))

RULE("xrcTextCtrl.Value", make_accessor(make_const<wxString>(wxString("test
string"))))

wxString test="test string";
BEGIN_RULES()
RULE("xrcTargetInfoMain.Value",
make_const<accessor>(make_accessor<wxString>(test)))
END_RULES()

The last case works. The previous tries all fail.

The first case compiles but gives me a runtime error. Oddly the crash is in
strlen(). It looks like the wxString hasn't been created yet. Below is the
simplified-for-readability backtrace.

MSVCR80D!strlen+0x30
MSVCP80D!std::basic_string::assign+0x10
MSVCP80D!std::basic_string::basic_string
MyApp!litwindow::converter<wxString>::to_string+0x5d [base_objects.cpp @ 36]
MyApp!litwindow::converter<wxString>::to_string+0x4d [dataadapterimp.h @
736]
MyApp!litwindow::const_accessor::to_string
MyApp!litwindow::wxTextCtrlAdapter::SetValue
MyApp!litwindow::converter_with_getset<>::set_value
MyApp!litwindow::typed_accessor<>::set
MyApp!litwindow::value_assign_expr<>::do_assign
MyApp!litwindow::rule_base::execute_immediate
MyApp!litwindow::constraint_solver::execute_all_immediate
MyApp!litwindow::RapidUI::Start


Case 2 and 3, fail during compilation. It complains about 'value_type' not
being a member of 'litwindow::accessor'. I am guessing this isn't
interesting, but, if it is, I'll send the detailed errors.

Case 4 works.... Well that's some progress. However, I still don't see how
to dynamically lookup a wxString. make_expr<wxString> returns
expr_primary<wxString> so it isn't suitable for changing into an
accessor<wxString>.
Post by Hajo Kirchhoff
Post by yrs90
- - -
On a different tact, I was puzzled by the following code snippet.
Actually the code does invalidate multiple values here. It is a bit
difficult to see, because the 'Value' is an accessor itself.
...
RapidUI rules dependency has two flavors. Static dependency means that a
rule depends on an accessor and that never changes its location and type
in memory during the lifetime of the rule. The object pointed to by this
accessor may change, but not the accessor itself.
Dynamic dependency otoh allows that the accessor itself changes.
This explanation is quite interesting. So it follows that rules which pass
an accessor are always dynamic because it assigns a replacement accessor
each time the rule is updated? What do static dependency rules look like?
(For a moment I thought make_expr<const_accessor> but that would just keep
the object pointed at from being changed, right?)

For the list assignment, the library takes care of invalidating the old
accessor so the user need not be concerned. Are there times when the user
is required to call NotifyChanged on a value before updating?

Joel




---
[This E-mail scanned for viruses by Declude Virus]



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
Hajo Kirchhoff
2005-05-01 06:53:05 UTC
Permalink
Hi,
Post by yrs90
I'd like to assign a wxString to Value, but I'm having trouble
figuring out
Post by yrs90
how to convert a wxString to an accessor in a wxTextCtrl rule. I thought
wrongly that perhaps the following rule would work.
PROP_GetSet(wxString, Info)
RULE("xrcTextCtrl.Value",
make_accessor(make_expr<wxString>("xrcList.Current.Info")))
of course, now I remember :)

Use xrcTextCtrl.Label instead of .Value.

The Value property is indeed an accessor. I don't know if it is possible
to pass an accessor using explicit rules. If it is, it should be

make_expr<accessor>("xrcList.Current.Info")

and make_expr should 'cast' the string to an accessor implicitly. Or
something like this. Your expression above tried to make an accessor for
the expression, which will not work.


wxTextCtrl has three properties that can be used for the actual text:

Value is of type accessor and automatically detects the correct type.
Double is of type double.
Label is of type string.

So for double variables you'd use

xrcTextCtrl.Double = m_myDouble

for string you'd use

xrcTextCtrl.Label = m_myString

I choose label because it is inherited by all controls.


The Value property comes in handy when you are using implicit rules
where your data variable and text ctrl name are the same. RapidUI will
create the rule automatically.

Regards

Hajo



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
yrs90
2005-05-01 10:43:37 UTC
Permalink
Post by Hajo Kirchhoff
Use xrcTextCtrl.Label instead of .Value.
It works! I thought I looked for another property that accepted wxString.
In fact, I don't see Label defined anywhere except wxControl. I guess it
searches both co-objects, adapter and widget hierarchies. I'm very happy to
get this working.

Thanks!



---
[This E-mail scanned for viruses by Declude Virus]



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
Hajo Kirchhoff
2005-05-02 05:59:18 UTC
Permalink
Post by yrs90
Post by Hajo Kirchhoff
Use xrcTextCtrl.Label instead of .Value.
It works! I thought I looked for another property that accepted wxString.
In fact, I don't see Label defined anywhere except wxControl. I guess it
searches both co-objects, adapter and widget hierarchies. I'm very happy to
get this working.
Thanks!
Great. Yes, both hierarchies are searched. The lit window text control
'inherits' from the textctrladapter and the textctrl itself.

Regarding your other post and 'SetLabel': I will introduce a new
property 'Text' or perhaps 'String' and will call SetValue instead.
Makes things more 'proper'. Label is indeed misleading.

What do you think would be better? Text or String? Value is already
taken and accepts an accessor. Double accepts double. So text could
accept a text.

Suggestions?

Hajo



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
yrs90
2005-05-02 10:17:40 UTC
Permalink
Post by Hajo Kirchhoff
Regarding your other post and 'SetLabel': I will introduce a new
property 'Text' or perhaps 'String' and will call SetValue instead.
Makes things more 'proper'. Label is indeed misleading.
It turns out that SetLabel doesn't have the intended affect in a multiline
wxTextCtrl anyway. Even with the correct wxTE_MULTILINE style set, the
SetLabel doesn't translate the newlines into linefeed carriage returns.
Post by Hajo Kirchhoff
What do you think would be better? Text or String? Value is already
taken and accepts an accessor. Double accepts double. So text could
accept a text.
In a fit of not-very-creative-let's-get-it-to-work, I created a StrValue
here locally. Either of your suggestions sounds acceptable, but I think
"Text" is a little closer to the actual meaning. So that's my vote.

Joel





---
[This E-mail scanned for viruses by Declude Virus]



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
Loading...