What is valPtr in ctor of wxTextValidator good for? - c++

I'm using a simple numeric text validator wxTextValidator along with a wxTextControl. I wonder what the 2nd parameter is good for:
wxTextValidator(long style = wxFILTER_NONE, wxString* valPtr = NULL)
I simply passed the reference to a member variable:
myTextControl_->SetValidator( wxTextValidator(wxFILTER_NUMERIC, &myValue_) );
I'm using wxWidgets 2.8.12, from the documentation I figured that the myValue_ variable would receive the validated content of the text control, but this does not happen in my application.
Am I doing something wrong or does the valPtr parameter not receive the content of the text control?

The myvalue_ variable should receive the value entered if you call wxValidator::Validate or wxValidator::TransferFromWindow. This happens automatically if you close the dialog with the default OnOK() handler. Otherwise you have to do it yourself.

Ravenspoint has already answered the initial question but I'd just like to add that wxValidator can be used either for validating or for data transfer -- or for both at once. In fact, some validators, such as wxGenericValidator are only used for data transfer (it doesn't make much sense to validate a check box or a radio button!). So the name of this class is somewhat misleading as it describes at most half, and probably less than that, of its uses.

Related

ActionListener Expression value for RichButton in ADF

We have a business need to collect specific bindings in every JSF page. and we do that inside overridden ViewHandlerWrapper class
I use the below code inside renderView method to get the whole expression value property for every RichInputText and it's work fine for me
ValueExpression valExp = Inputcomponent.getValueExpression("value");
String ExpressionString = valExp.getExpressionString();
output was: #{binding.EmployeeId.inputValue}
When I do the same against RichButtin I got null value as following:
ValueExpression valExp = Btncomponent.getValueExpression("actionlistener");
String ExpressionString = valExp.getExpressionString();
What is the wrong in my last peace of code?
Obtaining a ValueExpression form a RichInputText works because, as the name suggests, it evaluates to a value, which may or may not be an EL expression, let alone a method.
On the other hand, a RichButton does not really have to evaluate to something; rather, it aims to invoke behavior (i.e. a method), from which you would want a MethodExpression - though in this case, the closest we get to it is a MethodBinding.
Luckily, UIXCommand, a superclass of RichButton, provides two methods from which you can obtain your action listeners:
public final MethodBinding getActionListener()
From the MethodBinding returned, you can invoke getExpressionString() so you can get what you wanted - such as some actionListener EL string like #{binding.bean.actionListenerMethod}.
public final ActionListener[] getActionListeners()
Might be worth mentioning, though there is not much merit for this in your use case. It simply returns the listeners on which you can manually process the events.

Unexpected/weird results using OLE clipboard and classic clipboard, or do I miss something?

I'm trying to do the following trick:
I have IDataObject* to be set into the clipboard, so I'm using OleSetClipboard() to set it into the clipboard.
I have another CLIPFORMAT I want to add to the clipboard, but I can't do it with OleSetClipboard() because the IDataObject* I receive does not implement SetData() method. So, to overcome this limitation I OpenClipboard() with GetClipboardOwner(), this way, I can SetClipboardData() to the clipboard without EmptyClipboard() first.
Now, it all works well, but what happens is that OleGetClipboard() does not return the data I placed in the clipboard using SetClipboardData(), but I can using GetClipboardData().
I can imagine why this happens (It just returns the IDataObject*), so I tried to OleFlushClipboard() to delete the IDataObject*, and OleGetClipboard() again to let the OS rebuild a new IDataObject*, and it still didn't contain the CLIPFORMAT added by SetClipboardData().
Does anyone have any idea how to overcome this issue? or a different trick? or even explain why it works this way? Thanks
I just tried this (on Windows 7) and it appears to work but only cross-process:
In a different process to the clipboard owner, OleGetClipboard returns a data object that contains all of the formats (i.e. the original formats from the data object and the extra ones added to the clipboard).
In the same process, OleGetClipboard always returns a data object that does not contain the extra clipboard formats.
In both cases, calling OleFlushClipboard makes no difference.
Anyway, this doesn't seem like a terribly robust solution. What you can do instead is create your own data object that responds to the formats it knows about and delegates other formats to the original data object. The EnumFormatEtc method would combine formats from both objects, and so on. This article has the skeleton of a simple data object you could extend.

Playing with Ember.Object.reopen(), why I have those results?

I was trying to answer this question: emberjs: add routes after app initialize()
I started to play with Ember.Object.reopen(), to understand how it works, and perhaps finding a way of answering the previous question.
I feel a bit puzzled, and don't understand the behavior of this code:
jsfiddle: http://jsfiddle.net/Sly7/FpJwT/
<script type="text/x-handlebars">
<div>{{App.myObj.value}}</div>
<div>{{App.myObj2.value}}</div>
<div>{{App.myObj3.value}}</div>
</script>
App = Em.Application.create({});
App.MyObject = Em.Object.extend({value: 'initial'});
App.set('myObj', App.MyObject.create());
Em.run.later(function(){
App.get('myObj').reopen({
value: "reopenOnInstance"
}); // the template is not updated, 'initial' is still diplayed, but
console.log(App.get('myObj').get('value')); // print 'reopenOnInstance'
App.MyObject.reopen({
value: "reopenOnClass"
});
App.set('myObj2',App.MyObject.create()); // the template is updated and
console.log(App.get('myObj2').get('value')); //print 'reopenOnClass'
App.myObj3 = App.MyObject.create(); // the template is not updated but
console.log(App.myObj3.get('value')); // print 'reopenOnClass'
Em.run.later(function(){
App.get('myObj').set('value', "setWithSetter"); // the template is updated and
console.log(App.get('myObj').get('value')); // print 'setWithSetter'
App.get('myObj2').set('value', "setWithSetter"); // the template is updated and
console.log(App.get('myObj2').get('value')); // print 'setWithSetter'
App.myObj3.set('value', "setWithSetter"); // the template is not updated but
console.log(App.myObj3.get('value')); // print 'setWithSetter'
}, 2000);
},2000);
If someone can explain what is going on, particularly why the templates are sometimes not updated, sometimes updated, and also what's the difference between calling reopen on a class, calling it and on a instance.
Not 100% sure, but I will try and answer you questions.
First lets look at "myObj3". The ember getter/setter methods trigger the updates in the templates (they fire internal events which cause every property/observer to know something happened). Just setting a value by hand does update the value but will not fire these events and hence nothing changes in the UI. Kind of like when you use a Mutable list you use pushObject to make sure the UI updates.
Now lets look at your "reopen". When you reopen on the class it works as you would expect and updates the base class. When you reopen an instance it is actually creating a mixin and shims it on top of the object. This means when you do a "get" ember iterates over the mixin & object for the value to return. It finds that mixin and gets the value before the object; you could actually replace the method with a "return 'foo '+this._super()" on the instance you will get 'foo initial' (think of your object has having layers like an onion). If you have a group of mixin on top of your object you will have a hard time finding the correct value if you set something directly (but "get" will work perfectly). This leads to the general rule that you should always use "set" instead of a direct reference.
Side note: You can call "getPath" instead of "get" and you can use the relative or absolute path. Such as App.getPath('myObj2.value') which will make the code a little easier to manage. Goes for "setPath" also.
Lastly: The last value prints because you did change the value (it is in there) but the trigger for ember to update the ui never fired because you never called set on "myObj3" object.
EDIT: In the lastest version of ember it looks like the reopen on an instance does do a merge-down on the object (if that key already exists). The mixin only will wrap if you are adding new content.

getElementsByTagName returns 0-length list when called from didFinishLoad delegate

I'm using the Chromium port of WebKit on Windows and I'm trying to retrieve a list of all of the images in my document. I figured the best way to do this was to implement WebKit::WebFrameClient::didFinishLoading like so:
WebNodeList list = document->getElementsByTagName(L"img");
for (size_t i = 0; i < list.length(); ++i) {
// Manipulate images here...
}
However, when this delegate fires, list.length() returns 0. The only times I've seen it return a list of non-zero length is when I substitute "body" or "head" for "img". Strangely enough, if I call getElementsByTagName(L"img") outside of the delegate, it works correctly.
I'm guessing that the DOM isn't fully loaded when didFinishLoading is called, but that would seem to contradict the delegate's name. Does anyone know what I may be missing here?
It turns out that the mistake was purely on my side. I was caching a pointer to the DOM document in my frame wrapper. Of course, since a frame can outlive a DOM document, I ended up referencing an out-of-date document once I loaded a new page.

Error while calling member function

Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working.
The error is:
Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type
EDIT: The Code is:
void function ()
{
if (1001->Checked)
{
Sleep(2000);
}
}
Without seeing some of your code, it's very difficult to offer targeted assistance.
However, that error message usually comes about because the item you're de-referencing is not a pointer.
Check to ensure it's of the correct type. It should be something along the lines of:
tCheckBox *CheckBox1;
One possibility is that you've declared it not as a pointer to the checkbox but as a checkbox itself:
tCheckBox CheckBox1;
Note the lack of the asterisk there that would otherwise mark it as a pointer. In that case, you would use CheckBox1.Checked rather than CheckBox1->Checked, if it's allowed by the framework (this isn't standard C++ since that beast has no concept of GUI libraries).
If that doesn't help, please post the code so we can offer better suggestions.
Update:
if (1001->Checked) ?????
1001 is not a pointer - it's not a variable of any description, it's an integer constant.
You need to declare and use a variable of some description. First step is, I think, to read up on the documentation for your framework and/or get some sample code that does compile and work, basing your initial work of that.
Use CButton::GetCheck() to determine the state of the checkbox - like so...
CButton* pButton = (CButton*) GetDlgItem(IDC_CHECKBOX_RESOURCE_ID);
if ( BST_CHECKED == pButton->GetCheck() )
{
// button is checked
}